Skip to content

Commit f79b079

Browse files
committed
Issue-10544 ignore unreachable cluster while deleting machinePool
Signed-off-by: melserngawy <[email protected]>
1 parent e1a701f commit f79b079

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

controllers/remote/cluster_cache_tracker.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ const (
5959
healthCheckUnhealthyThreshold = 10
6060
initialCacheSyncTimeout = 5 * time.Minute
6161
clusterCacheControllerName = "cluster-cache-tracker"
62+
63+
// ClusterAccessorErrorMessage error message for failing to create cluster accessor.
64+
ClusterAccessorErrorMessage = "failed to create cluster accessor"
6265
)
6366

6467
// ErrClusterLocked is returned in methods that require cluster-level locking
@@ -267,7 +270,7 @@ func (t *ClusterCacheTracker) getClusterAccessor(ctx context.Context, cluster cl
267270
// for the cluster at the same time.
268271
// Return an error if another go routine already tries to create a clusterAccessor.
269272
if ok := t.clusterLock.TryLock(cluster); !ok {
270-
return nil, errors.Wrapf(ErrClusterLocked, "failed to create cluster accessor: failed to get lock for cluster")
273+
return nil, errors.Wrapf(ErrClusterLocked, ClusterAccessorErrorMessage)
271274
}
272275
defer t.clusterLock.Unlock(cluster)
273276

@@ -281,7 +284,7 @@ func (t *ClusterCacheTracker) getClusterAccessor(ctx context.Context, cluster cl
281284
log.V(4).Info("Creating new cluster accessor")
282285
accessor, err := t.newClusterAccessor(ctx, cluster, indexes...)
283286
if err != nil {
284-
return nil, errors.Wrap(err, "failed to create cluster accessor")
287+
return nil, errors.Wrap(err, ClusterAccessorErrorMessage)
285288
}
286289

287290
log.V(4).Info("Storing new cluster accessor")

exp/internal/controllers/machinepool_controller.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223
"time"
2324

2425
"github.com/pkg/errors"
@@ -260,7 +261,9 @@ func (r *MachinePoolReconciler) reconcileDelete(ctx context.Context, cluster *cl
260261
return err
261262
}
262263

263-
if err := r.reconcileDeleteNodes(ctx, cluster, mp); err != nil {
264+
err := r.reconcileDeleteNodes(ctx, cluster, mp)
265+
// Check if the return error has ClusterAccessorErrorMessage to ignore unreachable cluster.
266+
if err != nil && !strings.Contains(err.Error(), remote.ClusterAccessorErrorMessage) {
264267
// Return early and don't remove the finalizer if we got an error.
265268
return err
266269
}
@@ -274,7 +277,13 @@ func (r *MachinePoolReconciler) reconcileDeleteNodes(ctx context.Context, cluste
274277
return nil
275278
}
276279

280+
// return if cluster is deleting
281+
if !cluster.DeletionTimestamp.IsZero() {
282+
return nil
283+
}
284+
277285
clusterClient, err := r.Tracker.GetClient(ctx, util.ObjectKey(cluster))
286+
278287
if err != nil {
279288
return err
280289
}

0 commit comments

Comments
 (0)