Skip to content

Commit b88f435

Browse files
committed
Extract airgap.yaml once
Signed-off-by: Evans Mungai <evans@replicated.com>
1 parent 46ca2d3 commit b88f435

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

cmd/installer/cli/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ func runInstall(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.Run
455455
}
456456

457457
logrus.Debugf("running install preflights")
458-
if err := runInstallPreflights(ctx, flags, rc, installReporter.reporter); err != nil {
458+
if err := runInstallPreflights(ctx, flags, rc, installReporter.reporter, airgapInfo); err != nil {
459459
if errors.Is(err, preflights.ErrPreflightsHaveFail) {
460460
return NewErrorNothingElseToAdd(err)
461461
}

cmd/installer/cli/install_runpreflights.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func runInstallRunPreflights(ctx context.Context, name string, flags InstallCmdF
8484
}
8585

8686
logrus.Debugf("running install preflights")
87-
if err := runInstallPreflights(ctx, flags, rc, nil); err != nil {
87+
if err := runInstallPreflights(ctx, flags, rc, nil, airgapInfo); err != nil {
8888
if errors.Is(err, preflights.ErrPreflightsHaveFail) {
8989
return NewErrorNothingElseToAdd(err)
9090
}
@@ -96,7 +96,7 @@ func runInstallRunPreflights(ctx context.Context, name string, flags InstallCmdF
9696
return nil
9797
}
9898

99-
func runInstallPreflights(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, metricsReporter metrics.ReporterInterface) error {
99+
func runInstallPreflights(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, metricsReporter metrics.ReporterInterface, airgapInfo *kotsv1beta1.Airgap) error {
100100
replicatedAppURL := replicatedAppURL()
101101
proxyRegistryURL := proxyRegistryURL()
102102

@@ -107,12 +107,7 @@ func runInstallPreflights(ctx context.Context, flags InstallCmdFlags, rc runtime
107107

108108
// Calculate airgap storage space requirement (2x uncompressed size for controller nodes)
109109
var controllerAirgapStorageSpace string
110-
if flags.airgapBundle != "" {
111-
airgapInfo, err := airgap.AirgapInfoFromPath(flags.airgapBundle)
112-
if err != nil {
113-
return fmt.Errorf("failed to get airgap info: %w", err)
114-
}
115-
// The first installed node is always a controller
110+
if airgapInfo != nil {
116111
controllerAirgapStorageSpace = preflights.CalculateAirgapStorageSpace(airgapInfo.Spec.UncompressedSize, true)
117112
}
118113

cmd/installer/cli/restore.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
3838
"github.com/replicatedhq/embedded-cluster/pkg/spinner"
3939
"github.com/replicatedhq/embedded-cluster/pkg/versions"
40+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
4041
"github.com/sirupsen/logrus"
4142
"github.com/spf13/cobra"
4243
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
@@ -134,11 +135,13 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
134135
return err
135136
}
136137

138+
var airgapInfo *kotsv1beta1.Airgap
137139
if flags.isAirgap {
138140
logrus.Debugf("checking airgap bundle matches binary")
139141

140142
// read file from path
141-
airgapInfo, err := airgap.AirgapInfoFromPath(flags.airgapBundle)
143+
var err error
144+
airgapInfo, err = airgap.AirgapInfoFromPath(flags.airgapBundle)
142145
if err != nil {
143146
return fmt.Errorf("failed to get airgap bundle versions: %w", err)
144147
}
@@ -201,7 +204,7 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
201204

202205
switch state {
203206
case ecRestoreStateNew:
204-
err = runRestoreStepNew(ctx, name, flags, rc, &s3Store, skipStoreValidation)
207+
err = runRestoreStepNew(ctx, name, flags, rc, &s3Store, skipStoreValidation, airgapInfo)
205208
if err != nil {
206209
return err
207210
}
@@ -356,7 +359,7 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
356359
return nil
357360
}
358361

359-
func runRestoreStepNew(ctx context.Context, name string, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, s3Store *s3BackupStore, skipStoreValidation bool) error {
362+
func runRestoreStepNew(ctx context.Context, name string, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, s3Store *s3BackupStore, skipStoreValidation bool, airgapInfo *kotsv1beta1.Airgap) error {
360363
logrus.Debugf("checking if k0s is already installed")
361364
err := verifyNoInstallation(name, "restore")
362365
if err != nil {
@@ -388,7 +391,7 @@ func runRestoreStepNew(ctx context.Context, name string, flags InstallCmdFlags,
388391
}
389392

390393
logrus.Debugf("running install preflights")
391-
if err := runInstallPreflights(ctx, flags, rc, nil); err != nil {
394+
if err := runInstallPreflights(ctx, flags, rc, nil, airgapInfo); err != nil {
392395
if errors.Is(err, preflights.ErrPreflightsHaveFail) {
393396
return NewErrorNothingElseToAdd(err)
394397
}

0 commit comments

Comments
 (0)