mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-28 14:41:10 +01:00
Call utils.TolerationsTolerateTaintsWithFilter directly, not through checkPodsSatisfyTolerations
This commit is contained in:
@@ -28,11 +28,6 @@ import (
|
|||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
TolerationOpExists v1.TolerationOperator = "Exists"
|
|
||||||
TolerationOpEqual v1.TolerationOperator = "Equal"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RemovePodsViolatingNodeTaints with elimination strategy
|
// RemovePodsViolatingNodeTaints with elimination strategy
|
||||||
func RemovePodsViolatingNodeTaints(ds *options.DeschedulerServer, strategy api.DeschedulerStrategy, policyGroupVersion string, nodes []*v1.Node, nodePodCount utils.NodePodEvictedCount) {
|
func RemovePodsViolatingNodeTaints(ds *options.DeschedulerServer, strategy api.DeschedulerStrategy, policyGroupVersion string, nodes []*v1.Node, nodePodCount utils.NodePodEvictedCount) {
|
||||||
if !strategy.Enabled {
|
if !strategy.Enabled {
|
||||||
@@ -56,7 +51,12 @@ func deletePodsViolatingNodeTaints(client clientset.Interface, policyGroupVersio
|
|||||||
if maxPodsToEvict > 0 && nodePodCount[node]+1 > maxPodsToEvict {
|
if maxPodsToEvict > 0 && nodePodCount[node]+1 > maxPodsToEvict {
|
||||||
break
|
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)
|
success, err := evictions.EvictPod(client, pods[i], policyGroupVersion, dryRun)
|
||||||
if !success {
|
if !success {
|
||||||
klog.Errorf("Error when evicting pod: %#v (%#v)\n", pods[i].Name, err)
|
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
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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",
|
description: "toleration and taint have the same key and effect, and operator is Exists, and taint has no value, expect tolerated",
|
||||||
toleration: v1.Toleration{
|
toleration: v1.Toleration{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
Operator: TolerationOpExists,
|
Operator: v1.TolerationOpExists,
|
||||||
Effect: v1.TaintEffectNoSchedule,
|
Effect: v1.TaintEffectNoSchedule,
|
||||||
},
|
},
|
||||||
taint: v1.Taint{
|
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",
|
description: "toleration and taint have the same key and effect, and operator is Exists, and taint has some value, expect tolerated",
|
||||||
toleration: v1.Toleration{
|
toleration: v1.Toleration{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
Operator: TolerationOpExists,
|
Operator: v1.TolerationOpExists,
|
||||||
Effect: v1.TaintEffectNoSchedule,
|
Effect: v1.TaintEffectNoSchedule,
|
||||||
},
|
},
|
||||||
taint: v1.Taint{
|
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",
|
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{
|
toleration: v1.Toleration{
|
||||||
Key: "",
|
Key: "",
|
||||||
Operator: TolerationOpExists,
|
Operator: v1.TolerationOpExists,
|
||||||
Effect: v1.TaintEffectNoSchedule,
|
Effect: v1.TaintEffectNoSchedule,
|
||||||
},
|
},
|
||||||
taint: v1.Taint{
|
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",
|
description: "toleration and taint have the same key, effect and value, and operator is Equal, expect tolerated",
|
||||||
toleration: v1.Toleration{
|
toleration: v1.Toleration{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
Operator: TolerationOpEqual,
|
Operator: v1.TolerationOpEqual,
|
||||||
Value: "bar",
|
Value: "bar",
|
||||||
Effect: v1.TaintEffectNoSchedule,
|
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",
|
description: "toleration and taint have the same key and effect, but different values, and operator is Equal, expect not tolerated",
|
||||||
toleration: v1.Toleration{
|
toleration: v1.Toleration{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
Operator: TolerationOpEqual,
|
Operator: v1.TolerationOpEqual,
|
||||||
Value: "value1",
|
Value: "value1",
|
||||||
Effect: v1.TaintEffectNoSchedule,
|
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",
|
description: "toleration and taint have the same key and value, but different effects, and operator is Equal, expect not tolerated",
|
||||||
toleration: v1.Toleration{
|
toleration: v1.Toleration{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
Operator: TolerationOpEqual,
|
Operator: v1.TolerationOpEqual,
|
||||||
Value: "bar",
|
Value: "bar",
|
||||||
Effect: v1.TaintEffectNoSchedule,
|
Effect: v1.TaintEffectNoSchedule,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user