Skip to content

Commit ee7964f

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

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
@@ -36,6 +36,7 @@ import (
3636
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
3737
"github.com/replicatedhq/embedded-cluster/pkg/spinner"
3838
"github.com/replicatedhq/embedded-cluster/pkg/versions"
39+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
3940
"github.com/sirupsen/logrus"
4041
"github.com/spf13/cobra"
4142
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
@@ -133,11 +134,13 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
133134
return err
134135
}
135136

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

139141
// read file from path
140-
airgapInfo, err := airgap.AirgapInfoFromPath(flags.airgapBundle)
142+
var err error
143+
airgapInfo, err = airgap.AirgapInfoFromPath(flags.airgapBundle)
141144
if err != nil {
142145
return fmt.Errorf("failed to get airgap bundle versions: %w", err)
143146
}
@@ -200,7 +203,7 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
200203

201204
switch state {
202205
case ecRestoreStateNew:
203-
err = runRestoreStepNew(ctx, name, flags, rc, &s3Store, skipStoreValidation)
206+
err = runRestoreStepNew(ctx, name, flags, rc, &s3Store, skipStoreValidation, airgapInfo)
204207
if err != nil {
205208
return err
206209
}
@@ -355,7 +358,7 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
355358
return nil
356359
}
357360

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

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

0 commit comments

Comments
 (0)