Skip to content

Commit

Permalink
fix(delete): recreate cluster when deleted via argocd-ui (#118)
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Haar <[email protected]>
  • Loading branch information
haarchri authored Nov 30, 2023
1 parent 00b9ad6 commit 8fa0d60
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pkg/controller/cluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8fa0d60

Please sign in to comment.