Skip to content

Commit 8a38a3b

Browse files
feat(v3): add support for local registry templates (#2712)
* local registry template functions * add tests * refactor after feedback * address feedback * use runtime config not installation config for calculating registry settings
1 parent 9f1cb9f commit 8a38a3b

File tree

21 files changed

+741
-42
lines changed

21 files changed

+741
-42
lines changed

api/controllers/app/install/apppreflight.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
type RunAppPreflightOptions struct {
1818
PreflightBinaryPath string
1919
ProxySpec *ecv1beta1.ProxySpec
20+
RegistrySettings *types.RegistrySettings
2021
ExtraPaths []string
2122
CleanupBinary bool
2223
}
@@ -47,7 +48,7 @@ func (c *InstallController) RunAppPreflights(ctx context.Context, opts RunAppPre
4748
}
4849

4950
// Extract app preflight spec from Helm charts
50-
appPreflightSpec, err := c.appReleaseManager.ExtractAppPreflightSpec(ctx, configValues, opts.ProxySpec)
51+
appPreflightSpec, err := c.appReleaseManager.ExtractAppPreflightSpec(ctx, configValues, opts.ProxySpec, opts.RegistrySettings)
5152
if err != nil {
5253
return fmt.Errorf("extract app preflight spec: %w", err)
5354
}

api/controllers/app/install/test_suite.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
190190
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
191191
mock.InOrder(
192192
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
193-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(expectedAPF, nil),
193+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(expectedAPF, nil),
194194
apm.On("RunAppPreflights", mock.Anything, mock.MatchedBy(func(opts apppreflightmanager.RunAppPreflightOptions) bool {
195195
return expectedAPF == opts.AppPreflightSpec
196196
})).Return(nil),
@@ -216,7 +216,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
216216
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
217217
mock.InOrder(
218218
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
219-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(expectedAPF, nil),
219+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(expectedAPF, nil),
220220
apm.On("RunAppPreflights", mock.Anything, mock.MatchedBy(func(opts apppreflightmanager.RunAppPreflightOptions) bool {
221221
return expectedAPF == opts.AppPreflightSpec
222222
})).Return(nil),
@@ -242,7 +242,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
242242
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
243243
mock.InOrder(
244244
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
245-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(expectedAPF, nil),
245+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(expectedAPF, nil),
246246
apm.On("RunAppPreflights", mock.Anything, mock.MatchedBy(func(opts apppreflightmanager.RunAppPreflightOptions) bool {
247247
return expectedAPF == opts.AppPreflightSpec
248248
})).Return(nil),
@@ -268,7 +268,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
268268
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
269269
mock.InOrder(
270270
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
271-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(expectedAPF, nil),
271+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(expectedAPF, nil),
272272
apm.On("RunAppPreflights", mock.Anything, mock.MatchedBy(func(opts apppreflightmanager.RunAppPreflightOptions) bool {
273273
return expectedAPF == opts.AppPreflightSpec
274274
})).Return(nil),
@@ -294,7 +294,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
294294
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
295295
mock.InOrder(
296296
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
297-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(expectedAPF, nil),
297+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(expectedAPF, nil),
298298
apm.On("RunAppPreflights", mock.Anything, mock.MatchedBy(func(opts apppreflightmanager.RunAppPreflightOptions) bool {
299299
return expectedAPF == opts.AppPreflightSpec
300300
})).Return(nil),
@@ -313,7 +313,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
313313
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
314314
mock.InOrder(
315315
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
316-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(expectedAPF, nil),
316+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(expectedAPF, nil),
317317
apm.On("RunAppPreflights", mock.Anything, mock.MatchedBy(func(opts apppreflightmanager.RunAppPreflightOptions) bool {
318318
return expectedAPF == opts.AppPreflightSpec
319319
})).Return(nil),
@@ -332,7 +332,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
332332
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
333333
mock.InOrder(
334334
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
335-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(expectedAPF, nil),
335+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(expectedAPF, nil),
336336
apm.On("RunAppPreflights", mock.Anything, mock.MatchedBy(func(opts apppreflightmanager.RunAppPreflightOptions) bool {
337337
return expectedAPF == opts.AppPreflightSpec
338338
})).Return(nil),
@@ -358,7 +358,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
358358
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
359359
mock.InOrder(
360360
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
361-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(nil, errors.New("extraction error")),
361+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(nil, errors.New("extraction error")),
362362
)
363363
},
364364
expectedErr: true,
@@ -373,7 +373,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
373373
setupMocks: func(apm *apppreflightmanager.MockAppPreflightManager, arm *appreleasemanager.MockAppReleaseManager, acm *appconfig.MockAppConfigManager) {
374374
mock.InOrder(
375375
acm.On("GetConfigValues").Return(types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, nil),
376-
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything).Return(expectedAPF, nil),
376+
arm.On("ExtractAppPreflightSpec", mock.Anything, types.AppConfigValues{"test-item": types.AppConfigValue{Value: "test-value"}}, mock.Anything, mock.Anything).Return(expectedAPF, nil),
377377
apm.On("RunAppPreflights", mock.Anything, mock.MatchedBy(func(opts apppreflightmanager.RunAppPreflightOptions) bool {
378378
return expectedAPF == opts.AppPreflightSpec
379379
})).Return(errors.New("run preflights error")),

api/controllers/linux/install/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Controller interface {
3434
GetHostPreflightTitles(ctx context.Context) ([]string, error)
3535
SetupInfra(ctx context.Context, ignoreHostPreflights bool) error
3636
GetInfra(ctx context.Context) (types.Infra, error)
37+
CalculateRegistrySettings(ctx context.Context) (*types.RegistrySettings, error)
3738
// App controller methods
3839
appcontroller.Controller
3940
}
@@ -239,6 +240,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
239240
installation.WithInstallationStore(controller.store.LinuxInstallationStore()),
240241
installation.WithLicense(controller.license),
241242
installation.WithAirgapBundle(controller.airgapBundle),
243+
installation.WithReleaseData(controller.releaseData),
242244
installation.WithHostUtils(controller.hostUtils),
243245
installation.WithNetUtils(controller.netUtils),
244246
)

api/controllers/linux/install/controller_mock.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,12 @@ func (m *MockController) GetAppInstallStatus(ctx context.Context) (types.AppInst
152152
args := m.Called(ctx)
153153
return args.Get(0).(types.AppInstall), args.Error(1)
154154
}
155+
156+
// CalculateRegistrySettings mocks the CalculateRegistrySettings method
157+
func (m *MockController) CalculateRegistrySettings(ctx context.Context) (*types.RegistrySettings, error) {
158+
args := m.Called(ctx)
159+
if args.Get(0) == nil {
160+
return nil, args.Error(1)
161+
}
162+
return args.Get(0).(*types.RegistrySettings), args.Error(1)
163+
}

api/controllers/linux/install/installation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,7 @@ func (c *InstallController) computeCIDRs(config *types.LinuxInstallationConfig)
171171
func (c *InstallController) GetInstallationStatus(ctx context.Context) (types.Status, error) {
172172
return c.installationManager.GetStatus()
173173
}
174+
175+
func (c *InstallController) CalculateRegistrySettings(ctx context.Context) (*types.RegistrySettings, error) {
176+
return c.installationManager.CalculateRegistrySettings(ctx, c.rc)
177+
}

api/integration/kubernetes/install/apppreflight_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func TestPostRunAppPreflights(t *testing.T) {
198198

199199
// Create mock app release manager
200200
mockAppReleaseManager := &appreleasemanager.MockAppReleaseManager{}
201-
mockAppReleaseManager.On("ExtractAppPreflightSpec", mock.Anything, mock.Anything, mock.Anything).Return(&troubleshootv1beta2.PreflightSpec{
201+
mockAppReleaseManager.On("ExtractAppPreflightSpec", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&troubleshootv1beta2.PreflightSpec{
202202
Analyzers: []*troubleshootv1beta2.Analyze{
203203
{
204204
ClusterVersion: &troubleshootv1beta2.ClusterVersion{

api/integration/linux/install/apppreflight_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func TestPostRunAppPreflights(t *testing.T) {
198198

199199
// Create mock app release manager
200200
mockAppReleaseManager := &appreleasemanager.MockAppReleaseManager{}
201-
mockAppReleaseManager.On("ExtractAppPreflightSpec", mock.Anything, mock.Anything, mock.Anything).Return(&troubleshootv1beta2.PreflightSpec{
201+
mockAppReleaseManager.On("ExtractAppPreflightSpec", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&troubleshootv1beta2.PreflightSpec{
202202
Analyzers: []*troubleshootv1beta2.Analyze{
203203
{
204204
ClusterVersion: &troubleshootv1beta2.ClusterVersion{

api/internal/handlers/linux/install.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,17 @@ func (h *Handler) GetHostPreflightsStatus(w http.ResponseWriter, r *http.Request
163163
// @Failure 400 {object} types.APIError
164164
// @Router /linux/install/app-preflights/run [post]
165165
func (h *Handler) PostRunAppPreflights(w http.ResponseWriter, r *http.Request) {
166-
err := h.installController.RunAppPreflights(r.Context(), appinstall.RunAppPreflightOptions{
166+
registrySettings, err := h.installController.CalculateRegistrySettings(r.Context())
167+
if err != nil {
168+
utils.LogError(r, err, h.logger, "failed to calculate registry settings")
169+
utils.JSONError(w, r, err, h.logger)
170+
return
171+
}
172+
173+
err = h.installController.RunAppPreflights(r.Context(), appinstall.RunAppPreflightOptions{
167174
PreflightBinaryPath: h.cfg.RuntimeConfig.PathToEmbeddedClusterBinary("kubectl-preflight"),
168175
ProxySpec: h.cfg.RuntimeConfig.ProxySpec(),
176+
RegistrySettings: registrySettings,
169177
ExtraPaths: []string{h.cfg.RuntimeConfig.EmbeddedClusterBinsSubDir()},
170178
})
171179
if err != nil {

api/internal/managers/app/release/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
// AppReleaseManager provides methods for managing the release of an app
1818
type AppReleaseManager interface {
19-
ExtractAppPreflightSpec(ctx context.Context, configValues types.AppConfigValues, proxySpec *ecv1beta1.ProxySpec) (*troubleshootv1beta2.PreflightSpec, error)
19+
ExtractAppPreflightSpec(ctx context.Context, configValues types.AppConfigValues, proxySpec *ecv1beta1.ProxySpec, registrySettings *types.RegistrySettings) (*troubleshootv1beta2.PreflightSpec, error)
2020
}
2121

2222
type appReleaseManager struct {

api/internal/managers/app/release/manager_mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type MockAppReleaseManager struct {
1717
}
1818

1919
// ExtractAppPreflightSpec mocks the ExtractAppPreflightSpec method
20-
func (m *MockAppReleaseManager) ExtractAppPreflightSpec(ctx context.Context, configValues types.AppConfigValues, proxySpec *ecv1beta1.ProxySpec) (*troubleshootv1beta2.PreflightSpec, error) {
21-
args := m.Called(ctx, configValues, proxySpec)
20+
func (m *MockAppReleaseManager) ExtractAppPreflightSpec(ctx context.Context, configValues types.AppConfigValues, proxySpec *ecv1beta1.ProxySpec, registrySettings *types.RegistrySettings) (*troubleshootv1beta2.PreflightSpec, error) {
21+
args := m.Called(ctx, configValues, proxySpec, registrySettings)
2222
if args.Get(0) == nil {
2323
return nil, args.Error(1)
2424
}

0 commit comments

Comments
 (0)