From 8726281df41dce5afd7b0722cd7821baf430a18f Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Wed, 13 Dec 2023 13:53:04 +0100 Subject: [PATCH] handle cluster cascading deletion --- controller/pkg/cluster_controller/reconciler.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/controller/pkg/cluster_controller/reconciler.go b/controller/pkg/cluster_controller/reconciler.go index 0ae66dbb09..89c5ea27c7 100644 --- a/controller/pkg/cluster_controller/reconciler.go +++ b/controller/pkg/cluster_controller/reconciler.go @@ -206,6 +206,17 @@ func (r *Reconciler) getProviderIdAndSetControllerRef(ctx context.Context, clust return nil, &ctrl.Result{}, fmt.Errorf("could not get provider, got error: %+v", err) } + // Once provider is marked with deletion timestamp we should delete cluster as well. + // Provider cannot be deleted until cluster exists so that ensures cascading deletion. + if provider.DeletionTimestamp != nil { + err := r.Delete(ctx, cluster) + if err != nil { + return nil, &ctrl.Result{}, err + } + + return nil, &requeue, nil + } + if !provider.Status.HasID() { logger.Info("Provider does not have ID set yet") return nil, &requeue, nil