Skip to content

Commit 7b24950

Browse files
no longer ad terminting NoExecute taint for the Deleting Cluster
Signed-off-by: changzhen <[email protected]>
1 parent 9d68815 commit 7b24950

File tree

6 files changed

+25
-106
lines changed

6 files changed

+25
-106
lines changed

cmd/controller-manager/app/controllermanager.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ func startClusterController(ctx controllerscontext.Context) (enabled bool, err e
254254
ClusterMonitorGracePeriod: opts.ClusterMonitorGracePeriod.Duration,
255255
ClusterStartupGracePeriod: opts.ClusterStartupGracePeriod.Duration,
256256
FailoverEvictionTimeout: opts.FailoverEvictionTimeout.Duration,
257-
EnableTaintManager: ctx.Opts.EnableTaintManager,
258257
ClusterTaintEvictionRetryFrequency: 10 * time.Second,
259258
ExecutionSpaceRetryFrequency: 10 * time.Second,
260259
RateLimiterOptions: ctx.Opts.RateLimiterOptions,

pkg/apis/cluster/v1alpha1/well_known_constants.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const (
2727
// (corresponding to ClusterConditionReady status ConditionUnknown)
2828
// and removed when cluster becomes reachable (ClusterConditionReady status ConditionTrue).
2929
TaintClusterUnreachable = "cluster.karmada.io/unreachable"
30-
// TaintClusterTerminating will be added when cluster is terminating.
31-
TaintClusterTerminating = "cluster.karmada.io/terminating"
3230

3331
// CacheSourceAnnotationKey is the annotation that added to a resource to
3432
// represent which cluster it cached from.

pkg/controllers/cluster/cluster_controller.go

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
apierrors "k8s.io/apimachinery/pkg/api/errors"
3030
"k8s.io/apimachinery/pkg/api/meta"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32-
"k8s.io/apimachinery/pkg/fields"
3332
"k8s.io/apimachinery/pkg/types"
3433
utilerrors "k8s.io/apimachinery/pkg/util/errors"
3534
"k8s.io/apimachinery/pkg/util/wait"
@@ -42,13 +41,11 @@ import (
4241

4342
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
4443
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
45-
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
4644
"github.com/karmada-io/karmada/pkg/events"
4745
"github.com/karmada-io/karmada/pkg/features"
4846
"github.com/karmada-io/karmada/pkg/sharedcli/ratelimiterflag"
4947
"github.com/karmada-io/karmada/pkg/util"
5048
utilhelper "github.com/karmada-io/karmada/pkg/util/helper"
51-
"github.com/karmada-io/karmada/pkg/util/indexregistry"
5249
"github.com/karmada-io/karmada/pkg/util/names"
5350
)
5451

@@ -90,20 +87,12 @@ var (
9087
Key: clusterv1alpha1.TaintClusterNotReady,
9188
Effect: corev1.TaintEffectNoSchedule,
9289
}
93-
94-
// TerminatingTaintTemplate is the taint for when a cluster is terminating executing resources.
95-
// Used for taint based eviction.
96-
TerminatingTaintTemplate = &corev1.Taint{
97-
Key: clusterv1alpha1.TaintClusterTerminating,
98-
Effect: corev1.TaintEffectNoExecute,
99-
}
10090
)
10191

10292
// Controller is to sync Cluster.
10393
type Controller struct {
104-
client.Client // used to operate Cluster resources.
105-
EventRecorder record.EventRecorder
106-
EnableTaintManager bool
94+
client.Client // used to operate Cluster resources.
95+
EventRecorder record.EventRecorder
10796

10897
// ClusterMonitorPeriod represents cluster-controller monitoring period, i.e. how often does
10998
// cluster-controller check cluster health signal posted from cluster-status-controller.
@@ -243,12 +232,6 @@ func (c *Controller) syncCluster(ctx context.Context, cluster *clusterv1alpha1.C
243232
}
244233

245234
func (c *Controller) removeCluster(ctx context.Context, cluster *clusterv1alpha1.Cluster) (controllerruntime.Result, error) {
246-
// add terminating taint before cluster is deleted
247-
if err := c.updateClusterTaints(ctx, []*corev1.Taint{TerminatingTaintTemplate}, nil, cluster); err != nil {
248-
klog.ErrorS(err, "Failed to update terminating taint", "cluster", cluster.Name)
249-
return controllerruntime.Result{}, err
250-
}
251-
252235
if err := c.removeExecutionSpace(ctx, cluster); err != nil {
253236
klog.Errorf("Failed to remove execution space %s: %v", cluster.Name, err)
254237
c.EventRecorder.Event(cluster, corev1.EventTypeWarning, events.EventReasonRemoveExecutionSpaceFailed, err.Error())
@@ -268,46 +251,9 @@ func (c *Controller) removeCluster(ctx context.Context, cluster *clusterv1alpha1
268251
// delete the health data from the map explicitly after we removing the cluster.
269252
c.clusterHealthMap.delete(cluster.Name)
270253

271-
// check if target cluster is removed from all bindings.
272-
if c.EnableTaintManager {
273-
if done, err := c.isTargetClusterRemoved(ctx, cluster); err != nil {
274-
klog.ErrorS(err, "Failed to check whether target cluster is removed from bindings", "cluster", cluster.Name)
275-
return controllerruntime.Result{}, err
276-
} else if !done {
277-
klog.InfoS("Terminating taint eviction process has not finished yet, will try again later", "cluster", cluster.Name)
278-
return controllerruntime.Result{RequeueAfter: c.ClusterTaintEvictionRetryFrequency}, nil
279-
}
280-
}
281-
282254
return c.removeFinalizer(ctx, cluster)
283255
}
284256

285-
func (c *Controller) isTargetClusterRemoved(ctx context.Context, cluster *clusterv1alpha1.Cluster) (bool, error) {
286-
// List all ResourceBindings which are assigned to this cluster.
287-
rbList := &workv1alpha2.ResourceBindingList{}
288-
if err := c.List(ctx, rbList, client.MatchingFieldsSelector{
289-
Selector: fields.OneTermEqualSelector(indexregistry.ResourceBindingIndexByFieldCluster, cluster.Name),
290-
}); err != nil {
291-
klog.ErrorS(err, "Failed to list ResourceBindings", "cluster", cluster.Name)
292-
return false, err
293-
}
294-
if len(rbList.Items) != 0 {
295-
return false, nil
296-
}
297-
// List all ClusterResourceBindings which are assigned to this cluster.
298-
crbList := &workv1alpha2.ClusterResourceBindingList{}
299-
if err := c.List(ctx, crbList, client.MatchingFieldsSelector{
300-
Selector: fields.OneTermEqualSelector(indexregistry.ClusterResourceBindingIndexByFieldCluster, cluster.Name),
301-
}); err != nil {
302-
klog.ErrorS(err, "Failed to list ClusterResourceBindings", "cluster", cluster.Name)
303-
return false, err
304-
}
305-
if len(crbList.Items) != 0 {
306-
return false, nil
307-
}
308-
return true, nil
309-
}
310-
311257
// removeExecutionSpace deletes the given execution space
312258
func (c *Controller) removeExecutionSpace(ctx context.Context, cluster *clusterv1alpha1.Cluster) error {
313259
executionSpaceName := names.GenerateExecutionSpaceName(cluster.Name)

pkg/controllers/cluster/cluster_controller_test.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/karmada-io/karmada/pkg/util"
3939
"github.com/karmada-io/karmada/pkg/util/gclient"
4040
"github.com/karmada-io/karmada/pkg/util/indexregistry"
41-
"github.com/karmada-io/karmada/pkg/util/names"
4241
)
4342

4443
func newClusterController() *Controller {
@@ -65,7 +64,6 @@ func newClusterController() *Controller {
6564
Client: client,
6665
EventRecorder: record.NewFakeRecorder(1024),
6766
clusterHealthMap: newClusterHealthMap(),
68-
EnableTaintManager: true,
6967
ClusterMonitorGracePeriod: 40 * time.Second,
7068
}
7169
}
@@ -249,41 +247,6 @@ func TestController_Reconcile(t *testing.T) {
249247
want: controllerruntime.Result{},
250248
wantErr: false,
251249
},
252-
{
253-
name: "remove cluster failed",
254-
cluster: &clusterv1alpha1.Cluster{
255-
ObjectMeta: controllerruntime.ObjectMeta{
256-
Name: "test-cluster",
257-
Finalizers: []string{util.ClusterControllerFinalizer},
258-
},
259-
Spec: clusterv1alpha1.ClusterSpec{
260-
SyncMode: clusterv1alpha1.Pull,
261-
},
262-
Status: clusterv1alpha1.ClusterStatus{
263-
Conditions: []metav1.Condition{
264-
{
265-
Type: clusterv1alpha1.ClusterConditionReady,
266-
Status: metav1.ConditionFalse,
267-
},
268-
},
269-
},
270-
},
271-
ns: &corev1.Namespace{
272-
ObjectMeta: metav1.ObjectMeta{
273-
Name: names.GenerateExecutionSpaceName("test-cluster"),
274-
},
275-
},
276-
work: &workv1alpha1.Work{
277-
ObjectMeta: metav1.ObjectMeta{
278-
Name: "test-work",
279-
Namespace: names.GenerateExecutionSpaceName("test-cluster"),
280-
Finalizers: []string{util.ExecutionControllerFinalizer},
281-
},
282-
},
283-
del: true,
284-
want: controllerruntime.Result{},
285-
wantErr: true,
286-
},
287250
}
288251
for _, tt := range tests {
289252
t.Run(tt.name, func(t *testing.T) {

pkg/scheduler/event_handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ func (s *Scheduler) deleteCluster(obj interface{}) {
300300
if s.enableSchedulerEstimator {
301301
s.schedulerEstimatorWorker.Add(cluster.Name)
302302
}
303+
304+
s.clusterReconcileWorker.Add(cluster)
303305
}
304306

305307
func schedulerNameFilter(schedulerNameFromOptions, schedulerName string) bool {

pkg/scheduler/event_handler_test.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,23 @@ func TestDeleteCluster(t *testing.T) {
310310
obj interface{}
311311
expectedAdded bool
312312
expectedClusterName string
313+
expectedReconcileAdded int
313314
}{
314315
{
315316
name: "valid cluster object with estimator enabled",
316317
enableSchedulerEstimator: true,
317318
obj: createCluster("test-cluster", 0, nil),
318319
expectedAdded: true,
319320
expectedClusterName: "test-cluster",
321+
expectedReconcileAdded: 1,
320322
},
321323
{
322324
name: "valid cluster object with estimator disabled",
323325
enableSchedulerEstimator: false,
324326
obj: createCluster("test-cluster", 0, nil),
325327
expectedAdded: false,
326328
expectedClusterName: "",
329+
expectedReconcileAdded: 1,
327330
},
328331
{
329332
name: "deleted final state unknown with valid cluster",
@@ -332,8 +335,9 @@ func TestDeleteCluster(t *testing.T) {
332335
Key: "test-cluster",
333336
Obj: createCluster("test-cluster", 0, nil),
334337
},
335-
expectedAdded: true,
336-
expectedClusterName: "test-cluster",
338+
expectedAdded: true,
339+
expectedClusterName: "test-cluster",
340+
expectedReconcileAdded: 1,
337341
},
338342
{
339343
name: "deleted final state unknown with invalid object",
@@ -342,35 +346,42 @@ func TestDeleteCluster(t *testing.T) {
342346
Key: "test-pod",
343347
Obj: &corev1.Pod{},
344348
},
345-
expectedAdded: false,
346-
expectedClusterName: "",
349+
expectedAdded: false,
350+
expectedClusterName: "",
351+
expectedReconcileAdded: 0,
347352
},
348353
{
349354
name: "invalid object type",
350355
enableSchedulerEstimator: true,
351356
obj: &corev1.Pod{},
352357
expectedAdded: false,
353358
expectedClusterName: "",
359+
expectedReconcileAdded: 0,
354360
},
355361
}
356362

357363
for _, tt := range tests {
358364
t.Run(tt.name, func(t *testing.T) {
359-
worker := &mockAsyncWorker{}
365+
estimatorWorker := &mockAsyncWorker{}
366+
reconcileWorker := &mockAsyncWorker{}
360367
s := &Scheduler{
361368
enableSchedulerEstimator: tt.enableSchedulerEstimator,
362-
schedulerEstimatorWorker: worker,
369+
schedulerEstimatorWorker: estimatorWorker,
370+
clusterReconcileWorker: reconcileWorker,
363371
}
364372

365373
s.deleteCluster(tt.obj)
366374

367375
if tt.expectedAdded {
368-
assert.Equal(t, 1, worker.addCount, "Worker Add should have been called once")
369-
assert.Equal(t, tt.expectedClusterName, worker.lastAdded, "Incorrect cluster name added to worker")
376+
assert.Equal(t, 1, estimatorWorker.addCount, "Worker Add should have been called once")
377+
assert.Equal(t, tt.expectedClusterName, estimatorWorker.lastAdded, "Incorrect cluster name added to worker")
370378
} else {
371-
assert.Equal(t, 0, worker.addCount, "Worker Add should not have been called")
372-
assert.Nil(t, worker.lastAdded, "No cluster name should have been added")
379+
assert.Equal(t, 0, estimatorWorker.addCount, "Worker Add should not have been called")
380+
assert.Nil(t, estimatorWorker.lastAdded, "No cluster name should have been added")
373381
}
382+
383+
// Check clusterReconcileWorker
384+
assert.Equal(t, tt.expectedReconcileAdded, reconcileWorker.addCount, "Reconcile worker Add called unexpected number of times")
374385
})
375386
}
376387
}

0 commit comments

Comments
 (0)