Skip to content

Commit 5206aab

Browse files
committed
Move airgapInfo to preRunInstall
1 parent f72e05c commit 5206aab

File tree

5 files changed

+32
-45
lines changed

5 files changed

+32
-45
lines changed

api/internal/managers/infra/install.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ func (m *infraManager) install(ctx context.Context, rc runtimeconfig.RuntimeConf
9999
return fmt.Errorf("parse license: %w", err)
100100
}
101101

102-
var airgapInfo *kotsv1beta1.Airgap
103102
if m.airgapBundle != "" {
104103
var err error
105-
airgapInfo, err = airgap.AirgapInfoFromPath(m.airgapBundle)
104+
m.airgapInfo, err = airgap.AirgapInfoFromPath(m.airgapBundle)
106105
if err != nil {
107106
return fmt.Errorf("failed to get airgap info: %w", err)
108107
}
@@ -133,7 +132,7 @@ func (m *infraManager) install(ctx context.Context, rc runtimeconfig.RuntimeConf
133132
}
134133
defer hcli.Close()
135134

136-
in, err := m.recordInstallation(ctx, kcli, license, rc, airgapInfo)
135+
in, err := m.recordInstallation(ctx, kcli, license, rc)
137136
if err != nil {
138137
return fmt.Errorf("record installation: %w", err)
139138
}
@@ -228,16 +227,16 @@ func (m *infraManager) installK0s(ctx context.Context, rc runtimeconfig.RuntimeC
228227
return k0sCfg, nil
229228
}
230229

231-
func (m *infraManager) recordInstallation(ctx context.Context, kcli client.Client, license *kotsv1beta1.License, rc runtimeconfig.RuntimeConfig, airgapInfo *kotsv1beta1.Airgap) (*ecv1beta1.Installation, error) {
230+
func (m *infraManager) recordInstallation(ctx context.Context, kcli client.Client, license *kotsv1beta1.License, rc runtimeconfig.RuntimeConfig) (*ecv1beta1.Installation, error) {
232231
logFn := m.logFn("metadata")
233232

234233
// get the configured custom domains
235234
ecDomains := utils.GetDomains(m.releaseData)
236235

237236
// extract airgap uncompressed size if airgap info is provided
238237
var airgapUncompressedSize int64
239-
if airgapInfo != nil {
240-
airgapUncompressedSize = airgapInfo.Spec.UncompressedSize
238+
if m.airgapInfo != nil {
239+
airgapUncompressedSize = m.airgapInfo.Spec.UncompressedSize
241240
}
242241

243242
// record the installation

api/internal/managers/infra/manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/replicatedhq/embedded-cluster/pkg/helm"
1414
"github.com/replicatedhq/embedded-cluster/pkg/release"
1515
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
16+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1617
"github.com/sirupsen/logrus"
1718
"k8s.io/client-go/metadata"
1819
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -33,6 +34,7 @@ type infraManager struct {
3334
tlsConfig types.TLSConfig
3435
license []byte
3536
airgapBundle string
37+
airgapInfo *kotsv1beta1.Airgap
3638
configValues string
3739
releaseData *release.ReleaseData
3840
endUserConfig *ecv1beta1.Config

cmd/installer/cli/install.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type InstallCmdFlags struct {
5353
adminConsolePort int
5454
airgapBundle string
5555
isAirgap bool
56+
airgapInfo *kotsv1beta1.Airgap
5657
dataDir string
5758
licenseFile string
5859
localArtifactMirrorPort int
@@ -105,7 +106,7 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
105106
}
106107
}
107108

108-
if err := verifyAndPrompt(ctx, name, flags, prompts.New(), airgapInfo); err != nil {
109+
if err := verifyAndPrompt(ctx, name, flags, prompts.New()); err != nil {
109110
return err
110111
}
111112
if err := preRunInstall(cmd, &flags, rc); err != nil {
@@ -275,6 +276,13 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags, rc runtimeconfig.
275276
}
276277

277278
flags.isAirgap = flags.airgapBundle != ""
279+
if flags.airgapBundle != "" {
280+
var err error
281+
flags.airgapInfo, err = airgap.AirgapInfoFromPath(flags.airgapBundle)
282+
if err != nil {
283+
return fmt.Errorf("failed to get airgap info: %w", err)
284+
}
285+
}
278286

279287
hostCABundlePath, err := findHostCABundle()
280288
if err != nil {
@@ -463,7 +471,7 @@ func runInstall(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.Run
463471
}
464472

465473
logrus.Debugf("running install preflights")
466-
if err := runInstallPreflights(ctx, flags, rc, installReporter.reporter, airgapInfo); err != nil {
474+
if err := runInstallPreflights(ctx, flags, rc, installReporter.reporter); err != nil {
467475
if errors.Is(err, preflights.ErrPreflightsHaveFail) {
468476
return NewErrorNothingElseToAdd(err)
469477
}
@@ -588,7 +596,7 @@ func getAddonInstallOpts(flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig,
588596
return opts, nil
589597
}
590598

591-
func verifyAndPrompt(ctx context.Context, name string, flags InstallCmdFlags, prompt prompts.Prompt, airgapInfo *kotsv1beta1.Airgap) error {
599+
func verifyAndPrompt(ctx context.Context, name string, flags InstallCmdFlags, prompt prompts.Prompt) error {
592600
logrus.Debugf("checking if k0s is already installed")
593601
err := verifyNoInstallation(name, "reinstall")
594602
if err != nil {
@@ -605,9 +613,9 @@ func verifyAndPrompt(ctx context.Context, name string, flags InstallCmdFlags, pr
605613
if err != nil {
606614
return err
607615
}
608-
if airgapInfo != nil {
616+
if flags.airgapInfo != nil {
609617
logrus.Debugf("checking airgap bundle matches binary")
610-
if err := checkAirgapMatches(airgapInfo); err != nil {
618+
if err := checkAirgapMatches(flags.airgapInfo); err != nil {
611619
return err // we want the user to see the error message without a prefix
612620
}
613621
}

cmd/installer/cli/install_runpreflights.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import (
88

99
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils"
1010
"github.com/replicatedhq/embedded-cluster/pkg-new/preflights"
11-
"github.com/replicatedhq/embedded-cluster/pkg/airgap"
1211
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
1312
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
1413
"github.com/replicatedhq/embedded-cluster/pkg/prompts"
1514
"github.com/replicatedhq/embedded-cluster/pkg/release"
1615
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
17-
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1816
"github.com/sirupsen/logrus"
1917
"github.com/spf13/cobra"
2018
)
@@ -44,16 +42,7 @@ func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
4442
rc.Cleanup()
4543
},
4644
RunE: func(cmd *cobra.Command, args []string) error {
47-
var airgapInfo *kotsv1beta1.Airgap
48-
if flags.airgapBundle != "" {
49-
var err error
50-
airgapInfo, err = airgap.AirgapInfoFromPath(flags.airgapBundle)
51-
if err != nil {
52-
return fmt.Errorf("failed to get airgap info: %w", err)
53-
}
54-
}
55-
56-
if err := runInstallRunPreflights(cmd.Context(), name, flags, rc, airgapInfo); err != nil {
45+
if err := runInstallRunPreflights(cmd.Context(), name, flags, rc); err != nil {
5746
return err
5847
}
5948

@@ -71,8 +60,8 @@ func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
7160
return cmd
7261
}
7362

74-
func runInstallRunPreflights(ctx context.Context, name string, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, airgapInfo *kotsv1beta1.Airgap) error {
75-
if err := verifyAndPrompt(ctx, name, flags, prompts.New(), airgapInfo); err != nil {
63+
func runInstallRunPreflights(ctx context.Context, name string, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig) error {
64+
if err := verifyAndPrompt(ctx, name, flags, prompts.New()); err != nil {
7665
return err
7766
}
7867

@@ -90,7 +79,7 @@ func runInstallRunPreflights(ctx context.Context, name string, flags InstallCmdF
9079
}
9180

9281
logrus.Debugf("running install preflights")
93-
if err := runInstallPreflights(ctx, flags, rc, nil, airgapInfo); err != nil {
82+
if err := runInstallPreflights(ctx, flags, rc, nil); err != nil {
9483
if errors.Is(err, preflights.ErrPreflightsHaveFail) {
9584
return NewErrorNothingElseToAdd(err)
9685
}
@@ -102,7 +91,7 @@ func runInstallRunPreflights(ctx context.Context, name string, flags InstallCmdF
10291
return nil
10392
}
10493

105-
func runInstallPreflights(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, metricsReporter metrics.ReporterInterface, airgapInfo *kotsv1beta1.Airgap) error {
94+
func runInstallPreflights(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, metricsReporter metrics.ReporterInterface) error {
10695
replicatedAppURL := replicatedAppURL()
10796
proxyRegistryURL := proxyRegistryURL()
10897

@@ -113,8 +102,8 @@ func runInstallPreflights(ctx context.Context, flags InstallCmdFlags, rc runtime
113102

114103
// Calculate airgap storage space requirement (2x uncompressed size for controller nodes)
115104
var controllerAirgapStorageSpace string
116-
if airgapInfo != nil {
117-
controllerAirgapStorageSpace = preflights.CalculateAirgapStorageSpace(airgapInfo.Spec.UncompressedSize, true)
105+
if flags.airgapInfo != nil {
106+
controllerAirgapStorageSpace = preflights.CalculateAirgapStorageSpace(flags.airgapInfo.Spec.UncompressedSize, true)
118107
}
119108

120109
opts := preflights.PrepareOptions{

cmd/installer/cli/restore.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/replicatedhq/embedded-cluster/pkg-new/preflights"
2626
"github.com/replicatedhq/embedded-cluster/pkg/addons"
2727
addontypes "github.com/replicatedhq/embedded-cluster/pkg/addons/types"
28-
"github.com/replicatedhq/embedded-cluster/pkg/airgap"
2928
"github.com/replicatedhq/embedded-cluster/pkg/constants"
3029
"github.com/replicatedhq/embedded-cluster/pkg/disasterrecovery"
3130
"github.com/replicatedhq/embedded-cluster/pkg/helm"
@@ -37,7 +36,6 @@ import (
3736
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
3837
"github.com/replicatedhq/embedded-cluster/pkg/spinner"
3938
"github.com/replicatedhq/embedded-cluster/pkg/versions"
40-
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
4139
"github.com/sirupsen/logrus"
4240
"github.com/spf13/cobra"
4341
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
@@ -135,18 +133,9 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
135133
return err
136134
}
137135

138-
var airgapInfo *kotsv1beta1.Airgap
139-
if flags.isAirgap {
136+
if flags.airgapInfo != nil {
140137
logrus.Debugf("checking airgap bundle matches binary")
141-
142-
// read file from path
143-
var err error
144-
airgapInfo, err = airgap.AirgapInfoFromPath(flags.airgapBundle)
145-
if err != nil {
146-
return fmt.Errorf("failed to get airgap bundle versions: %w", err)
147-
}
148-
149-
if err := checkAirgapMatches(airgapInfo); err != nil {
138+
if err := checkAirgapMatches(flags.airgapInfo); err != nil {
150139
return err // we want the user to see the error message without a prefix
151140
}
152141
}
@@ -204,7 +193,7 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
204193

205194
switch state {
206195
case ecRestoreStateNew:
207-
err = runRestoreStepNew(ctx, name, flags, rc, &s3Store, skipStoreValidation, airgapInfo)
196+
err = runRestoreStepNew(ctx, name, flags, rc, &s3Store, skipStoreValidation)
208197
if err != nil {
209198
return err
210199
}
@@ -359,7 +348,7 @@ func runRestore(ctx context.Context, name string, flags InstallCmdFlags, rc runt
359348
return nil
360349
}
361350

362-
func runRestoreStepNew(ctx context.Context, name string, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, s3Store *s3BackupStore, skipStoreValidation bool, airgapInfo *kotsv1beta1.Airgap) error {
351+
func runRestoreStepNew(ctx context.Context, name string, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, s3Store *s3BackupStore, skipStoreValidation bool) error {
363352
logrus.Debugf("checking if k0s is already installed")
364353
err := verifyNoInstallation(name, "restore")
365354
if err != nil {
@@ -391,7 +380,7 @@ func runRestoreStepNew(ctx context.Context, name string, flags InstallCmdFlags,
391380
}
392381

393382
logrus.Debugf("running install preflights")
394-
if err := runInstallPreflights(ctx, flags, rc, nil, airgapInfo); err != nil {
383+
if err := runInstallPreflights(ctx, flags, rc, nil); err != nil {
395384
if errors.Is(err, preflights.ErrPreflightsHaveFail) {
396385
return NewErrorNothingElseToAdd(err)
397386
}

0 commit comments

Comments
 (0)