diff --git a/controllers/vspheredeploymentzone_controller.go b/controllers/vspheredeploymentzone_controller.go index 14be19e5e7..93d67e910d 100644 --- a/controllers/vspheredeploymentzone_controller.go +++ b/controllers/vspheredeploymentzone_controller.go @@ -185,21 +185,18 @@ func (r vsphereDeploymentZoneReconciler) reconcileNormal(deploymentZoneCtx *capv conditions.MarkTrue(deploymentZoneCtx.VSphereDeploymentZone, infrav1.VSphereFailureDomainValidatedCondition) // Ensure the VSphereDeploymentZone is marked as an owner of the VSphereFailureDomain. - if !clusterutilv1.HasOwnerRef(deploymentZoneCtx.VSphereFailureDomain.GetOwnerReferences(), metav1.OwnerReference{ - APIVersion: infrav1.GroupVersion.String(), - Kind: "VSphereDeploymentZone", - Name: deploymentZoneCtx.VSphereDeploymentZone.Name, - }) { - if err := updateOwnerReferences(deploymentZoneCtx, deploymentZoneCtx.VSphereFailureDomain, r.Client, func() []metav1.OwnerReference { - return append(deploymentZoneCtx.VSphereFailureDomain.OwnerReferences, metav1.OwnerReference{ - APIVersion: infrav1.GroupVersion.String(), - Kind: deploymentZoneCtx.VSphereDeploymentZone.Kind, - Name: deploymentZoneCtx.VSphereDeploymentZone.Name, - UID: deploymentZoneCtx.VSphereDeploymentZone.UID, - }) + if err := updateOwnerReferences(deploymentZoneCtx, deploymentZoneCtx.VSphereFailureDomain, r.Client, + func() []metav1.OwnerReference { + return clusterutilv1.EnsureOwnerRef( + deploymentZoneCtx.VSphereFailureDomain.OwnerReferences, + metav1.OwnerReference{ + APIVersion: infrav1.GroupVersion.String(), + Kind: deploymentZoneCtx.VSphereDeploymentZone.Kind, + Name: deploymentZoneCtx.VSphereDeploymentZone.Name, + UID: deploymentZoneCtx.VSphereDeploymentZone.UID, + }) }); err != nil { - return err - } + return err } deploymentZoneCtx.VSphereDeploymentZone.Status.Ready = pointer.Bool(true) diff --git a/controllers/vspheremachine_controller.go b/controllers/vspheremachine_controller.go index 7d15151f60..9edc24518c 100644 --- a/controllers/vspheremachine_controller.go +++ b/controllers/vspheremachine_controller.go @@ -263,7 +263,7 @@ func (r *machineReconciler) Reconcile(_ context.Context, req ctrl.Request) (_ ct } func (r *machineReconciler) reconcileDelete(machineCtx capvcontext.MachineContext) (reconcile.Result, error) { - machineCtx.GetLogger().Info("Handling deleted SphereMachine") + machineCtx.GetLogger().Info("Handling deleted VSphereMachine") conditions.MarkFalse(machineCtx.GetVSphereMachine(), infrav1.VMProvisionedCondition, clusterv1.DeletingReason, clusterv1.ConditionSeverityInfo, "") if err := r.VMService.ReconcileDelete(machineCtx); err != nil { diff --git a/test/e2e/data/infrastructure-vsphere/main/failuredomains/drop-existing-secret.yaml b/test/e2e/data/infrastructure-vsphere/main/failuredomains/drop-existing-identity-secret.yaml similarity index 100% rename from test/e2e/data/infrastructure-vsphere/main/failuredomains/drop-existing-secret.yaml rename to test/e2e/data/infrastructure-vsphere/main/failuredomains/drop-existing-identity-secret.yaml diff --git a/test/e2e/data/infrastructure-vsphere/main/failuredomains/failure-domains.yaml b/test/e2e/data/infrastructure-vsphere/main/failuredomains/failure-domains.yaml new file mode 100644 index 0000000000..7a65dc0fde --- /dev/null +++ b/test/e2e/data/infrastructure-vsphere/main/failuredomains/failure-domains.yaml @@ -0,0 +1,33 @@ +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: VSphereFailureDomain +metadata: + name: "fd1" + namespace: "${NAMESPACE}" +spec: + region: + name: '${VSPHERE_DATACENTER}' + type: Datacenter + tagCategory: k8s-region + autoConfigure: true + zone: + name: "cluster0" + type: ComputeCluster + tagCategory: k8s-zone + autoConfigure: true + topology: + datacenter: '${VSPHERE_DATACENTER}' + # datastore is optional and should\can be set when only one compute cluster is set + # or we should use storage policy + computeCluster: "cluster0" +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: VSphereDeploymentZone +metadata: + name: "zone1" + namespace: "${NAMESPACE}" +spec: + server: '${VSPHERE_SERVER}' + failureDomain: "fd1" + placementConstraint: + resourcePool: '${VSPHERE_RESOURCE_POOL}' \ No newline at end of file diff --git a/test/e2e/data/infrastructure-vsphere/main/failuredomains/kustomization.yaml b/test/e2e/data/infrastructure-vsphere/main/failuredomains/kustomization.yaml index fe657a92ac..c05d7d011f 100644 --- a/test/e2e/data/infrastructure-vsphere/main/failuredomains/kustomization.yaml +++ b/test/e2e/data/infrastructure-vsphere/main/failuredomains/kustomization.yaml @@ -3,10 +3,10 @@ kind: Kustomization resources: - ../base - cluster-identity.yaml + - failure-domains.yaml patchesStrategicMerge: - ../commons/cluster-resource-set-label.yaml - ../commons/cluster-network-CIDR.yaml - ../commons/cluster-resource-set-csi-insecure.yaml - vsphereclusteridentity.yaml - - drop-existing-secret.yaml -# - ../commons/failure-domain.yaml + - drop-existing-identity-secret.yaml diff --git a/test/e2e/owner_reference_test.go b/test/e2e/ownerreference_test.go similarity index 90% rename from test/e2e/owner_reference_test.go rename to test/e2e/ownerreference_test.go index 6510041f97..9e43fd2b3f 100644 --- a/test/e2e/owner_reference_test.go +++ b/test/e2e/ownerreference_test.go @@ -128,15 +128,22 @@ var ( "VSphereClusterIdentity": func(owners []metav1.OwnerReference) error { return framework.HasExactOwners(owners) }, - "VSphereFailureDomain": func(owners []metav1.OwnerReference) error { panic("IMPLEMENT ME") }, - "vSphereDeploymentZone": func(owners []metav1.OwnerReference) error { panic("IMPLEMENT ME") }, + "VSphereDeploymentZone": func(owners []metav1.OwnerReference) error { + // The vSphereDeploymentZone does not have any owners. + return framework.HasExactOwners(owners) + }, + "VSphereFailureDomain": func(owners []metav1.OwnerReference) error { + // The vSphereFailureDomain can be owned by one or more vSphereDeploymentZones. + return framework.HasOneOfExactOwners(owners, []metav1.OwnerReference{vSphereDeploymentZoneOwner}, []metav1.OwnerReference{vSphereDeploymentZoneOwner, vSphereDeploymentZoneOwner}) + }, } ) var ( // CAPV owners. - vSphereMachineOwner = metav1.OwnerReference{Kind: "VSphereMachine", APIVersion: infrav1.GroupVersion.String()} - vSphereClusterOwner = metav1.OwnerReference{Kind: "VSphereCluster", APIVersion: infrav1.GroupVersion.String()} + vSphereMachineOwner = metav1.OwnerReference{Kind: "VSphereMachine", APIVersion: infrav1.GroupVersion.String()} + vSphereClusterOwner = metav1.OwnerReference{Kind: "VSphereCluster", APIVersion: infrav1.GroupVersion.String()} + vSphereDeploymentZoneOwner = metav1.OwnerReference{Kind: "VSphereDeploymentZone", APIVersion: infrav1.GroupVersion.String()} // CAPI owners. clusterClassOwner = metav1.OwnerReference{Kind: "ClusterClass", APIVersion: clusterv1.GroupVersion.String()}