From 9840dcbdfa41968b37926f4ee0e8bc8f4cda6437 Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Fri, 9 Aug 2024 13:10:15 +0200 Subject: [PATCH] test: check failureDomains on VSphereCluster in e2e test --- .../ownerrefs-finalizers/kustomization.yaml | 1 + .../vspherecluster-failuredomainselector.yaml | 7 +++ test/e2e/ownerrefs_finalizers_test.go | 46 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 test/e2e/data/infrastructure-vsphere-govmomi/main/ownerrefs-finalizers/vspherecluster-failuredomainselector.yaml diff --git a/test/e2e/data/infrastructure-vsphere-govmomi/main/ownerrefs-finalizers/kustomization.yaml b/test/e2e/data/infrastructure-vsphere-govmomi/main/ownerrefs-finalizers/kustomization.yaml index 93257b21a5..3da6575628 100644 --- a/test/e2e/data/infrastructure-vsphere-govmomi/main/ownerrefs-finalizers/kustomization.yaml +++ b/test/e2e/data/infrastructure-vsphere-govmomi/main/ownerrefs-finalizers/kustomization.yaml @@ -9,3 +9,4 @@ patchesStrategicMerge: - ../commons/cluster-network-CIDR.yaml - vsphereclusteridentity.yaml - drop-existing-identity-secret.yaml + - vspherecluster-failuredomainselector.yaml diff --git a/test/e2e/data/infrastructure-vsphere-govmomi/main/ownerrefs-finalizers/vspherecluster-failuredomainselector.yaml b/test/e2e/data/infrastructure-vsphere-govmomi/main/ownerrefs-finalizers/vspherecluster-failuredomainselector.yaml new file mode 100644 index 0000000000..e5e2072dc9 --- /dev/null +++ b/test/e2e/data/infrastructure-vsphere-govmomi/main/ownerrefs-finalizers/vspherecluster-failuredomainselector.yaml @@ -0,0 +1,7 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: VSphereCluster +metadata: + name: ${CLUSTER_NAME} + namespace: ${NAMESPACE} +spec: + failureDomainSelector: {} \ No newline at end of file diff --git a/test/e2e/ownerrefs_finalizers_test.go b/test/e2e/ownerrefs_finalizers_test.go index 2e10cd7fc5..8e6e1c5987 100644 --- a/test/e2e/ownerrefs_finalizers_test.go +++ b/test/e2e/ownerrefs_finalizers_test.go @@ -26,6 +26,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/pkg/errors" + topologyv1 "github.com/vmware-tanzu/vm-operator/external/tanzu-topology/api/v1alpha1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -85,6 +86,13 @@ var _ = Describe("Ensure OwnerReferences and Finalizers are resilient [vcsim] [s } }, PostMachinesProvisioned: func(proxy framework.ClusterProxy, namespace, clusterName string) { + By("Checking that failure domains got added to the Cluster") + if testMode == GovmomiTestMode { + checkGovmomiVSphereClusterFailureDomains(ctx, proxy, namespace, clusterName) + } else { + checkSupervisorVSphereClusterFailureDomains(ctx, proxy, namespace, clusterName) + } + forceCtx, forceCancelFunc := context.WithCancel(ctx) if testMode == GovmomiTestMode { // check the cluster identity secret has expected ownerReferences and finalizers, and they are resilient @@ -358,6 +366,44 @@ func createVsphereIdentitySecret(ctx context.Context, bootstrapClusterProxy fram })).To(Succeed()) } +func checkGovmomiVSphereClusterFailureDomains(ctx context.Context, proxy framework.ClusterProxy, namespace, clusterName string) { + vSphereCluster := &infrav1.VSphereCluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: namespace, + Name: clusterName, + }, + } + Expect(proxy.GetClient().Get(ctx, ctrlclient.ObjectKeyFromObject(vSphereCluster), vSphereCluster)).To(Succeed()) + + Expect(vSphereCluster.Status.FailureDomains).To(BeEquivalentTo(clusterv1.FailureDomains{ + "ownerrefs-finalizers": clusterv1.FailureDomainSpec{ + ControlPlane: true, + }, + })) +} + +func checkSupervisorVSphereClusterFailureDomains(ctx context.Context, proxy framework.ClusterProxy, namespace, clusterName string) { + avalabilityZones := &topologyv1.AvailabilityZoneList{} + Expect(proxy.GetClient().List(ctx, avalabilityZones)).To(Succeed()) + + wantFailureDomains := clusterv1.FailureDomains{} + for _, zone := range avalabilityZones.Items { + wantFailureDomains[zone.Name] = clusterv1.FailureDomainSpec{ + ControlPlane: true, + } + } + + vSphereCluster := &vmwarev1.VSphereCluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: namespace, + Name: clusterName, + }, + } + Expect(proxy.GetClient().Get(ctx, ctrlclient.ObjectKeyFromObject(vSphereCluster), vSphereCluster)).To(Succeed()) + + Expect(vSphereCluster.Status.FailureDomains).To(BeEquivalentTo(wantFailureDomains)) +} + func checkClusterIdentitySecretOwnerRefAndFinalizer(ctx context.Context, c ctrlclient.Client) { s := &corev1.Secret{}