Skip to content

Commit

Permalink
check that vspheremachines are deleted before deleting the vsphereclu…
Browse files Browse the repository at this point in the history
…ster

Signed-off-by: Yassine TIJANI <[email protected]>

Co-Authored-By: Andy Goldstein <[email protected]>
  • Loading branch information
yastij and ncdc committed Feb 21, 2020
1 parent f9a3592 commit 621fb1f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controllers/vspherecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ func (r clusterReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr er
func (r clusterReconciler) reconcileDelete(ctx *context.ClusterContext) (reconcile.Result, error) {
ctx.Logger.Info("Reconciling VSphereCluster delete")

vsphereMachines, err := infrautilv1.GetVSphereMachinesInCluster(ctx, ctx.Client, ctx.VSphereCluster.Namespace, ctx.VSphereCluster.Name)
if err != nil {
return reconcile.Result{}, errors.Wrapf(err,
"unable to list VSphereMachines part of VSphereCluster %s/%s", ctx.VSphereCluster.Namespace, ctx.VSphereCluster.Name)
}

if len(vsphereMachines) > 0 {
return reconcile.Result{}, errors.Errorf("unable to delete VSphereCluster %s/%s: %v VSphereMachines left", ctx.VSphereCluster.Namespace, ctx.VSphereCluster.Name, len(vsphereMachines))
}

// Cluster is deleted so remove the finalizer.
ctx.VSphereCluster.Finalizers = clusterutilv1.Filter(ctx.VSphereCluster.Finalizers, infrav1.ClusterFinalizer)

Expand Down

0 comments on commit 621fb1f

Please sign in to comment.