Skip to content

Commit

Permalink
Merge pull request #5879 from XiShanYongYe-Chang/taint-manager-purgemode
Browse files Browse the repository at this point in the history
Update taint-manager to config eviction task with purgeMode
  • Loading branch information
karmada-bot authored Nov 25, 2024
2 parents 9267eae + 25867c4 commit 72cfef5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/controllers/cluster/taint_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/features"
"github.com/karmada-io/karmada/pkg/util"
Expand Down Expand Up @@ -172,9 +173,15 @@ func (tc *NoExecuteTaintManager) syncBindingEviction(key util.QueueKey) error {
if needEviction || tolerationTime == 0 {
// update final result to evict the target cluster
if features.FeatureGate.Enabled(features.GracefulEviction) {
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager), workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated)))
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(
workv1alpha2.WithPurgeMode(policyv1alpha1.Graciously),
workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated)))
} else {
binding.Spec.RemoveCluster(cluster)
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(
workv1alpha2.WithPurgeMode(policyv1alpha1.Immediately),
workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated)))
}
if err = tc.Update(context.TODO(), binding); err != nil {
helper.EmitClusterEvictionEventForResourceBinding(binding, cluster, tc.EventRecorder, err)
Expand Down Expand Up @@ -228,9 +235,15 @@ func (tc *NoExecuteTaintManager) syncClusterBindingEviction(key util.QueueKey) e
if needEviction || tolerationTime == 0 {
// update final result to evict the target cluster
if features.FeatureGate.Enabled(features.GracefulEviction) {
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager), workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated)))
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(
workv1alpha2.WithPurgeMode(policyv1alpha1.Graciously),
workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated)))
} else {
binding.Spec.RemoveCluster(cluster)
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(
workv1alpha2.WithPurgeMode(policyv1alpha1.Immediately),
workv1alpha2.WithProducer(workv1alpha2.EvictionProducerTaintManager),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonTaintUntolerated)))
}
if err = tc.Update(context.TODO(), binding); err != nil {
helper.EmitClusterEvictionEventForClusterResourceBinding(binding, cluster, tc.EventRecorder, err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/controllers/cluster/taint_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/fedinformer/keys"
Expand Down Expand Up @@ -237,6 +238,7 @@ func TestNoExecuteTaintManager_syncBindingEviction(t *testing.T) {
GracefulEvictionTasks: []workv1alpha2.GracefulEvictionTask{
{
FromCluster: "test-cluster",
PurgeMode: policyv1alpha1.Graciously,
Replicas: &replica,
Reason: workv1alpha2.EvictionReasonTaintUntolerated,
Producer: workv1alpha2.EvictionProducerTaintManager,
Expand Down Expand Up @@ -403,6 +405,7 @@ func TestNoExecuteTaintManager_syncClusterBindingEviction(t *testing.T) {
GracefulEvictionTasks: []workv1alpha2.GracefulEvictionTask{
{
FromCluster: "test-cluster",
PurgeMode: policyv1alpha1.Graciously,
Replicas: &replica,
Reason: workv1alpha2.EvictionReasonTaintUntolerated,
Producer: workv1alpha2.EvictionProducerTaintManager,
Expand Down

0 comments on commit 72cfef5

Please sign in to comment.