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 13, 2024
1 parent c6eff61 commit 9840dcb
Show file tree
Hide file tree
Showing 3 changed files with 54 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: VSphereCluster
metadata:
name: ${CLUSTER_NAME}
namespace: ${NAMESPACE}
spec:
failureDomainSelector: {}
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 == 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
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 9840dcb

Please sign in to comment.