Skip to content

Commit

Permalink
Add ownerReference tests for FailureDomain types
Browse files Browse the repository at this point in the history
Signed-off-by: killianmuldoon <[email protected]>
  • Loading branch information
killianmuldoon committed Sep 6, 2023
1 parent bfcf1f9 commit d1e1705
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 21 deletions.
25 changes: 11 additions & 14 deletions controllers/vspheredeploymentzone_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion controllers/vspheremachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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}'
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down

0 comments on commit d1e1705

Please sign in to comment.