Skip to content

Commit b25cb49

Browse files
authored
feat(v3): rely on kots to process the app airgap bundle and create the image pull secrets (#2760)
* feat(v3): rely on kots to process the app airgap bundle and create the image pull secrets * f
1 parent 5fa0f88 commit b25cb49

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

api/internal/managers/app/install/install.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,24 @@ func (m *appInstallManager) Install(ctx context.Context, installableCharts []typ
4949
}
5050

5151
func (m *appInstallManager) install(ctx context.Context, installableCharts []types.InstallableHelmChart, kotsConfigValues kotsv1beta1.ConfigValues) error {
52-
license := &kotsv1beta1.License{}
53-
if err := kyaml.Unmarshal(m.license, license); err != nil {
54-
return fmt.Errorf("parse license: %w", err)
55-
}
56-
57-
// Setup Helm client
58-
if err := m.setupHelmClient(); err != nil {
59-
return fmt.Errorf("setup helm client: %w", err)
52+
if err := m.installKots(kotsConfigValues); err != nil {
53+
return fmt.Errorf("install kots: %w", err)
6054
}
6155

6256
// Install Helm charts
6357
if err := m.installHelmCharts(ctx, installableCharts); err != nil {
6458
return fmt.Errorf("install helm charts: %w", err)
6559
}
6660

61+
return nil
62+
}
63+
64+
func (m *appInstallManager) installKots(kotsConfigValues kotsv1beta1.ConfigValues) error {
65+
license := &kotsv1beta1.License{}
66+
if err := kyaml.Unmarshal(m.license, license); err != nil {
67+
return fmt.Errorf("parse license: %w", err)
68+
}
69+
6770
ecDomains := utils.GetDomains(m.releaseData)
6871

6972
installOpts := kotscli.InstallOptions{
@@ -83,11 +86,25 @@ func (m *appInstallManager) install(ctx context.Context, installableCharts []typ
8386
}
8487
installOpts.ConfigValuesFile = configValuesFile
8588

89+
logFn := m.logFn("app")
90+
91+
logFn("preparing the app for installation")
92+
8693
if m.kotsCLI != nil {
87-
return m.kotsCLI.Install(installOpts)
94+
err := m.kotsCLI.Install(installOpts)
95+
if err != nil {
96+
return fmt.Errorf("install kots: %w", err)
97+
}
98+
} else {
99+
err := kotscli.Install(installOpts)
100+
if err != nil {
101+
return fmt.Errorf("install kots: %w", err)
102+
}
88103
}
89104

90-
return kotscli.Install(installOpts)
105+
logFn("successfully prepared the app for installation")
106+
107+
return nil
91108
}
92109

93110
// createConfigValuesFile creates a temporary file with the config values
@@ -119,6 +136,11 @@ func (m *appInstallManager) installHelmCharts(ctx context.Context, installableCh
119136
return fmt.Errorf("no helm charts found")
120137
}
121138

139+
// Setup Helm client
140+
if err := m.setupHelmClient(); err != nil {
141+
return fmt.Errorf("setup helm client: %w", err)
142+
}
143+
122144
logFn("installing %d helm charts", len(installableCharts))
123145

124146
for _, installableChart := range installableCharts {
@@ -132,6 +154,8 @@ func (m *appInstallManager) installHelmCharts(ctx context.Context, installableCh
132154
logFn("successfully installed %s chart", chartName)
133155
}
134156

157+
logFn("successfully installed all %d helm charts", len(installableCharts))
158+
135159
return nil
136160
}
137161

api/internal/managers/app/install/install_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ func TestAppInstallManager_Install(t *testing.T) {
257257
return opts.ChartPath != "" && opts.ReleaseName == "fluentd" && opts.Namespace == "logging"
258258
})).Return((*helmrelease.Release)(nil), assert.AnError)
259259

260-
// Create manager with initialized store (no need for KOTS installer mock since Helm fails first)
260+
// Create mock installer that succeeds (so we get to Helm charts)
261+
mockInstaller := &MockKotsCLIInstaller{}
262+
mockInstaller.On("Install", mock.Anything).Return(nil)
263+
264+
// Create manager with initialized store
261265
store := appinstallstore.NewMemoryStore(appinstallstore.WithAppInstall(types.AppInstall{
262266
Status: types.Status{State: types.StatePending},
263267
}))
@@ -266,6 +270,7 @@ func TestAppInstallManager_Install(t *testing.T) {
266270
WithClusterID("test-cluster"),
267271
WithReleaseData(releaseData),
268272
WithK8sVersion("v1.33.0"),
273+
WithKotsCLI(mockInstaller),
269274
WithHelmClient(mockHelmClient),
270275
WithLogger(logger.NewDiscardLogger()),
271276
WithAppInstallStore(store),
@@ -282,6 +287,7 @@ func TestAppInstallManager_Install(t *testing.T) {
282287
assert.Equal(t, types.StateFailed, appInstall.Status.State)
283288
assert.Contains(t, appInstall.Status.Description, "install helm charts")
284289

290+
mockInstaller.AssertExpectations(t)
285291
mockHelmClient.AssertExpectations(t)
286292
})
287293

@@ -491,6 +497,10 @@ func TestComponentStatusTracking(t *testing.T) {
491497
return opts.ReleaseName == "failing-app"
492498
})).Return((*helmrelease.Release)(nil), errors.New("helm install failed"))
493499

500+
// Create mock installer that succeeds (so we get to Helm charts)
501+
mockInstaller := &MockKotsCLIInstaller{}
502+
mockInstaller.On("Install", mock.Anything).Return(nil)
503+
494504
// Create manager with in-memory store
495505
appInstallStore := appinstallstore.NewMemoryStore(appinstallstore.WithAppInstall(types.AppInstall{
496506
Status: types.Status{State: types.StatePending},
@@ -501,6 +511,7 @@ func TestComponentStatusTracking(t *testing.T) {
501511
WithK8sVersion("v1.33.0"),
502512
WithLicense([]byte(`{"spec":{"appSlug":"test-app"}}`)),
503513
WithClusterID("test-cluster"),
514+
WithKotsCLI(mockInstaller),
504515
WithHelmClient(mockHelmClient),
505516
)
506517
require.NoError(t, err)
@@ -525,6 +536,7 @@ func TestComponentStatusTracking(t *testing.T) {
525536
// Overall status should be failed
526537
assert.Equal(t, types.StateFailed, appInstall.Status.State)
527538

539+
mockInstaller.AssertExpectations(t)
528540
mockHelmClient.AssertExpectations(t)
529541
})
530542
}

0 commit comments

Comments
 (0)