From 62f0c07ab8ab38dcff9fb4c6a492cf2efbea5116 Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Thu, 30 Nov 2023 19:29:06 +0100 Subject: [PATCH] fix(delete): recreate cluster when deleted via argocd-ui Signed-off-by: Christopher Haar --- pkg/controller/cluster/controller.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pkg/controller/cluster/controller.go b/pkg/controller/cluster/controller.go index ee4db0c..91f92fe 100644 --- a/pkg/controller/cluster/controller.go +++ b/pkg/controller/cluster/controller.go @@ -113,11 +113,26 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex observedCluster, err := e.client.Get(ctx, &clusterQuery) if err != nil { switch { - case cluster.IsErrorClusterNotFound(err), - cluster.IsErrorPermissionDenied(err) && meta.WasDeleted(cr): + case cluster.IsErrorClusterNotFound(err): + // Case: Cluster not found return managed.ExternalObservation{}, nil + + case cluster.IsErrorPermissionDenied(err): + if meta.WasDeleted(cr) { + // Case: Cluster is deleted, + // and the managed resource has a deletion timestamp + return managed.ExternalObservation{}, nil + } + // Case: Cluster is deleted via argocd-ui, + // but the managed resource still exists + return managed.ExternalObservation{ + ResourceExists: false, + }, nil + + default: + // Default case: Handle other errors + return managed.ExternalObservation{}, errors.Wrap(err, errGetFailed) } - return managed.ExternalObservation{}, errors.Wrap(err, errGetFailed) } if meta.WasDeleted(cr) && meta.GetExternalName(cr) != observedCluster.Name { // ArgoCD Cluster resource ignores the name field. This detects the deletion of the default cluster resource.