Skip to content

Commit

Permalink
test: check failureDomains on VSphereCluster in e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Aug 9, 2024
1 parent a4089cf commit 322b009
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ patchesStrategicMerge:
- ../commons/cluster-network-CIDR.yaml
- vsphereclusteridentity.yaml
- drop-existing-identity-secret.yaml
- vspherecluster-failuredomainselector.yaml
46 changes: 46 additions & 0 deletions test/e2e/ownerrefs_finalizers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 == SupervisorTestMode {
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
Expand Down Expand Up @@ -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{}

Expand Down

0 comments on commit 322b009

Please sign in to comment.