@@ -8,12 +8,16 @@ package e2e
88import (
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
1923type 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+ }
0 commit comments