mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-26 21:31:18 +01:00
Drop local implementation of toleratesTaint in favor of k8s.io/api/core/v1.Toleration.TolerateTaint
Functionally identical implementation of toleratesTaint is already provided in k8s.io/api
This commit is contained in:
@@ -97,24 +97,6 @@ func getNoScheduleTaints(taints []v1.Taint) []v1.Taint {
|
||||
return result
|
||||
}
|
||||
|
||||
//toleratesTaint returns true if a toleration tolerates a taint, or false otherwise
|
||||
func toleratesTaint(toleration *v1.Toleration, taint *v1.Taint) bool {
|
||||
|
||||
if (len(toleration.Key) > 0 && toleration.Key != taint.Key) ||
|
||||
(len(toleration.Effect) > 0 && toleration.Effect != taint.Effect) {
|
||||
return false
|
||||
}
|
||||
switch toleration.Operator {
|
||||
// empty operator means Equal
|
||||
case "", TolerationOpEqual:
|
||||
return toleration.Value == taint.Value
|
||||
case TolerationOpExists:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// allTaintsTolerated returns true if all are tolerated, or false otherwise.
|
||||
func allTaintsTolerated(taints []v1.Taint, tolerations []v1.Toleration) bool {
|
||||
if len(taints) == 0 {
|
||||
@@ -126,7 +108,7 @@ func allTaintsTolerated(taints []v1.Taint, tolerations []v1.Toleration) bool {
|
||||
for i := range taints {
|
||||
tolerated := false
|
||||
for j := range tolerations {
|
||||
if toleratesTaint(&tolerations[j], &taints[i]) {
|
||||
if tolerations[j].ToleratesTaint(&taints[i]) {
|
||||
tolerated = true
|
||||
break
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ func TestToleratesTaint(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
if tolerated := toleratesTaint(&tc.toleration, &tc.taint); tc.expectTolerated != tolerated {
|
||||
if tolerated := tc.toleration.ToleratesTaint(&tc.taint); tc.expectTolerated != tolerated {
|
||||
t.Errorf("[%s] expect %v, got %v: toleration %+v, taint %s", tc.description, tc.expectTolerated, tolerated, tc.toleration, tc.taint.ToString())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user