Skip to content

Commit 3aec255

Browse files
authored
integration tests without custom domains (#1992)
* check helm chart image prefixes in dryrun * add a dryrun test that ensures the default image proxy is used properly * comment
1 parent 8c045dc commit 3aec255

File tree

7 files changed

+168
-8
lines changed

7 files changed

+168
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/replicatedhq/embedded-cluster
22

3-
go 1.23.4
3+
go 1.24.0
44

55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.7

tests/dryrun/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23.4-alpine AS build
1+
FROM golang:1.24.0-alpine AS build
22

33
RUN apk add --no-cache ca-certificates curl git make bash
44

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: embeddedcluster.replicated.com/v1beta1
2+
kind: Config
3+
metadata:
4+
name: "testconfig"
5+
spec:
6+
version: "testversion"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: embeddedcluster.replicated.com/v1beta1
2+
kind: Config
3+
metadata:
4+
name: "testconfig"
5+
spec:
6+
version: "testversion"
7+
domains:
8+
replicatedAppDomain: "fake-endpoint.com"
9+
proxyRegistryDomain: "fake-replicated-proxy.test.net"

tests/dryrun/assets/install-release.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ channelID: "fake-channel-id"
33
channelSlug: "fake-channel-slug"
44
appSlug: "fake-app-slug"
55
versionLabel: "fake-version-label"
6+
defaultDomains:
7+
replicatedAppDomain: "staging.replicated.app"
8+
proxyRegistryDomain: "proxy.staging.replicated.com"
9+
replicatedRegistryDomain: "registry.staging.replicated.com"

tests/dryrun/install_test.go

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,27 @@ func testDefaultInstallationImpl(t *testing.T) {
4444
openebsOpts := hcli.Calls[0].Arguments[1].(helm.InstallOptions)
4545
assert.Equal(t, "openebs", openebsOpts.ReleaseName)
4646
assertHelmValues(t, openebsOpts.Values, map[string]interface{}{
47-
"['localpv-provisioner'].localpv.basePath": "/var/lib/embedded-cluster/openebs-local",
47+
"['localpv-provisioner'].localpv.basePath": "/var/lib/embedded-cluster/openebs-local",
48+
"['localpv-provisioner'].helperPod.image.registry": "fake-replicated-proxy.test.net/anonymous/",
49+
"['localpv-provisioner'].localpv.image.registry": "fake-replicated-proxy.test.net/anonymous/",
50+
"['preUpgradeHook'].image.registry": "fake-replicated-proxy.test.net/anonymous",
4851
})
4952

5053
// embedded cluster operator
5154
assert.Equal(t, "Install", hcli.Calls[1].Method)
5255
operatorOpts := hcli.Calls[1].Arguments[1].(helm.InstallOptions)
5356
assert.Equal(t, "embedded-cluster-operator", operatorOpts.ReleaseName)
57+
assertHelmValues(t, operatorOpts.Values, map[string]interface{}{
58+
"image.repository": "fake-replicated-proxy.test.net/anonymous/replicated/embedded-cluster-operator-image",
59+
})
5460

5561
// velero
5662
assert.Equal(t, "Install", hcli.Calls[2].Method)
5763
veleroOpts := hcli.Calls[2].Arguments[1].(helm.InstallOptions)
5864
assert.Equal(t, "velero", veleroOpts.ReleaseName)
5965
assertHelmValues(t, veleroOpts.Values, map[string]interface{}{
6066
"nodeAgent.podVolumePath": "/var/lib/embedded-cluster/k0s/kubelet/pods",
67+
"image.repository": "fake-replicated-proxy.test.net/anonymous/replicated/ec-velero",
6168
})
6269

6370
// admin console
@@ -67,6 +74,12 @@ func testDefaultInstallationImpl(t *testing.T) {
6774
assertHelmValues(t, adminConsoleOpts.Values, map[string]interface{}{
6875
"kurlProxy.nodePort": float64(30000),
6976
})
77+
assertHelmValuePrefixes(t, adminConsoleOpts.Values, map[string]string{
78+
"images.kotsadm": "fake-replicated-proxy.test.net/anonymous",
79+
"images.kurlProxy": "fake-replicated-proxy.test.net/anonymous",
80+
"images.migrations": "fake-replicated-proxy.test.net/anonymous",
81+
"images.rqlite": "fake-replicated-proxy.test.net/anonymous",
82+
})
7083

7184
// --- validate os env --- //
7285
assertEnv(t, dr.OSEnv, map[string]string{
@@ -159,6 +172,14 @@ func testDefaultInstallationImpl(t *testing.T) {
159172
assert.Equal(t, "10.244.0.0/17", k0sConfig.Spec.Network.PodCIDR)
160173
assert.Equal(t, "10.244.128.0/17", k0sConfig.Spec.Network.ServiceCIDR)
161174
assert.Contains(t, k0sConfig.Spec.API.SANs, "kubernetes.default.svc.cluster.local")
175+
176+
assert.Contains(t, k0sConfig.Spec.Images.MetricsServer.Image, "fake-replicated-proxy.test.net/anonymous")
177+
assert.Contains(t, k0sConfig.Spec.Images.KubeProxy.Image, "fake-replicated-proxy.test.net/anonymous")
178+
assert.Contains(t, k0sConfig.Spec.Images.CoreDNS.Image, "fake-replicated-proxy.test.net/anonymous")
179+
assert.Contains(t, k0sConfig.Spec.Images.Pause.Image, "fake-replicated-proxy.test.net/anonymous")
180+
assert.Contains(t, k0sConfig.Spec.Images.Calico.CNI.Image, "fake-replicated-proxy.test.net/anonymous")
181+
assert.Contains(t, k0sConfig.Spec.Images.Calico.Node.Image, "fake-replicated-proxy.test.net/anonymous")
182+
assert.Contains(t, k0sConfig.Spec.Images.Calico.KubeControllers.Image, "fake-replicated-proxy.test.net/anonymous")
162183
}
163184

164185
func TestCustomDataDir(t *testing.T) {
@@ -463,3 +484,90 @@ func TestCustomCidrInstallation(t *testing.T) {
463484

464485
t.Logf("%s: test complete", time.Now().Format(time.RFC3339))
465486
}
487+
488+
// this test is to ensure that when no domains are provided in the cluster config that the domains from the embedded release file are used
489+
func TestNoDomains(t *testing.T) {
490+
hcli := &helm.MockClient{}
491+
492+
mock.InOrder(
493+
// 4 addons
494+
hcli.On("Install", mock.Anything, mock.Anything).Times(4).Return(nil, nil),
495+
hcli.On("Close").Once().Return(nil),
496+
)
497+
498+
dr := dryrunInstallWithClusterConfig(t,
499+
&dryrun.Client{HelmClient: hcli},
500+
clusterConfigNoDomainsData,
501+
)
502+
503+
// --- validate addons --- //
504+
505+
// openebs
506+
assert.Equal(t, "Install", hcli.Calls[0].Method)
507+
openebsOpts := hcli.Calls[0].Arguments[1].(helm.InstallOptions)
508+
assert.Equal(t, "openebs", openebsOpts.ReleaseName)
509+
assertHelmValues(t, openebsOpts.Values, map[string]interface{}{
510+
"['localpv-provisioner'].localpv.basePath": "/var/lib/embedded-cluster/openebs-local",
511+
"['localpv-provisioner'].helperPod.image.registry": "proxy.staging.replicated.com/anonymous/",
512+
"['localpv-provisioner'].localpv.image.registry": "proxy.staging.replicated.com/anonymous/",
513+
"['preUpgradeHook'].image.registry": "proxy.staging.replicated.com/anonymous",
514+
})
515+
516+
// embedded cluster operator
517+
assert.Equal(t, "Install", hcli.Calls[1].Method)
518+
operatorOpts := hcli.Calls[1].Arguments[1].(helm.InstallOptions)
519+
assert.Equal(t, "embedded-cluster-operator", operatorOpts.ReleaseName)
520+
assertHelmValues(t, operatorOpts.Values, map[string]interface{}{
521+
"image.repository": "proxy.staging.replicated.com/anonymous/replicated/embedded-cluster-operator-image",
522+
})
523+
524+
// velero
525+
assert.Equal(t, "Install", hcli.Calls[2].Method)
526+
veleroOpts := hcli.Calls[2].Arguments[1].(helm.InstallOptions)
527+
assert.Equal(t, "velero", veleroOpts.ReleaseName)
528+
assertHelmValues(t, veleroOpts.Values, map[string]interface{}{
529+
"nodeAgent.podVolumePath": "/var/lib/embedded-cluster/k0s/kubelet/pods",
530+
"image.repository": "proxy.staging.replicated.com/anonymous/replicated/ec-velero",
531+
})
532+
533+
// admin console
534+
assert.Equal(t, "Install", hcli.Calls[3].Method)
535+
adminConsoleOpts := hcli.Calls[3].Arguments[1].(helm.InstallOptions)
536+
assert.Equal(t, "admin-console", adminConsoleOpts.ReleaseName)
537+
assertHelmValues(t, adminConsoleOpts.Values, map[string]interface{}{
538+
"kurlProxy.nodePort": float64(30000),
539+
})
540+
assertHelmValuePrefixes(t, adminConsoleOpts.Values, map[string]string{
541+
"images.kotsadm": "proxy.staging.replicated.com/anonymous",
542+
"images.kurlProxy": "proxy.staging.replicated.com/anonymous",
543+
"images.migrations": "proxy.staging.replicated.com/anonymous",
544+
"images.rqlite": "proxy.staging.replicated.com/anonymous",
545+
})
546+
547+
// --- validate installation object --- //
548+
kcli, err := dr.KubeClient()
549+
if err != nil {
550+
t.Fatalf("failed to create kube client: %v", err)
551+
}
552+
in, err := kubeutils.GetLatestInstallation(context.TODO(), kcli)
553+
if err != nil {
554+
t.Fatalf("failed to get latest installation: %v", err)
555+
}
556+
// expected to be empty
557+
assert.Equal(t, "", in.Spec.Config.Domains.ProxyRegistryDomain)
558+
assert.Equal(t, "", in.Spec.Config.Domains.ReplicatedAppDomain)
559+
assert.Equal(t, "", in.Spec.Config.Domains.ReplicatedRegistryDomain)
560+
561+
// --- validate k0s cluster config --- //
562+
k0sConfig := readK0sConfig(t)
563+
564+
assert.Contains(t, k0sConfig.Spec.Images.MetricsServer.Image, "proxy.staging.replicated.com/anonymous")
565+
assert.Contains(t, k0sConfig.Spec.Images.KubeProxy.Image, "proxy.staging.replicated.com/anonymous")
566+
assert.Contains(t, k0sConfig.Spec.Images.CoreDNS.Image, "proxy.staging.replicated.com/anonymous")
567+
assert.Contains(t, k0sConfig.Spec.Images.Pause.Image, "proxy.staging.replicated.com/anonymous")
568+
assert.Contains(t, k0sConfig.Spec.Images.Calico.CNI.Image, "proxy.staging.replicated.com/anonymous")
569+
assert.Contains(t, k0sConfig.Spec.Images.Calico.Node.Image, "proxy.staging.replicated.com/anonymous")
570+
assert.Contains(t, k0sConfig.Spec.Images.Calico.KubeControllers.Image, "proxy.staging.replicated.com/anonymous")
571+
572+
t.Logf("%s: test complete", time.Now().Format(time.RFC3339))
573+
}

tests/dryrun/util.go

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ var (
3131
//go:embed assets/install-release.yaml
3232
releaseData string
3333

34+
//go:embed assets/cluster-config.yaml
35+
clusterConfigData string
36+
37+
//go:embed assets/cluster-config-nodomains.yaml
38+
clusterConfigNoDomainsData string
39+
3440
//go:embed assets/install-license.yaml
3541
licenseData string
3642
)
3743

3844
func dryrunJoin(t *testing.T, args ...string) dryruntypes.DryRun {
39-
if err := embedReleaseData(); err != nil {
45+
if err := embedReleaseData(clusterConfigData); err != nil {
4046
t.Fatalf("fail to embed release data: %v", err)
4147
}
4248

@@ -57,7 +63,11 @@ func dryrunJoin(t *testing.T, args ...string) dryruntypes.DryRun {
5763
}
5864

5965
func dryrunInstall(t *testing.T, c *dryrun.Client, args ...string) dryruntypes.DryRun {
60-
if err := embedReleaseData(); err != nil {
66+
return dryrunInstallWithClusterConfig(t, c, clusterConfigData, args...)
67+
}
68+
69+
func dryrunInstallWithClusterConfig(t *testing.T, c *dryrun.Client, clusterConfig string, args ...string) dryruntypes.DryRun {
70+
if err := embedReleaseData(clusterConfig); err != nil {
6171
t.Fatalf("fail to embed release data: %v", err)
6272
}
6373

@@ -85,7 +95,7 @@ func dryrunInstall(t *testing.T, c *dryrun.Client, args ...string) dryruntypes.D
8595
}
8696

8797
func dryrunUpdate(t *testing.T, args ...string) dryruntypes.DryRun {
88-
if err := embedReleaseData(); err != nil {
98+
if err := embedReleaseData(clusterConfigData); err != nil {
8999
t.Fatalf("fail to embed release data: %v", err)
90100
}
91101

@@ -104,9 +114,10 @@ func dryrunUpdate(t *testing.T, args ...string) dryruntypes.DryRun {
104114
return *dr
105115
}
106116

107-
func embedReleaseData() error {
117+
func embedReleaseData(clusterConfig string) error {
108118
if err := release.SetReleaseDataForTests(map[string][]byte{
109-
"release.yaml": []byte(releaseData),
119+
"release.yaml": []byte(releaseData),
120+
"cluster-config.yaml": []byte(clusterConfig),
110121
}); err != nil {
111122
return fmt.Errorf("set release data: %v", err)
112123
}
@@ -246,3 +257,25 @@ func assertHelmValues(t *testing.T, actualValues map[string]interface{}, expecte
246257
assert.Equal(t, expectedValue, actualValue)
247258
}
248259
}
260+
261+
func assertHelmValuePrefixes(t *testing.T, actualValues map[string]interface{}, expectedPrefixes map[string]string) {
262+
for expectedKey, expectedPrefix := range expectedPrefixes {
263+
actualValue, err := helm.GetValue(actualValues, expectedKey)
264+
assert.NoError(t, err)
265+
if actualValue == nil {
266+
t.Errorf("expected prefix %s for key %s, got nil", expectedPrefix, expectedKey)
267+
return
268+
}
269+
270+
actualValueStr, ok := actualValue.(string)
271+
if !ok {
272+
t.Errorf("expected prefix %s for key %s, got %v", expectedPrefix, expectedKey, actualValue)
273+
return
274+
}
275+
276+
if !strings.HasPrefix(actualValueStr, expectedPrefix) {
277+
t.Errorf("expected prefix %s for key %s, got %s", expectedPrefix, expectedKey, actualValueStr)
278+
return
279+
}
280+
}
281+
}

0 commit comments

Comments
 (0)