From 073f9e9c5a404131e98df0d83513d33a81dc1b77 Mon Sep 17 00:00:00 2001 From: Paul Maidment Date: Tue, 3 Sep 2024 17:40:39 +0300 Subject: [PATCH] MGMT-18702: Fix error due to missing local cluster name When the local cluster name could not be resolved, we inadvertantly try to clean it up. This issue addresses that by ensuring we do not attempt cleanup in the absence of a name derived from ManagedCluster --- .../controller/controllers/local_cluster_import_controller.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/controller/controllers/local_cluster_import_controller.go b/internal/controller/controllers/local_cluster_import_controller.go index 0db4f4ed1d8c..1d0152bd6982 100644 --- a/internal/controller/controllers/local_cluster_import_controller.go +++ b/internal/controller/controllers/local_cluster_import_controller.go @@ -330,6 +330,10 @@ func (r *LocalClusterImportReconciler) hasLocalManagedCluster(ctx context.Contex // If they are present, they will be deleted // No error will be returned if these are not found as this is the desired state. func (r *LocalClusterImportReconciler) ensureLocalClusterCRsDeleted(ctx context.Context) error { + if r.localClusterName == "" { + r.log.Infof("skipping local cluster import cleanup as feature has not previously been enabled") + return nil + } err := r.deleteClusterDeployment(ctx, r.localClusterName, r.localClusterName) if err != nil && !k8serrors.IsNotFound(err) { r.log.Errorf("could not delete local cluster ClusterDeployment due to error %s", err.Error())