Skip to content

Commit 20cd4b8

Browse files
authored
Deploy kots and app to namespace named appslug (#3070)
* Set kotsadm namespace to appslug for new installations Signed-off-by: Steven Crespo <[email protected]>
1 parent d4878e0 commit 20cd4b8

Some content is hidden

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

65 files changed

+773
-202
lines changed

api/controllers/app/controller.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/replicatedhq/embedded-cluster/pkg/release"
1919
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
2020
"github.com/sirupsen/logrus"
21+
helmcli "helm.sh/helm/v3/pkg/cli"
22+
"sigs.k8s.io/controller-runtime/pkg/client"
2123
kyaml "sigs.k8s.io/yaml"
2224
)
2325

@@ -48,6 +50,8 @@ type AppController struct {
4850
license []byte
4951
releaseData *release.ReleaseData
5052
hcli helm.Client
53+
kcli client.Client
54+
kubernetesEnvSettings *helmcli.EnvSettings
5155
store store.Store
5256
configValues types.AppConfigValues
5357
clusterID string
@@ -117,6 +121,18 @@ func WithHelmClient(hcli helm.Client) AppControllerOption {
117121
}
118122
}
119123

124+
func WithKubeClient(kcli client.Client) AppControllerOption {
125+
return func(c *AppController) {
126+
c.kcli = kcli
127+
}
128+
}
129+
130+
func WithKubernetesEnvSettings(envSettings *helmcli.EnvSettings) AppControllerOption {
131+
return func(c *AppController) {
132+
c.kubernetesEnvSettings = envSettings
133+
}
134+
}
135+
120136
func WithConfigValues(configValues types.AppConfigValues) AppControllerOption {
121137
return func(c *AppController) {
122138
c.configValues = configValues
@@ -177,6 +193,7 @@ func NewAppController(opts ...AppControllerOption) (*AppController, error) {
177193
appconfig.WithLicense(license),
178194
appconfig.WithIsAirgap(controller.airgapBundle != ""),
179195
appconfig.WithPrivateCACertConfigMapName(controller.privateCACertConfigMapName),
196+
appconfig.WithKubeClient(controller.kcli),
180197
)
181198
if err != nil {
182199
return nil, fmt.Errorf("failed to create app config manager: %w", err)
@@ -211,6 +228,7 @@ func NewAppController(opts ...AppControllerOption) (*AppController, error) {
211228
appreleasemanager.WithIsAirgap(controller.airgapBundle != ""),
212229
appreleasemanager.WithPrivateCACertConfigMapName(controller.privateCACertConfigMapName),
213230
appreleasemanager.WithHelmClient(controller.hcli),
231+
appreleasemanager.WithKubeClient(controller.kcli),
214232
)
215233
if err != nil {
216234
return nil, fmt.Errorf("create app release manager: %w", err)
@@ -226,6 +244,8 @@ func NewAppController(opts ...AppControllerOption) (*AppController, error) {
226244
appinstallmanager.WithClusterID(controller.clusterID),
227245
appinstallmanager.WithAirgapBundle(controller.airgapBundle),
228246
appinstallmanager.WithAppInstallStore(controller.store.AppInstallStore()),
247+
appinstallmanager.WithKubeClient(controller.kcli),
248+
appinstallmanager.WithKubernetesEnvSettings(controller.kubernetesEnvSettings),
229249
)
230250
if err != nil {
231251
return nil, fmt.Errorf("create app install manager: %w", err)
@@ -241,6 +261,8 @@ func NewAppController(opts ...AppControllerOption) (*AppController, error) {
241261
appupgrademanager.WithClusterID(controller.clusterID),
242262
appupgrademanager.WithAirgapBundle(controller.airgapBundle),
243263
appupgrademanager.WithAppUpgradeStore(controller.store.AppUpgradeStore()),
264+
appupgrademanager.WithKubeClient(controller.kcli),
265+
appupgrademanager.WithKubernetesEnvSettings(controller.kubernetesEnvSettings),
244266
)
245267
if err != nil {
246268
return nil, fmt.Errorf("create app upgrade manager: %w", err)

api/controllers/kubernetes/install/controller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/replicatedhq/embedded-cluster/pkg/release"
2020
"github.com/sirupsen/logrus"
2121
helmcli "helm.sh/helm/v3/pkg/cli"
22+
"sigs.k8s.io/controller-runtime/pkg/client"
2223
)
2324

2425
type Controller interface {
@@ -37,8 +38,9 @@ type InstallController struct {
3738
installationManager installation.InstallationManager
3839
infraManager infra.InfraManager
3940
metricsReporter metrics.ReporterInterface
40-
kubernetesEnvSettings *helmcli.EnvSettings
4141
hcli helm.Client
42+
kcli client.Client
43+
kubernetesEnvSettings *helmcli.EnvSettings
4244
releaseData *release.ReleaseData
4345
password string
4446
tlsConfig types.TLSConfig
@@ -80,6 +82,12 @@ func WithHelmClient(hcli helm.Client) InstallControllerOption {
8082
}
8183
}
8284

85+
func WithKubeClient(kcli client.Client) InstallControllerOption {
86+
return func(c *InstallController) {
87+
c.kcli = kcli
88+
}
89+
}
90+
8391
func WithKubernetesEnvSettings(envSettings *helmcli.EnvSettings) InstallControllerOption {
8492
return func(c *InstallController) {
8593
c.kubernetesEnvSettings = envSettings
@@ -200,6 +208,8 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
200208
appcontroller.WithAirgapBundle(controller.airgapBundle),
201209
appcontroller.WithPrivateCACertConfigMapName(""), // Private CA ConfigMap functionality not yet implemented for Kubernetes installations
202210
appcontroller.WithHelmClient(controller.hcli),
211+
appcontroller.WithKubeClient(controller.kcli),
212+
appcontroller.WithKubernetesEnvSettings(controller.kubernetesEnvSettings),
203213
)
204214
if err != nil {
205215
return nil, fmt.Errorf("create app install controller: %w", err)

api/controllers/kubernetes/upgrade/controller.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/replicatedhq/embedded-cluster/pkg/release"
1515
"github.com/sirupsen/logrus"
1616
helmcli "helm.sh/helm/v3/pkg/cli"
17+
"sigs.k8s.io/controller-runtime/pkg/client"
1718
)
1819

1920
type Controller interface {
@@ -24,8 +25,9 @@ type Controller interface {
2425
var _ Controller = (*UpgradeController)(nil)
2526

2627
type UpgradeController struct {
27-
kubernetesEnvSettings *helmcli.EnvSettings
2828
hcli helm.Client
29+
kcli client.Client
30+
kubernetesEnvSettings *helmcli.EnvSettings
2931
releaseData *release.ReleaseData
3032
license []byte
3133
airgapBundle string
@@ -45,15 +47,21 @@ func WithLogger(logger logrus.FieldLogger) UpgradeControllerOption {
4547
}
4648
}
4749

48-
func WithKubernetesEnvSettings(envSettings *helmcli.EnvSettings) UpgradeControllerOption {
50+
func WithHelmClient(hcli helm.Client) UpgradeControllerOption {
4951
return func(c *UpgradeController) {
50-
c.kubernetesEnvSettings = envSettings
52+
c.hcli = hcli
5153
}
5254
}
5355

54-
func WithHelmClient(hcli helm.Client) UpgradeControllerOption {
56+
func WithKubeClient(kcli client.Client) UpgradeControllerOption {
5557
return func(c *UpgradeController) {
56-
c.hcli = hcli
58+
c.kcli = kcli
59+
}
60+
}
61+
62+
func WithKubernetesEnvSettings(envSettings *helmcli.EnvSettings) UpgradeControllerOption {
63+
return func(c *UpgradeController) {
64+
c.kubernetesEnvSettings = envSettings
5765
}
5866
}
5967

@@ -134,6 +142,8 @@ func NewUpgradeController(opts ...UpgradeControllerOption) (*UpgradeController,
134142
appcontroller.WithAirgapBundle(controller.airgapBundle),
135143
appcontroller.WithPrivateCACertConfigMapName(""), // Private CA ConfigMap functionality not yet implemented for Kubernetes installations
136144
appcontroller.WithHelmClient(controller.hcli),
145+
appcontroller.WithKubeClient(controller.kcli),
146+
appcontroller.WithKubernetesEnvSettings(controller.kubernetesEnvSettings),
137147
)
138148
if err != nil {
139149
return nil, fmt.Errorf("create app controller: %w", err)

api/controllers/linux/install/controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/replicatedhq/embedded-cluster/pkg/release"
2525
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
2626
"github.com/sirupsen/logrus"
27+
"sigs.k8s.io/controller-runtime/pkg/client"
2728
)
2829

2930
type Controller interface {
@@ -70,6 +71,7 @@ type InstallController struct {
7071
store store.Store
7172
rc runtimeconfig.RuntimeConfig
7273
hcli helm.Client
74+
kcli client.Client
7375
stateMachine statemachine.Interface
7476
logger logrus.FieldLogger
7577
allowIgnoreHostPreflights bool
@@ -223,6 +225,12 @@ func WithHelmClient(hcli helm.Client) InstallControllerOption {
223225
}
224226
}
225227

228+
func WithKubeClient(kcli client.Client) InstallControllerOption {
229+
return func(c *InstallController) {
230+
c.kcli = kcli
231+
}
232+
}
233+
226234
func NewInstallController(opts ...InstallControllerOption) (*InstallController, error) {
227235
controller := &InstallController{
228236
store: store.NewMemoryStore(),
@@ -288,6 +296,8 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
288296
appcontroller.WithAirgapBundle(controller.airgapBundle),
289297
appcontroller.WithPrivateCACertConfigMapName(adminconsole.PrivateCASConfigMapName), // Linux installations use the ConfigMap
290298
appcontroller.WithHelmClient(controller.hcli),
299+
appcontroller.WithKubeClient(controller.kcli),
300+
appcontroller.WithKubernetesEnvSettings(controller.rc.GetKubernetesEnvSettings()),
291301
)
292302
if err != nil {
293303
return nil, fmt.Errorf("create app controller: %w", err)

api/controllers/linux/upgrade/controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/replicatedhq/embedded-cluster/pkg/release"
2424
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
2525
"github.com/sirupsen/logrus"
26+
"sigs.k8s.io/controller-runtime/pkg/client"
2627
)
2728

2829
type Controller interface {
@@ -56,6 +57,7 @@ type UpgradeController struct {
5657
store store.Store
5758
rc runtimeconfig.RuntimeConfig
5859
hcli helm.Client
60+
kcli client.Client
5961
stateMachine statemachine.Interface
6062
requiresInfraUpgrade bool
6163
logger logrus.FieldLogger
@@ -181,6 +183,12 @@ func WithHelmClient(hcli helm.Client) UpgradeControllerOption {
181183
}
182184
}
183185

186+
func WithKubeClient(kcli client.Client) UpgradeControllerOption {
187+
return func(c *UpgradeController) {
188+
c.kcli = kcli
189+
}
190+
}
191+
184192
func WithEndUserConfig(endUserConfig *ecv1beta1.Config) UpgradeControllerOption {
185193
return func(c *UpgradeController) {
186194
c.endUserConfig = endUserConfig
@@ -292,6 +300,8 @@ func NewUpgradeController(opts ...UpgradeControllerOption) (*UpgradeController,
292300
appcontroller.WithAirgapBundle(controller.airgapBundle),
293301
appcontroller.WithPrivateCACertConfigMapName(adminconsole.PrivateCASConfigMapName), // Linux upgrades use the ConfigMap
294302
appcontroller.WithHelmClient(controller.hcli),
303+
appcontroller.WithKubeClient(controller.kcli),
304+
appcontroller.WithKubernetesEnvSettings(controller.rc.GetKubernetesEnvSettings()),
295305
)
296306
if err != nil {
297307
return nil, fmt.Errorf("create app controller: %w", err)

api/integration/kubernetes/install/infra_test.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
2121
"github.com/replicatedhq/embedded-cluster/api/types"
2222
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
23-
"github.com/replicatedhq/embedded-cluster/pkg-new/constants"
2423
"github.com/replicatedhq/embedded-cluster/pkg-new/kubernetesinstallation"
2524
"github.com/replicatedhq/embedded-cluster/pkg/helm"
2625
"github.com/replicatedhq/embedded-cluster/pkg/release"
@@ -41,6 +40,15 @@ import (
4140

4241
// Test the kubernetes setupInfra endpoint runs infrastructure setup correctly
4342
func TestKubernetesPostSetupInfra(t *testing.T) {
43+
// Setup environment variable for V3
44+
t.Setenv("ENABLE_V3", "1")
45+
46+
// Set up release data globally so AppSlug() returns the correct value for v3
47+
err := release.SetReleaseDataForTests(map[string][]byte{
48+
"channelrelease.yaml": []byte("# channel release object\nappSlug: test-app"),
49+
})
50+
require.NoError(t, err)
51+
4452
// Create schemes
4553
scheme := runtime.NewScheme()
4654
require.NoError(t, ecv1beta1.AddToScheme(scheme))
@@ -84,9 +92,17 @@ func TestKubernetesPostSetupInfra(t *testing.T) {
8492

8593
// Create mocks
8694
helmMock := &helm.MockClient{}
95+
96+
// Create the app namespace that will be used by the addon
97+
appNamespace := &corev1.Namespace{
98+
ObjectMeta: metav1.ObjectMeta{
99+
Name: "test-app",
100+
},
101+
}
102+
87103
fakeKcli := clientfake.NewClientBuilder().
88104
WithScheme(scheme).
89-
WithObjects(integration.NewTestControllerNode(hostname)).
105+
WithObjects(integration.NewTestControllerNode(hostname), appNamespace).
90106
WithStatusSubresource(&ecv1beta1.Installation{}, &apiextensionsv1.CustomResourceDefinition{}).
91107
WithInterceptorFuncs(integration.NewTestInterceptorFuncs()).
92108
Build()
@@ -104,6 +120,7 @@ func TestKubernetesPostSetupInfra(t *testing.T) {
104120
kubernetesinfra.WithReleaseData(&release.ReleaseData{
105121
EmbeddedClusterConfig: &ecv1beta1.Config{},
106122
ChannelRelease: &release.ChannelRelease{
123+
AppSlug: "test-app",
107124
DefaultDomains: release.Domains{
108125
ReplicatedAppDomain: "replicated.example.com",
109126
ProxyRegistryDomain: "some-proxy.example.com",
@@ -127,6 +144,7 @@ func TestKubernetesPostSetupInfra(t *testing.T) {
127144
kubernetesinstall.WithReleaseData(&release.ReleaseData{
128145
EmbeddedClusterConfig: &ecv1beta1.Config{},
129146
ChannelRelease: &release.ChannelRelease{
147+
AppSlug: "test-app",
130148
DefaultDomains: release.Domains{
131149
ReplicatedAppDomain: "replicated.example.com",
132150
ProxyRegistryDomain: "some-proxy.example.com",
@@ -212,13 +230,15 @@ func TestKubernetesPostSetupInfra(t *testing.T) {
212230
// Verify that the mock expectations were met
213231
helmMock.AssertExpectations(t)
214232

215-
// Verify kotsadm namespace and kotsadm-password secret were created
233+
// Verify app namespace and kotsadm-password secret were created
234+
// The namespace name should be the app slug ("test-app")
235+
expectedNamespace := "test-app"
216236
var gotKotsadmNamespace corev1.Namespace
217-
err = fakeKcli.Get(t.Context(), client.ObjectKey{Name: constants.KotsadmNamespace}, &gotKotsadmNamespace)
237+
err = fakeKcli.Get(t.Context(), client.ObjectKey{Name: expectedNamespace}, &gotKotsadmNamespace)
218238
require.NoError(t, err)
219239

220240
var gotKotsadmPasswordSecret corev1.Secret
221-
err = fakeKcli.Get(t.Context(), client.ObjectKey{Namespace: constants.KotsadmNamespace, Name: "kotsadm-password"}, &gotKotsadmPasswordSecret)
241+
err = fakeKcli.Get(t.Context(), client.ObjectKey{Namespace: expectedNamespace, Name: "kotsadm-password"}, &gotKotsadmPasswordSecret)
222242
require.NoError(t, err)
223243
assert.NotEmpty(t, gotKotsadmPasswordSecret.Data["passwordBcrypt"])
224244

@@ -303,6 +323,7 @@ func TestKubernetesPostSetupInfra(t *testing.T) {
303323
kubernetesinfra.WithReleaseData(&release.ReleaseData{
304324
EmbeddedClusterConfig: &ecv1beta1.Config{},
305325
ChannelRelease: &release.ChannelRelease{
326+
AppSlug: "test-app",
306327
DefaultDomains: release.Domains{
307328
ReplicatedAppDomain: "replicated.example.com",
308329
ProxyRegistryDomain: "some-proxy.example.com",
@@ -326,6 +347,7 @@ func TestKubernetesPostSetupInfra(t *testing.T) {
326347
kubernetesinstall.WithReleaseData(&release.ReleaseData{
327348
EmbeddedClusterConfig: &ecv1beta1.Config{},
328349
ChannelRelease: &release.ChannelRelease{
350+
AppSlug: "test-app",
329351
DefaultDomains: release.Domains{
330352
ReplicatedAppDomain: "replicated.example.com",
331353
ProxyRegistryDomain: "some-proxy.example.com",

0 commit comments

Comments
 (0)