Skip to content

Commit 015dcbb

Browse files
committed
e2e: ensure registry addon CA exists and matches the root CA
1 parent 6b9d66c commit 015dcbb

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

test/e2e/quick_start_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ var _ = Describe("Quick start", func() {
295295
),
296296
},
297297
)
298-
299298
WaitForCoreDNSToBeReadyInWorkloadCluster(
300299
ctx,
301300
WaitForCoreDNSToBeReadyInWorkloadClusterInput{
@@ -307,6 +306,15 @@ var _ = Describe("Quick start", func() {
307306
),
308307
},
309308
)
309+
310+
EnsureClusterCAForRegistryAddon(
311+
ctx,
312+
EnsureClusterCAForRegistryAddonInput{
313+
Registry: addonsConfig.Registry,
314+
WorkloadCluster: workloadCluster,
315+
ClusterProxy: proxy,
316+
},
317+
)
310318
},
311319
}
312320
})

test/e2e/registry.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ package e2e
88
import (
99
"context"
1010

11+
. "github.com/onsi/gomega"
1112
appsv1 "k8s.io/api/apps/v1"
13+
corev1 "k8s.io/api/core/v1"
1214
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1315
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1416
"sigs.k8s.io/cluster-api/test/framework"
17+
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
1518

1619
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
20+
handlersutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/utils"
1721
)
1822

1923
type WaitForRegistryAddonToBeReadyInWorkloadClusterInput struct {
@@ -56,3 +60,44 @@ func WaitForRegistryAddonToBeReadyInWorkloadCluster(
5660
},
5761
}, input.StatefulSetIntervals...)
5862
}
63+
64+
type EnsureClusterCAForRegistryAddonInput struct {
65+
Registry *v1alpha1.RegistryAddon
66+
WorkloadCluster *clusterv1.Cluster
67+
ClusterProxy framework.ClusterProxy
68+
}
69+
70+
// EnsureClusterCAForRegistryAddon verifies that the cluster CA data exists and matches the root CA.
71+
func EnsureClusterCAForRegistryAddon(
72+
ctx context.Context,
73+
input EnsureClusterCAForRegistryAddonInput, //nolint:gocritic // This hugeParam is OK in tests.
74+
) {
75+
if input.Registry == nil {
76+
return
77+
}
78+
79+
cl := input.ClusterProxy.GetClient()
80+
81+
rootCASecret := &corev1.Secret{
82+
ObjectMeta: metav1.ObjectMeta{
83+
Name: handlersutils.RegistryAddonRootCASecretName,
84+
Namespace: corev1.NamespaceDefault,
85+
},
86+
}
87+
err := cl.Get(ctx, ctrlclient.ObjectKeyFromObject(rootCASecret), rootCASecret)
88+
Expect(err).NotTo(HaveOccurred())
89+
Expect(rootCASecret.Data).ToNot(BeEmpty())
90+
91+
clusterCASecret := &corev1.Secret{
92+
ObjectMeta: metav1.ObjectMeta{
93+
Name: handlersutils.SecretNameForRegistryAddonCA(input.WorkloadCluster),
94+
Namespace: input.WorkloadCluster.Namespace,
95+
},
96+
}
97+
err = cl.Get(ctx, ctrlclient.ObjectKeyFromObject(clusterCASecret), clusterCASecret)
98+
Expect(err).NotTo(HaveOccurred())
99+
Expect(clusterCASecret.Data).ToNot(BeEmpty())
100+
101+
const caCrtKey = "ca.crt"
102+
Expect(rootCASecret.Data[caCrtKey]).To(Equal(rootCASecret.Data[caCrtKey]))
103+
}

test/e2e/self_hosted_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ var _ = Describe("Self-hosted", Serial, func() {
168168
),
169169
},
170170
)
171+
172+
EnsureClusterCAForRegistryAddon(
173+
ctx,
174+
EnsureClusterCAForRegistryAddonInput{
175+
Registry: addonsConfig.Registry,
176+
WorkloadCluster: workloadCluster,
177+
ClusterProxy: proxy,
178+
},
179+
)
171180
},
172181
}
173182
},

0 commit comments

Comments
 (0)