Skip to content

Commit bbebb5e

Browse files
sgalsalehemosbaugh
authored andcommitted
Add missing online functionality for the image pull secret template functions (#2758)
1 parent 1ae4d94 commit bbebb5e

File tree

11 files changed

+312
-66
lines changed

11 files changed

+312
-66
lines changed

api/controllers/app/install/test_suite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ func (s *AppInstallControllerTestSuite) TestInstallApp() {
644644
NoProxy: "localhost,127.0.0.1",
645645
},
646646
registrySettings: &types.RegistrySettings{
647-
HasLocalRegistry: true,
648-
Host: "10.128.0.11:5000",
647+
HasLocalRegistry: true,
648+
LocalRegistryHost: "10.128.0.11:5000",
649649
},
650650
setupMocks: func(acm *appconfig.MockAppConfigManager, arm *appreleasemanager.MockAppReleaseManager, aim *appinstallmanager.MockAppInstallManager) {
651651
configValues := kotsv1beta1.ConfigValues{

api/integration/linux/install/appinstall_test.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ import (
3434
"github.com/stretchr/testify/require"
3535
)
3636

37+
// mockLicense creates a mock license for testing
38+
func mockLicense() []byte {
39+
return []byte(`
40+
apiVersion: kots.io/v1beta1
41+
kind: License
42+
spec:
43+
licenseID: "test-license-id-12345"
44+
appSlug: "test-app"
45+
customerName: "Test Customer"
46+
`)
47+
}
48+
3749
// TestGetAppInstallStatus tests the GET /linux/install/app/status endpoint
3850
func TestGetAppInstallStatus(t *testing.T) {
3951
// Create mock helm chart archive
@@ -44,9 +56,11 @@ func TestGetAppInstallStatus(t *testing.T) {
4456
HelmChartArchives: [][]byte{mockChartArchive},
4557
EmbeddedClusterConfig: &ecv1beta1.Config{},
4658
ChannelRelease: &release.ChannelRelease{
59+
AppSlug: "test-app",
4760
DefaultDomains: release.Domains{
48-
ReplicatedAppDomain: "replicated.example.com",
49-
ProxyRegistryDomain: "some-proxy.example.com",
61+
ReplicatedAppDomain: "replicated.example.com",
62+
ProxyRegistryDomain: "some-proxy.example.com",
63+
ReplicatedRegistryDomain: "registry.example.com",
5064
},
5165
},
5266
AppConfig: &kotsv1beta1.Config{},
@@ -109,6 +123,7 @@ func TestGetAppInstallStatus(t *testing.T) {
109123
linuxinstall.WithAppInstallController(appInstallController),
110124
linuxinstall.WithReleaseData(releaseData),
111125
linuxinstall.WithRuntimeConfig(runtimeconfig.New(nil)),
126+
linuxinstall.WithLicense(mockLicense()),
112127
)
113128
require.NoError(t, err)
114129

@@ -165,6 +180,7 @@ func TestGetAppInstallStatus(t *testing.T) {
165180
// Create simple Linux install controller
166181
installController, err := linuxinstall.NewInstallController(
167182
linuxinstall.WithReleaseData(releaseData),
183+
linuxinstall.WithLicense(mockLicense()),
168184
)
169185
require.NoError(t, err)
170186

@@ -228,9 +244,11 @@ func TestPostInstallApp(t *testing.T) {
228244
releaseData := &release.ReleaseData{
229245
EmbeddedClusterConfig: &ecv1beta1.Config{},
230246
ChannelRelease: &release.ChannelRelease{
247+
AppSlug: "test-app",
231248
DefaultDomains: release.Domains{
232-
ReplicatedAppDomain: "replicated.example.com",
233-
ProxyRegistryDomain: "some-proxy.example.com",
249+
ReplicatedAppDomain: "replicated.example.com",
250+
ProxyRegistryDomain: "some-proxy.example.com",
251+
ReplicatedRegistryDomain: "registry.example.com",
234252
},
235253
},
236254
AppConfig: &kotsv1beta1.Config{},
@@ -320,6 +338,7 @@ func TestPostInstallApp(t *testing.T) {
320338
linuxinstall.WithMetricsReporter(mockReporter),
321339
linuxinstall.WithReleaseData(releaseData),
322340
linuxinstall.WithRuntimeConfig(rc),
341+
linuxinstall.WithLicense(mockLicense()),
323342
)
324343
require.NoError(t, err)
325344

@@ -391,6 +410,7 @@ func TestPostInstallApp(t *testing.T) {
391410
linuxinstall.WithStateMachine(stateMachine),
392411
linuxinstall.WithAppInstallController(appInstallController),
393412
linuxinstall.WithReleaseData(releaseData),
413+
linuxinstall.WithLicense(mockLicense()),
394414
)
395415
require.NoError(t, err)
396416

@@ -479,6 +499,7 @@ func TestPostInstallApp(t *testing.T) {
479499
linuxinstall.WithStore(mockStore),
480500
linuxinstall.WithReleaseData(releaseData),
481501
linuxinstall.WithRuntimeConfig(rc),
502+
linuxinstall.WithLicense(mockLicense()),
482503
)
483504
require.NoError(t, err)
484505

@@ -532,6 +553,7 @@ func TestPostInstallApp(t *testing.T) {
532553
// Create simple Linux install controller
533554
installController, err := linuxinstall.NewInstallController(
534555
linuxinstall.WithReleaseData(releaseData),
556+
linuxinstall.WithLicense(mockLicense()),
535557
)
536558
require.NoError(t, err)
537559

@@ -607,6 +629,7 @@ func TestPostInstallApp(t *testing.T) {
607629
linuxinstall.WithStateMachine(stateMachine),
608630
linuxinstall.WithAppInstallController(appInstallController),
609631
linuxinstall.WithReleaseData(releaseData),
632+
linuxinstall.WithLicense(mockLicense()),
610633
)
611634
require.NoError(t, err)
612635

@@ -684,6 +707,7 @@ func TestPostInstallApp(t *testing.T) {
684707
linuxinstall.WithStateMachine(stateMachine),
685708
linuxinstall.WithAppInstallController(appInstallController),
686709
linuxinstall.WithReleaseData(releaseData),
710+
linuxinstall.WithLicense(mockLicense()),
687711
)
688712
require.NoError(t, err)
689713

api/integration/linux/install/apppreflight_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,17 @@ func TestPostRunAppPreflights(t *testing.T) {
238238
linuxinstall.WithReleaseData(&release.ReleaseData{
239239
EmbeddedClusterConfig: &ecv1beta1.Config{},
240240
ChannelRelease: &release.ChannelRelease{
241+
AppSlug: "test-app",
241242
DefaultDomains: release.Domains{
242-
ReplicatedAppDomain: "replicated.example.com",
243-
ProxyRegistryDomain: "some-proxy.example.com",
243+
ReplicatedAppDomain: "replicated.example.com",
244+
ProxyRegistryDomain: "some-proxy.example.com",
245+
ReplicatedRegistryDomain: "registry.example.com",
244246
},
245247
},
246248
AppConfig: &kotsv1beta1.Config{},
247249
}),
248250
linuxinstall.WithRuntimeConfig(rc),
251+
linuxinstall.WithLicense(mockLicense()),
249252
)
250253
require.NoError(t, err)
251254

@@ -295,8 +298,19 @@ func TestPostRunAppPreflights(t *testing.T) {
295298
linuxinstall.WithStateMachine(linuxinstall.NewStateMachine(
296299
linuxinstall.WithCurrentState(states.StateNew), // Wrong state
297300
)),
298-
linuxinstall.WithReleaseData(integration.DefaultReleaseData()),
301+
linuxinstall.WithReleaseData(&release.ReleaseData{
302+
AppConfig: &kotsv1beta1.Config{},
303+
ChannelRelease: &release.ChannelRelease{
304+
AppSlug: "test-app",
305+
DefaultDomains: release.Domains{
306+
ReplicatedAppDomain: "replicated.example.com",
307+
ProxyRegistryDomain: "some-proxy.example.com",
308+
ReplicatedRegistryDomain: "registry.example.com",
309+
},
310+
},
311+
}),
299312
linuxinstall.WithRuntimeConfig(rc),
313+
linuxinstall.WithLicense(mockLicense()),
300314
)
301315
require.NoError(t, err)
302316

api/internal/handlers/kubernetes/install.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ func (h *Handler) PostRunAppPreflights(w http.ResponseWriter, r *http.Request) {
9797
return
9898
}
9999

100+
// TODO: support registry settings
101+
100102
err = h.installController.RunAppPreflights(r.Context(), appinstall.RunAppPreflightOptions{
101103
PreflightBinaryPath: preflightBinary,
102104
ProxySpec: h.cfg.Installation.ProxySpec(),
@@ -300,6 +302,8 @@ func (h *Handler) PostInstallApp(w http.ResponseWriter, r *http.Request) {
300302
return
301303
}
302304

305+
// TODO: support registry settings
306+
303307
err := h.installController.InstallApp(r.Context(), appinstall.InstallAppOptions{
304308
IgnoreAppPreflights: req.IgnoreAppPreflights,
305309
ProxySpec: h.cfg.Installation.ProxySpec(),

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,12 @@ spec:
724724
},
725725
configValues: types.AppConfigValues{},
726726
registrySettings: &types.RegistrySettings{
727-
HasLocalRegistry: true,
728-
Host: "10.128.0.11:5000",
729-
Address: "10.128.0.11:5000/myapp",
730-
Namespace: "myapp",
731-
ImagePullSecretName: "embedded-cluster-registry",
732-
ImagePullSecretValue: "dGVzdC1zZWNyZXQtdmFsdWU=",
727+
HasLocalRegistry: true,
728+
LocalRegistryHost: "10.128.0.11:5000",
729+
LocalRegistryAddress: "10.128.0.11:5000/myapp",
730+
LocalRegistryNamespace: "myapp",
731+
ImagePullSecretName: "test-app-registry",
732+
ImagePullSecretValue: "dGVzdC1zZWNyZXQtdmFsdWU=",
733733
},
734734
expected: []*kotsv1beta2.HelmChart{
735735
createHelmChartCRFromYAML(`
@@ -746,7 +746,7 @@ spec:
746746
image:
747747
repository: "10.128.0.11:5000/myapp/nginx"
748748
imagePullSecrets:
749-
- name: "embedded-cluster-registry"
749+
- name: "test-app-registry"
750750
registry:
751751
host: "10.128.0.11:5000"
752752
address: "10.128.0.11:5000/myapp"
@@ -2346,12 +2346,12 @@ spec:
23462346
},
23472347
configValues: types.AppConfigValues{},
23482348
registrySettings: &types.RegistrySettings{
2349-
HasLocalRegistry: true,
2350-
Host: "10.128.0.11:5000",
2351-
Address: "10.128.0.11:5000/myapp",
2352-
Namespace: "myapp",
2353-
ImagePullSecretName: "embedded-cluster-registry",
2354-
ImagePullSecretValue: "dGVzdC1zZWNyZXQtdmFsdWU=",
2349+
HasLocalRegistry: true,
2350+
LocalRegistryHost: "10.128.0.11:5000",
2351+
LocalRegistryAddress: "10.128.0.11:5000/myapp",
2352+
LocalRegistryNamespace: "myapp",
2353+
ImagePullSecretName: "test-app-registry",
2354+
ImagePullSecretValue: "dGVzdC1zZWNyZXQtdmFsdWU=",
23552355
},
23562356
expectError: false,
23572357
expected: []types.InstallableHelmChart{
@@ -2363,7 +2363,7 @@ spec:
23632363
"tag": "1.20.0",
23642364
},
23652365
"imagePullSecrets": []any{
2366-
map[string]any{"name": "embedded-cluster-registry"},
2366+
map[string]any{"name": "test-app-registry"},
23672367
},
23682368
"registry": map[string]any{
23692369
"host": "10.128.0.11:5000",
@@ -2386,7 +2386,7 @@ spec:
23862386
repository: "10.128.0.11:5000/myapp/nginx"
23872387
tag: "1.20.0"
23882388
imagePullSecrets:
2389-
- name: "embedded-cluster-registry"
2389+
- name: "test-app-registry"
23902390
registry:
23912391
host: "10.128.0.11:5000"
23922392
address: "10.128.0.11:5000/myapp"

api/internal/managers/linux/installation/config.go

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import (
77
"fmt"
88
"runtime/debug"
99

10+
"github.com/replicatedhq/embedded-cluster/api/internal/utils"
1011
"github.com/replicatedhq/embedded-cluster/api/types"
1112
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1213
newconfig "github.com/replicatedhq/embedded-cluster/pkg-new/config"
1314
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils"
1415
"github.com/replicatedhq/embedded-cluster/pkg/addons/registry"
1516
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
1617
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
18+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
19+
kyaml "sigs.k8s.io/yaml"
1720
)
1821

1922
func (m *installationManager) GetConfig() (types.LinuxInstallationConfig, error) {
@@ -236,11 +239,37 @@ func (m *installationManager) ConfigureHost(ctx context.Context, rc runtimeconfi
236239
return nil
237240
}
238241

239-
// CalculateRegistrySettings calculates registry settings for airgap installations
242+
// CalculateRegistrySettings calculates registry settings for both online and airgap installations
240243
func (m *installationManager) CalculateRegistrySettings(ctx context.Context, rc runtimeconfig.RuntimeConfig) (*types.RegistrySettings, error) {
241-
// Only return registry settings for airgap installations
242244
if m.airgapBundle == "" {
243-
return nil, nil
245+
// Online mode: Use replicated proxy registry with license ID authentication
246+
ecDomains := utils.GetDomains(m.releaseData)
247+
248+
// Parse license from bytes
249+
if len(m.license) == 0 {
250+
return nil, fmt.Errorf("license is required for online registry settings")
251+
}
252+
license := &kotsv1beta1.License{}
253+
if err := kyaml.Unmarshal(m.license, license); err != nil {
254+
return nil, fmt.Errorf("parse license: %w", err)
255+
}
256+
257+
// Get app slug for secret name
258+
if m.releaseData == nil || m.releaseData.ChannelRelease == nil || m.releaseData.ChannelRelease.AppSlug == "" {
259+
return nil, fmt.Errorf("release data with app slug is required for registry settings")
260+
}
261+
appSlug := m.releaseData.ChannelRelease.AppSlug
262+
263+
// Create auth config for both proxy and registry domains
264+
authConfig := fmt.Sprintf(`{"auths":{"%s":{"username": "LICENSE_ID", "password": "%s"},"%s":{"username": "LICENSE_ID", "password": "%s"}}}`,
265+
ecDomains.ProxyRegistryDomain, license.Spec.LicenseID, ecDomains.ReplicatedRegistryDomain, license.Spec.LicenseID)
266+
imagePullSecretValue := base64.StdEncoding.EncodeToString([]byte(authConfig))
267+
268+
return &types.RegistrySettings{
269+
HasLocalRegistry: false,
270+
ImagePullSecretName: fmt.Sprintf("%s-registry", appSlug),
271+
ImagePullSecretValue: imagePullSecretValue,
272+
}, nil
244273
}
245274

246275
// Use runtime config as the authoritative source for service CIDR
@@ -254,27 +283,27 @@ func (m *installationManager) CalculateRegistrySettings(ctx context.Context, rc
254283
// Construct registry host with port
255284
registryHost := fmt.Sprintf("%s:5000", registryIP)
256285

257-
// Get app namespace from release data - required for app preflights
286+
// Get app slug for secret name
258287
if m.releaseData == nil || m.releaseData.ChannelRelease == nil || m.releaseData.ChannelRelease.AppSlug == "" {
259288
return nil, fmt.Errorf("release data with app slug is required for registry settings")
260289
}
261-
appNamespace := m.releaseData.ChannelRelease.AppSlug
290+
appSlug := m.releaseData.ChannelRelease.AppSlug
262291

263292
// Construct full registry address with namespace
293+
appNamespace := appSlug // registry namespace is the same as the app slug in linux target
264294
registryAddress := fmt.Sprintf("%s/%s", registryHost, appNamespace)
265295

266296
// Create image pull secret value using the same pattern as admin console
267-
authString := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("embedded-cluster:%s", registry.GetRegistryPassword())))
268-
authConfig := fmt.Sprintf(`{"auths":{"%s":{"username": "embedded-cluster", "password": "%s", "auth": "%s"}}}`,
269-
registryHost, registry.GetRegistryPassword(), authString)
297+
authConfig := fmt.Sprintf(`{"auths":{"%s":{"username": "embedded-cluster", "password": "%s"}}}`,
298+
registryHost, registry.GetRegistryPassword())
270299
imagePullSecretValue := base64.StdEncoding.EncodeToString([]byte(authConfig))
271300

272301
return &types.RegistrySettings{
273-
HasLocalRegistry: true,
274-
Host: registryHost,
275-
Address: registryAddress,
276-
Namespace: appNamespace,
277-
ImagePullSecretName: "embedded-cluster-registry",
278-
ImagePullSecretValue: imagePullSecretValue,
302+
HasLocalRegistry: true,
303+
LocalRegistryHost: registryHost,
304+
LocalRegistryAddress: registryAddress,
305+
LocalRegistryNamespace: appNamespace,
306+
ImagePullSecretName: fmt.Sprintf("%s-registry", appSlug),
307+
ImagePullSecretValue: imagePullSecretValue,
279308
}, nil
280309
}

0 commit comments

Comments
 (0)