Skip to content

Commit 1b48b5c

Browse files
committed
ensure host ca bundle configmap
1 parent e1e37ae commit 1b48b5c

File tree

17 files changed

+616
-229
lines changed

17 files changed

+616
-229
lines changed

api/controllers/app/controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
2121
"github.com/sirupsen/logrus"
2222
helmcli "helm.sh/helm/v3/pkg/cli"
23+
"k8s.io/client-go/metadata"
2324
"sigs.k8s.io/controller-runtime/pkg/client"
2425
kyaml "sigs.k8s.io/yaml"
2526
)
@@ -52,6 +53,7 @@ type AppController struct {
5253
releaseData *release.ReleaseData
5354
hcli helm.Client
5455
kcli client.Client
56+
mcli metadata.Interface
5557
preflightRunner preflights.PreflightRunnerInterface
5658
kubernetesEnvSettings *helmcli.EnvSettings
5759
store store.Store
@@ -129,6 +131,12 @@ func WithKubeClient(kcli client.Client) AppControllerOption {
129131
}
130132
}
131133

134+
func WithMetadataClient(mcli metadata.Interface) AppControllerOption {
135+
return func(c *AppController) {
136+
c.mcli = mcli
137+
}
138+
}
139+
132140
func WithKubernetesEnvSettings(envSettings *helmcli.EnvSettings) AppControllerOption {
133141
return func(c *AppController) {
134142
c.kubernetesEnvSettings = envSettings
@@ -262,6 +270,7 @@ func NewAppController(opts ...AppControllerOption) (*AppController, error) {
262270
appinstallmanager.WithAirgapBundle(controller.airgapBundle),
263271
appinstallmanager.WithAppInstallStore(controller.store.AppInstallStore()),
264272
appinstallmanager.WithKubeClient(controller.kcli),
273+
appinstallmanager.WithMetadataClient(controller.mcli),
265274
appinstallmanager.WithKubernetesEnvSettings(controller.kubernetesEnvSettings),
266275
appinstallmanager.WithHelmClient(controller.hcli),
267276
)

api/controllers/app/install.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type InstallAppOptions struct {
2020
IgnoreAppPreflights bool
2121
ProxySpec *ecv1beta1.ProxySpec
2222
RegistrySettings *types.RegistrySettings
23+
HostCABundlePath string
2324
}
2425

2526
// InstallApp triggers app installation with proper state transitions and panic handling
@@ -72,12 +73,6 @@ func (c *AppController) InstallApp(ctx context.Context, opts InstallAppOptions)
7273
return fmt.Errorf("get app config values for app install: %w", err)
7374
}
7475

75-
// Get KOTS config values for KOTS CLI install
76-
kotsConfigValues, err := c.appConfigManager.GetKotsadmConfigValues()
77-
if err != nil {
78-
return fmt.Errorf("get kotsadm config values for app install: %w", err)
79-
}
80-
8176
// Extract installable Helm charts from release manager
8277
installableCharts, err := c.appReleaseManager.ExtractInstallableHelmCharts(ctx, appConfigValues, opts.ProxySpec, opts.RegistrySettings)
8378
if err != nil {
@@ -116,8 +111,8 @@ func (c *AppController) InstallApp(ctx context.Context, opts InstallAppOptions)
116111
return fmt.Errorf("set status to running: %w", err)
117112
}
118113

119-
// Install the app with installable charts and KOTS CLI
120-
err = c.appInstallManager.Install(ctx, installableCharts, kotsConfigValues, opts.RegistrySettings)
114+
// Install the app with installable charts
115+
err = c.appInstallManager.Install(ctx, installableCharts, opts.RegistrySettings, opts.HostCABundlePath)
121116
if err != nil {
122117
return fmt.Errorf("install app: %w", err)
123118
}

api/controllers/app/tests/test_suite.go

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -509,23 +509,15 @@ func (s *AppControllerTestSuite) TestInstallApp() {
509509
appConfigValues := types.AppConfigValues{
510510
"test-key": types.AppConfigValue{Value: "test-value"},
511511
}
512-
kotsConfigValues := kotsv1beta1.ConfigValues{
513-
Spec: kotsv1beta1.ConfigValuesSpec{
514-
Values: map[string]kotsv1beta1.ConfigValue{
515-
"test-key": {Value: "test-value"},
516-
},
517-
},
518-
}
519512
mock.InOrder(
520513
acm.On("GetConfigValues").Return(appConfigValues, nil),
521-
acm.On("GetKotsadmConfigValues").Return(kotsConfigValues, nil),
522514
arm.On("ExtractInstallableHelmCharts", mock.Anything, appConfigValues, mock.AnythingOfType("*v1beta1.ProxySpec"), mock.AnythingOfType("*types.RegistrySettings")).Return(expectedCharts, nil),
523515

524516
store.AppInstallMockStore.On("SetStatus", mock.MatchedBy(func(status types.Status) bool {
525517
return status.State == types.StateRunning
526518
})).Return(nil),
527519

528-
aim.On("Install", mock.Anything, expectedCharts, kotsConfigValues).Return(nil),
520+
aim.On("Install", mock.Anything, expectedCharts, mock.AnythingOfType("*types.RegistrySettings"), mock.AnythingOfType("string")).Return(nil),
529521

530522
store.AppInstallMockStore.On("SetStatus", mock.MatchedBy(func(status types.Status) bool {
531523
return status.State == types.StateSucceeded
@@ -542,23 +534,15 @@ func (s *AppControllerTestSuite) TestInstallApp() {
542534
appConfigValues := types.AppConfigValues{
543535
"test-key": types.AppConfigValue{Value: "test-value"},
544536
}
545-
kotsConfigValues := kotsv1beta1.ConfigValues{
546-
Spec: kotsv1beta1.ConfigValuesSpec{
547-
Values: map[string]kotsv1beta1.ConfigValue{
548-
"test-key": {Value: "test-value"},
549-
},
550-
},
551-
}
552537
mock.InOrder(
553538
acm.On("GetConfigValues").Return(appConfigValues, nil),
554-
acm.On("GetKotsadmConfigValues").Return(kotsConfigValues, nil),
555539
arm.On("ExtractInstallableHelmCharts", mock.Anything, appConfigValues, mock.AnythingOfType("*v1beta1.ProxySpec"), mock.AnythingOfType("*types.RegistrySettings")).Return([]types.InstallableHelmChart{}, nil),
556540

557541
store.AppInstallMockStore.On("SetStatus", mock.MatchedBy(func(status types.Status) bool {
558542
return status.State == types.StateRunning
559543
})).Return(nil),
560544

561-
aim.On("Install", mock.Anything, []types.InstallableHelmChart{}, kotsConfigValues).Return(nil),
545+
aim.On("Install", mock.Anything, []types.InstallableHelmChart{}, mock.AnythingOfType("*types.RegistrySettings"), mock.AnythingOfType("string")).Return(nil),
562546

563547
store.AppInstallMockStore.On("SetStatus", mock.MatchedBy(func(status types.Status) bool {
564548
return status.State == types.StateSucceeded
@@ -575,23 +559,15 @@ func (s *AppControllerTestSuite) TestInstallApp() {
575559
appConfigValues := types.AppConfigValues{
576560
"test-key": types.AppConfigValue{Value: "test-value"},
577561
}
578-
kotsConfigValues := kotsv1beta1.ConfigValues{
579-
Spec: kotsv1beta1.ConfigValuesSpec{
580-
Values: map[string]kotsv1beta1.ConfigValue{
581-
"test-key": {Value: "test-value"},
582-
},
583-
},
584-
}
585562
mock.InOrder(
586563
acm.On("GetConfigValues").Return(appConfigValues, nil),
587-
acm.On("GetKotsadmConfigValues").Return(kotsConfigValues, nil),
588564
arm.On("ExtractInstallableHelmCharts", mock.Anything, appConfigValues, mock.AnythingOfType("*v1beta1.ProxySpec"), mock.AnythingOfType("*types.RegistrySettings")).Return([]types.InstallableHelmChart{}, nil),
589565

590566
store.AppInstallMockStore.On("SetStatus", mock.MatchedBy(func(status types.Status) bool {
591567
return status.State == types.StateRunning
592568
})).Return(nil),
593569

594-
aim.On("Install", mock.Anything, []types.InstallableHelmChart{}, kotsConfigValues).Return(errors.New("install error")),
570+
aim.On("Install", mock.Anything, []types.InstallableHelmChart{}, mock.AnythingOfType("*types.RegistrySettings"), mock.AnythingOfType("string")).Return(errors.New("install error")),
595571

596572
store.AppInstallMockStore.On("SetStatus", mock.MatchedBy(func(status types.Status) bool {
597573
return status.State == types.StateFailed && strings.Contains(status.Description, "install error")
@@ -620,13 +596,6 @@ func (s *AppControllerTestSuite) TestInstallApp() {
620596
appConfigValues := types.AppConfigValues{
621597
"test-key": types.AppConfigValue{Value: "test-value"},
622598
}
623-
kotsConfigValues := kotsv1beta1.ConfigValues{
624-
Spec: kotsv1beta1.ConfigValuesSpec{
625-
Values: map[string]kotsv1beta1.ConfigValue{
626-
"test-key": {Value: "test-value"},
627-
},
628-
},
629-
}
630599
mock.InOrder(
631600
// Mock GetAppPreflightOutput to return non-strict failures (can be bypassed)
632601
apm.On("GetAppPreflightOutput", mock.Anything).Return(&types.PreflightsOutput{
@@ -640,14 +609,13 @@ func (s *AppControllerTestSuite) TestInstallApp() {
640609
}, nil),
641610

642611
acm.On("GetConfigValues").Return(appConfigValues, nil),
643-
acm.On("GetKotsadmConfigValues").Return(kotsConfigValues, nil),
644612
arm.On("ExtractInstallableHelmCharts", mock.Anything, appConfigValues, mock.AnythingOfType("*v1beta1.ProxySpec"), mock.AnythingOfType("*types.RegistrySettings")).Return([]types.InstallableHelmChart{}, nil),
645613

646614
store.AppInstallMockStore.On("SetStatus", mock.MatchedBy(func(status types.Status) bool {
647615
return status.State == types.StateRunning
648616
})).Return(nil),
649617

650-
aim.On("Install", mock.Anything, []types.InstallableHelmChart{}, kotsConfigValues).Return(nil),
618+
aim.On("Install", mock.Anything, []types.InstallableHelmChart{}, mock.AnythingOfType("*types.RegistrySettings"), mock.AnythingOfType("string")).Return(nil),
651619

652620
store.AppInstallMockStore.On("SetStatus", mock.MatchedBy(func(status types.Status) bool {
653621
return status.State == types.StateSucceeded

api/controllers/kubernetes/install/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
225225
appcontroller.WithPrivateCACertConfigMapName(""), // Private CA ConfigMap functionality not yet implemented for Kubernetes installations
226226
appcontroller.WithHelmClient(controller.hcli),
227227
appcontroller.WithKubeClient(controller.kcli),
228+
appcontroller.WithMetadataClient(controller.mcli),
228229
appcontroller.WithKubernetesEnvSettings(controller.kubernetesEnvSettings),
229230
appcontroller.WithPreflightRunner(controller.preflightRunner),
230231
)

api/controllers/kubernetes/upgrade/controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/replicatedhq/embedded-cluster/pkg/release"
1616
"github.com/sirupsen/logrus"
1717
helmcli "helm.sh/helm/v3/pkg/cli"
18+
"k8s.io/client-go/metadata"
1819
"sigs.k8s.io/controller-runtime/pkg/client"
1920
)
2021

@@ -28,6 +29,7 @@ var _ Controller = (*UpgradeController)(nil)
2829
type UpgradeController struct {
2930
hcli helm.Client
3031
kcli client.Client
32+
mcli metadata.Interface
3133
preflightRunner preflights.PreflightRunnerInterface
3234
kubernetesEnvSettings *helmcli.EnvSettings
3335
releaseData *release.ReleaseData
@@ -61,6 +63,12 @@ func WithKubeClient(kcli client.Client) UpgradeControllerOption {
6163
}
6264
}
6365

66+
func WithMetadataClient(mcli metadata.Interface) UpgradeControllerOption {
67+
return func(c *UpgradeController) {
68+
c.mcli = mcli
69+
}
70+
}
71+
6472
func WithPreflightRunner(preflightRunner preflights.PreflightRunnerInterface) UpgradeControllerOption {
6573
return func(c *UpgradeController) {
6674
c.preflightRunner = preflightRunner
@@ -151,6 +159,7 @@ func NewUpgradeController(opts ...UpgradeControllerOption) (*UpgradeController,
151159
appcontroller.WithPrivateCACertConfigMapName(""), // Private CA ConfigMap functionality not yet implemented for Kubernetes installations
152160
appcontroller.WithHelmClient(controller.hcli),
153161
appcontroller.WithKubeClient(controller.kcli),
162+
appcontroller.WithMetadataClient(controller.mcli),
154163
appcontroller.WithKubernetesEnvSettings(controller.kubernetesEnvSettings),
155164
appcontroller.WithPreflightRunner(controller.preflightRunner),
156165
)

api/controllers/linux/install/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
314314
appcontroller.WithPrivateCACertConfigMapName(adminconsole.PrivateCASConfigMapName), // Linux installations use the ConfigMap
315315
appcontroller.WithHelmClient(controller.hcli),
316316
appcontroller.WithKubeClient(controller.kcli),
317+
appcontroller.WithMetadataClient(controller.mcli),
317318
appcontroller.WithKubernetesEnvSettings(controller.rc.GetKubernetesEnvSettings()),
318319
appcontroller.WithPreflightRunner(controller.preflightRunner),
319320
)

api/controllers/linux/upgrade/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ func NewUpgradeController(opts ...UpgradeControllerOption) (*UpgradeController,
321321
appcontroller.WithPrivateCACertConfigMapName(adminconsole.PrivateCASConfigMapName), // Linux upgrades use the ConfigMap
322322
appcontroller.WithHelmClient(controller.hcli),
323323
appcontroller.WithKubeClient(controller.kcli),
324+
appcontroller.WithMetadataClient(controller.mcli),
324325
appcontroller.WithKubernetesEnvSettings(controller.rc.GetKubernetesEnvSettings()),
325326
appcontroller.WithPreflightRunner(controller.preflightRunner),
326327
)

api/internal/handlers/kubernetes/kubernetes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func New(cfg types.APIConfig, opts ...Option) (*Handler, error) {
138138
upgrade.WithConfigValues(h.cfg.ConfigValues),
139139
upgrade.WithHelmClient(h.hcli),
140140
upgrade.WithKubeClient(h.kcli),
141+
upgrade.WithMetadataClient(h.mcli),
141142
upgrade.WithPreflightRunner(h.preflightRunner),
142143
)
143144
if err != nil {

api/internal/handlers/linux/install/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ func (h *Handler) PostInstallApp(w http.ResponseWriter, r *http.Request) {
494494
IgnoreAppPreflights: req.IgnoreAppPreflights,
495495
ProxySpec: h.cfg.RuntimeConfig.ProxySpec(),
496496
RegistrySettings: registrySettings,
497+
HostCABundlePath: h.cfg.RuntimeConfig.HostCABundlePath(),
497498
})
498499
if err != nil {
499500
utils.LogError(r, err, h.logger, "failed to install app")

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ import (
99
"github.com/replicatedhq/embedded-cluster/api/types"
1010
"github.com/replicatedhq/embedded-cluster/pkg/helm"
1111
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
12-
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1312
)
1413

15-
// Install installs the app with the provided config values
16-
func (m *appInstallManager) Install(ctx context.Context, installableCharts []types.InstallableHelmChart, configValues kotsv1beta1.ConfigValues, registrySettings *types.RegistrySettings) error {
17-
if err := m.initKubeClient(); err != nil {
18-
return fmt.Errorf("init kube client: %w", err)
14+
// Install installs the app with the provided Helm charts
15+
func (m *appInstallManager) Install(ctx context.Context, installableCharts []types.InstallableHelmChart, registrySettings *types.RegistrySettings, hostCABundlePath string) error {
16+
if err := m.setupClients(); err != nil {
17+
return fmt.Errorf("setup clients: %w", err)
1918
}
2019

2120
// Start the namespace reconciler to ensure image pull secrets and other required resources in app namespaces
22-
nsReconciler, err := runNamespaceReconciler(ctx, m.kcli, registrySettings, m.logger)
21+
nsReconciler, err := runNamespaceReconciler(ctx, m.kcli, m.mcli, registrySettings, hostCABundlePath, m.logger)
2322
if err != nil {
2423
return fmt.Errorf("start namespace reconciler: %w", err)
2524
}

0 commit comments

Comments
 (0)