Skip to content

Commit 1ae4d94

Browse files
committed
fix(api): use correct helm client k8s version (#2751)
* fix(api): use correct helm client k8s version * f * use embedded k0s version for linux installs * use embedded k0s version for linux installs * pass in k8s version to app release manager when target is kubernetes * f
1 parent cfefc0c commit 1ae4d94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+393
-179
lines changed

api/api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func WithMetricsReporter(metricsReporter metrics.ReporterInterface) Option {
9595

9696
// New creates a new API instance.
9797
func New(cfg types.APIConfig, opts ...Option) (*API, error) {
98+
if cfg.InstallTarget == "" {
99+
return nil, fmt.Errorf("target is required")
100+
}
101+
98102
api := &API{
99103
cfg: cfg,
100104
}

api/controllers/app/install/controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type InstallController struct {
4848
clusterID string
4949
airgapBundle string
5050
privateCACertConfigMapName string
51+
k8sVersion string
5152
restClientGetter genericclioptions.RESTClientGetter
5253
kubeConfigPath string
5354
}
@@ -132,6 +133,12 @@ func WithPrivateCACertConfigMapName(configMapName string) InstallControllerOptio
132133
}
133134
}
134135

136+
func WithK8sVersion(k8sVersion string) InstallControllerOption {
137+
return func(c *InstallController) {
138+
c.k8sVersion = k8sVersion
139+
}
140+
}
141+
135142
func WithRESTClientGetter(restClientGetter genericclioptions.RESTClientGetter) InstallControllerOption {
136143
return func(c *InstallController) {
137144
c.restClientGetter = restClientGetter
@@ -205,6 +212,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
205212
appreleasemanager.WithReleaseData(controller.releaseData),
206213
appreleasemanager.WithLicense(license),
207214
appreleasemanager.WithPrivateCACertConfigMapName(controller.privateCACertConfigMapName),
215+
appreleasemanager.WithK8sVersion(controller.k8sVersion),
208216
)
209217
if err != nil {
210218
return nil, fmt.Errorf("create app release manager: %w", err)
@@ -220,6 +228,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
220228
appinstallmanager.WithClusterID(controller.clusterID),
221229
appinstallmanager.WithAirgapBundle(controller.airgapBundle),
222230
appinstallmanager.WithAppInstallStore(controller.store.AppInstallStore()),
231+
appinstallmanager.WithK8sVersion(controller.k8sVersion),
223232
appinstallmanager.WithRESTClientGetter(controller.restClientGetter),
224233
appinstallmanager.WithKubeConfigPath(controller.kubeConfigPath),
225234
)

api/controllers/app/install/test_suite.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func (s *AppInstallControllerTestSuite) TestPatchAppConfigValues() {
142142
WithAppInstallManager(appInstallManager),
143143
WithStore(&store.MockStore{}),
144144
WithReleaseData(&release.ReleaseData{}),
145+
WithK8sVersion("v1.33.0"),
145146
)
146147
require.NoError(t, err, "failed to create install controller")
147148

@@ -409,6 +410,7 @@ func (s *AppInstallControllerTestSuite) TestRunAppPreflights() {
409410
WithAppReleaseManager(appReleaseManager),
410411
WithStore(&store.MockStore{}),
411412
WithReleaseData(&release.ReleaseData{}),
413+
WithK8sVersion("v1.33.0"),
412414
)
413415
require.NoError(t, err, "failed to create install controller")
414416

@@ -481,6 +483,7 @@ func (s *AppInstallControllerTestSuite) TestGetAppInstallStatus() {
481483
WithAppInstallManager(appInstallManager),
482484
WithStore(&store.MockStore{}),
483485
WithReleaseData(&release.ReleaseData{}),
486+
WithK8sVersion("v1.33.0"),
484487
)
485488
require.NoError(t, err, "failed to create install controller")
486489

@@ -692,6 +695,7 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
692695
WithAppInstallManager(appInstallManager),
693696
WithStore(&store.MockStore{}),
694697
WithReleaseData(&release.ReleaseData{}),
698+
WithK8sVersion("v1.33.0"),
695699
)
696700
require.NoError(t, err, "failed to create install controller")
697701

api/controllers/kubernetes/install/controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type InstallController struct {
3737
installationManager installation.InstallationManager
3838
infraManager infra.InfraManager
3939
metricsReporter metrics.ReporterInterface
40+
k8sVersion string
4041
restClientGetter genericclioptions.RESTClientGetter
4142
releaseData *release.ReleaseData
4243
password string
@@ -73,6 +74,12 @@ func WithMetricsReporter(metricsReporter metrics.ReporterInterface) InstallContr
7374
}
7475
}
7576

77+
func WithK8sVersion(k8sVersion string) InstallControllerOption {
78+
return func(c *InstallController) {
79+
c.k8sVersion = k8sVersion
80+
}
81+
}
82+
7683
func WithRESTClientGetter(restClientGetter genericclioptions.RESTClientGetter) InstallControllerOption {
7784
return func(c *InstallController) {
7885
c.restClientGetter = restClientGetter
@@ -191,7 +198,8 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
191198
appcontroller.WithReleaseData(controller.releaseData),
192199
appcontroller.WithConfigValues(controller.configValues),
193200
appcontroller.WithAirgapBundle(controller.airgapBundle),
194-
appcontroller.WithPrivateCACertConfigMapName(""), // Private CA ConfigMap functionality not yet implemented for Kubernetes installations
201+
appcontroller.WithPrivateCACertConfigMapName(""), // Private CA ConfigMap functionality not yet implemented for Kubernetes installations
202+
appcontroller.WithK8sVersion(controller.k8sVersion), // Used to determine the kubernetes version for the helm client
195203
appcontroller.WithRESTClientGetter(controller.restClientGetter),
196204
)
197205
if err != nil {

api/controllers/kubernetes/install/controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func TestGetInstallationConfig(t *testing.T) {
102102
WithInstallation(ki),
103103
WithInstallationManager(mockManager),
104104
WithReleaseData(getTestReleaseData(&kotsv1beta1.Config{})),
105+
WithK8sVersion("v1.33.0"),
105106
)
106107
require.NoError(t, err)
107108

@@ -219,6 +220,7 @@ func TestConfigureInstallation(t *testing.T) {
219220
WithStore(mockStore),
220221
WithMetricsReporter(metricsReporter),
221222
WithReleaseData(getTestReleaseData(&kotsv1beta1.Config{})),
223+
WithK8sVersion("v1.33.0"),
222224
)
223225
require.NoError(t, err)
224226

@@ -282,6 +284,7 @@ func TestGetInstallationStatus(t *testing.T) {
282284
controller, err := NewInstallController(
283285
WithInstallationManager(mockManager),
284286
WithReleaseData(getTestReleaseData(&kotsv1beta1.Config{})),
287+
WithK8sVersion("v1.33.0"),
285288
)
286289
require.NoError(t, err)
287290

@@ -408,6 +411,7 @@ func TestSetupInfra(t *testing.T) {
408411
appcontroller.WithStore(mockStore),
409412
appcontroller.WithReleaseData(getTestReleaseData(&appConfig)),
410413
appcontroller.WithAppConfigManager(mockAppConfigManager),
414+
appcontroller.WithK8sVersion("v1.33.0"),
411415
)
412416
require.NoError(t, err)
413417

@@ -420,6 +424,7 @@ func TestSetupInfra(t *testing.T) {
420424
WithMetricsReporter(mockMetricsReporter),
421425
WithReleaseData(getTestReleaseData(&appConfig)),
422426
WithStore(mockStore),
427+
WithK8sVersion("v1.33.0"),
423428
)
424429
require.NoError(t, err)
425430

@@ -514,6 +519,7 @@ func TestGetInfra(t *testing.T) {
514519
controller, err := NewInstallController(
515520
WithInfraManager(mockManager),
516521
WithReleaseData(getTestReleaseData(&kotsv1beta1.Config{})),
522+
WithK8sVersion("v1.33.0"),
517523
)
518524
require.NoError(t, err)
519525

api/controllers/linux/install/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
2222
"github.com/replicatedhq/embedded-cluster/pkg/release"
2323
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
24+
"github.com/replicatedhq/embedded-cluster/pkg/versions"
2425
"github.com/sirupsen/logrus"
2526
)
2627

@@ -266,6 +267,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
266267
appcontroller.WithClusterID(controller.clusterID),
267268
appcontroller.WithAirgapBundle(controller.airgapBundle),
268269
appcontroller.WithPrivateCACertConfigMapName(adminconsole.PrivateCASConfigMapName), // Linux installations use the ConfigMap
270+
appcontroller.WithK8sVersion(versions.K0sVersion), // Used to determine the kubernetes version for the helm client
269271
appcontroller.WithKubeConfigPath(controller.rc.PathToKubeConfig()),
270272
)
271273
if err != nil {

api/controllers/linux/install/controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ func TestSetupInfra(t *testing.T) {
11991199
appcontroller.WithStateMachine(sm),
12001200
appcontroller.WithStore(mockStore),
12011201
appcontroller.WithReleaseData(getTestReleaseData(&appConfig)),
1202+
appcontroller.WithK8sVersion("v1.33.0"),
12021203
appcontroller.WithLicense([]byte("spec:\n licenseID: test-license\n")),
12031204
appcontroller.WithAppConfigManager(mockAppConfigManager),
12041205
appcontroller.WithAppPreflightManager(mockAppPreflightManager),

api/handlers.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
healthhandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/health"
99
kuberneteshandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/kubernetes"
1010
linuxhandler "github.com/replicatedhq/embedded-cluster/api/internal/handlers/linux"
11+
apitypes "github.com/replicatedhq/embedded-cluster/api/types"
1112
)
1213

1314
type handlers struct {
@@ -49,28 +50,30 @@ func (a *API) initHandlers() error {
4950
}
5051
a.handlers.health = healthHandler
5152

52-
// Linux handler
53-
linuxHandler, err := linuxhandler.New(
54-
a.cfg,
55-
linuxhandler.WithLogger(a.logger),
56-
linuxhandler.WithMetricsReporter(a.metricsReporter),
57-
linuxhandler.WithInstallController(a.linuxInstallController),
58-
)
59-
if err != nil {
60-
return fmt.Errorf("new linux handler: %w", err)
61-
}
62-
a.handlers.linux = linuxHandler
53+
switch a.cfg.InstallTarget {
54+
case apitypes.InstallTargetLinux:
55+
linuxHandler, err := linuxhandler.New(
56+
a.cfg,
57+
linuxhandler.WithLogger(a.logger),
58+
linuxhandler.WithMetricsReporter(a.metricsReporter),
59+
linuxhandler.WithInstallController(a.linuxInstallController),
60+
)
61+
if err != nil {
62+
return fmt.Errorf("new linux handler: %w", err)
63+
}
64+
a.handlers.linux = linuxHandler
6365

64-
// Kubernetes handler
65-
kubernetesHandler, err := kuberneteshandler.New(
66-
a.cfg,
67-
kuberneteshandler.WithLogger(a.logger),
68-
kuberneteshandler.WithInstallController(a.kubernetesInstallController),
69-
)
70-
if err != nil {
71-
return fmt.Errorf("new kubernetes handler: %w", err)
66+
case apitypes.InstallTargetKubernetes:
67+
kubernetesHandler, err := kuberneteshandler.New(
68+
a.cfg,
69+
kuberneteshandler.WithLogger(a.logger),
70+
kuberneteshandler.WithInstallController(a.kubernetesInstallController),
71+
)
72+
if err != nil {
73+
return fmt.Errorf("new kubernetes handler: %w", err)
74+
}
75+
a.handlers.kubernetes = kubernetesHandler
7276
}
73-
a.handlers.kubernetes = kubernetesHandler
7477

7578
return nil
7679
}

api/integration/app/install/config_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ func TestAppInstallSuite(t *testing.T) {
10511051
)
10521052
require.NoError(t, err)
10531053
// Create the API with the install controller
1054-
return integration.NewAPIWithReleaseData(t,
1054+
return integration.NewTargetLinuxAPIWithReleaseData(t,
10551055
api.WithLinuxInstallController(controller),
10561056
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
10571057
api.WithLogger(logger.NewDiscardLogger()),
@@ -1068,10 +1068,11 @@ func TestAppInstallSuite(t *testing.T) {
10681068
kubernetesinstall.WithReleaseData(rd),
10691069
kubernetesinstall.WithLicense([]byte("spec:\n licenseID: test-license\n")),
10701070
kubernetesinstall.WithConfigValues(configValues),
1071+
kubernetesinstall.WithK8sVersion("v1.33.0"),
10711072
)
10721073
require.NoError(t, err)
10731074
// Create the API with the install controller
1074-
return integration.NewAPIWithReleaseData(t,
1075+
return integration.NewTargetKubernetesAPIWithReleaseData(t,
10751076
api.WithKubernetesInstallController(controller),
10761077
api.WithAuthController(auth.NewStaticAuthController("TOKEN")),
10771078
api.WithLogger(logger.NewDiscardLogger()),

api/integration/auth/controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/replicatedhq/embedded-cluster/api/controllers/auth"
1414
linuxinstall "github.com/replicatedhq/embedded-cluster/api/controllers/linux/install"
1515
"github.com/replicatedhq/embedded-cluster/api/integration"
16-
"github.com/replicatedhq/embedded-cluster/api/internal/managers/linux/installation"
16+
linuxinstallation "github.com/replicatedhq/embedded-cluster/api/internal/managers/linux/installation"
1717
"github.com/replicatedhq/embedded-cluster/api/internal/utils"
1818
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
1919
"github.com/replicatedhq/embedded-cluster/api/types"
@@ -28,15 +28,15 @@ func TestAuthLoginAndTokenValidation(t *testing.T) {
2828

2929
// Create an install controller
3030
installController, err := linuxinstall.NewInstallController(
31-
linuxinstall.WithInstallationManager(installation.NewInstallationManager(
32-
installation.WithNetUtils(&utils.MockNetUtils{}),
31+
linuxinstall.WithInstallationManager(linuxinstallation.NewInstallationManager(
32+
linuxinstallation.WithNetUtils(&utils.MockNetUtils{}),
3333
)),
3434
linuxinstall.WithReleaseData(integration.DefaultReleaseData()),
3535
)
3636
require.NoError(t, err)
3737

3838
// Create the API with the auth controller
39-
apiInstance := integration.NewAPIWithReleaseData(t,
39+
apiInstance := integration.NewTargetLinuxAPIWithReleaseData(t,
4040
api.WithAuthController(authController),
4141
api.WithLinuxInstallController(installController),
4242
api.WithLogger(logger.NewDiscardLogger()),
@@ -134,7 +134,7 @@ func TestAuthLoginAndTokenValidation(t *testing.T) {
134134

135135
func TestAPIClientLogin(t *testing.T) {
136136
// Create the API with the auth controller
137-
apiInstance := integration.NewAPIWithReleaseData(t,
137+
apiInstance := integration.NewTargetLinuxAPIWithReleaseData(t,
138138
api.WithLogger(logger.NewDiscardLogger()),
139139
)
140140

0 commit comments

Comments
 (0)