From 6db7c3b92ccf5316ef8ba236285120fff147dc52 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 19 Apr 2020 22:23:27 +0200 Subject: [PATCH] Call utils.TolerationsTolerateTaintsWithFilter directly, not through checkPodsSatisfyTolerations --- pkg/descheduler/strategies/node_taint.go | 25 +++++-------------- pkg/descheduler/strategies/node_taint_test.go | 12 ++++----- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/pkg/descheduler/strategies/node_taint.go b/pkg/descheduler/strategies/node_taint.go index b018d006b..3fa63518b 100644 --- a/pkg/descheduler/strategies/node_taint.go +++ b/pkg/descheduler/strategies/node_taint.go @@ -28,11 +28,6 @@ import ( "k8s.io/klog" ) -const ( - TolerationOpExists v1.TolerationOperator = "Exists" - TolerationOpEqual v1.TolerationOperator = "Equal" -) - // RemovePodsViolatingNodeTaints with elimination strategy func RemovePodsViolatingNodeTaints(ds *options.DeschedulerServer, strategy api.DeschedulerStrategy, policyGroupVersion string, nodes []*v1.Node, nodePodCount utils.NodePodEvictedCount) { if !strategy.Enabled { @@ -56,7 +51,12 @@ func deletePodsViolatingNodeTaints(client clientset.Interface, policyGroupVersio if maxPodsToEvict > 0 && nodePodCount[node]+1 > maxPodsToEvict { break } - if !checkPodsSatisfyTolerations(pods[i], node) { + if !utils.TolerationsTolerateTaintsWithFilter( + pods[i].Spec.Tolerations, + node.Spec.Taints, + func(taint *v1.Taint) bool { return taint.Effect == v1.TaintEffectNoSchedule }, + ) { + klog.V(2).Infof("Not all taints with NoSchedule effect are tolerated after update for pod %v on node %v", pods[i].Name, node.Name) success, err := evictions.EvictPod(client, pods[i], policyGroupVersion, dryRun) if !success { klog.Errorf("Error when evicting pod: %#v (%#v)\n", pods[i].Name, err) @@ -70,16 +70,3 @@ func deletePodsViolatingNodeTaints(client clientset.Interface, policyGroupVersio } return podsEvicted } - -// checkPodsSatisfyTolerations checks if the node's taints (NoSchedule) are still satisfied by pods' tolerations. -func checkPodsSatisfyTolerations(pod *v1.Pod, node *v1.Node) bool { - if !utils.TolerationsTolerateTaintsWithFilter( - pod.Spec.Tolerations, - node.Spec.Taints, - func(taint *v1.Taint) bool { return taint.Effect == v1.TaintEffectNoSchedule }, - ) { - klog.V(2).Infof("Not all taints are tolerated after update for Pod %v on node %v", pod.Name, node.Name) - return false - } - return true -} diff --git a/pkg/descheduler/strategies/node_taint_test.go b/pkg/descheduler/strategies/node_taint_test.go index 8749aa972..509844a52 100644 --- a/pkg/descheduler/strategies/node_taint_test.go +++ b/pkg/descheduler/strategies/node_taint_test.go @@ -188,7 +188,7 @@ func TestToleratesTaint(t *testing.T) { description: "toleration and taint have the same key and effect, and operator is Exists, and taint has no value, expect tolerated", toleration: v1.Toleration{ Key: "foo", - Operator: TolerationOpExists, + Operator: v1.TolerationOpExists, Effect: v1.TaintEffectNoSchedule, }, taint: v1.Taint{ @@ -201,7 +201,7 @@ func TestToleratesTaint(t *testing.T) { description: "toleration and taint have the same key and effect, and operator is Exists, and taint has some value, expect tolerated", toleration: v1.Toleration{ Key: "foo", - Operator: TolerationOpExists, + Operator: v1.TolerationOpExists, Effect: v1.TaintEffectNoSchedule, }, taint: v1.Taint{ @@ -215,7 +215,7 @@ func TestToleratesTaint(t *testing.T) { description: "toleration and taint have the same effect, toleration has empty key and operator is Exists, means match all taints, expect tolerated", toleration: v1.Toleration{ Key: "", - Operator: TolerationOpExists, + Operator: v1.TolerationOpExists, Effect: v1.TaintEffectNoSchedule, }, taint: v1.Taint{ @@ -229,7 +229,7 @@ func TestToleratesTaint(t *testing.T) { description: "toleration and taint have the same key, effect and value, and operator is Equal, expect tolerated", toleration: v1.Toleration{ Key: "foo", - Operator: TolerationOpEqual, + Operator: v1.TolerationOpEqual, Value: "bar", Effect: v1.TaintEffectNoSchedule, }, @@ -244,7 +244,7 @@ func TestToleratesTaint(t *testing.T) { description: "toleration and taint have the same key and effect, but different values, and operator is Equal, expect not tolerated", toleration: v1.Toleration{ Key: "foo", - Operator: TolerationOpEqual, + Operator: v1.TolerationOpEqual, Value: "value1", Effect: v1.TaintEffectNoSchedule, }, @@ -259,7 +259,7 @@ func TestToleratesTaint(t *testing.T) { description: "toleration and taint have the same key and value, but different effects, and operator is Equal, expect not tolerated", toleration: v1.Toleration{ Key: "foo", - Operator: TolerationOpEqual, + Operator: v1.TolerationOpEqual, Value: "bar", Effect: v1.TaintEffectNoSchedule, },