kubectl describe: print toleration tolerating everything

An empty key with operator Exists matches all keys, values
and effects which means this will tolerate everything:
tolerations:
- operator: "Exists"

as stated in https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/.

However, the current printTolerationsMultilineWithIndent implementation ignores
this case. As the toleration is valid, there's no reason
to skip it when writing the list of all pod's tolerations.

Kubernetes-commit: 0bd9a4c6c5ba4fbbc8439effddc99004ddd6b232
This commit is contained in:
Jan Chaloupka 2020-05-12 15:59:52 +02:00 committed by Kubernetes Publisher
parent 8158b274a3
commit 50e4974848
2 changed files with 14 additions and 1 deletions

View File

@ -4606,6 +4606,17 @@ func printTolerationsMultilineWithIndent(w PrefixWriter, initialIndent, title, i
if len(toleration.Effect) != 0 {
w.Write(LEVEL_0, ":%s", toleration.Effect)
}
// tolerations:
// - operator: "Exists"
// is a special case which tolerates everything
if toleration.Operator == corev1.TolerationOpExists && len(toleration.Value) == 0 {
if len(toleration.Key) != 0 {
w.Write(LEVEL_0, " op=Exists")
} else {
w.Write(LEVEL_0, "op=Exists")
}
}
if toleration.TolerationSeconds != nil {
w.Write(LEVEL_0, " for %ds", *toleration.TolerationSeconds)
}

View File

@ -179,6 +179,7 @@ func TestDescribePodTolerations(t *testing.T) {
},
Spec: corev1.PodSpec{
Tolerations: []corev1.Toleration{
{Operator: corev1.TolerationOpExists},
{Key: "key0", Operator: corev1.TolerationOpExists},
{Key: "key1", Value: "value1"},
{Key: "key2", Operator: corev1.TolerationOpEqual, Value: "value2", Effect: corev1.TaintEffectNoSchedule},
@ -193,7 +194,8 @@ func TestDescribePodTolerations(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(out, "key0\n") ||
if !strings.Contains(out, " op=Exists\n") ||
!strings.Contains(out, "key0 op=Exists\n") ||
!strings.Contains(out, "key1=value1\n") ||
!strings.Contains(out, "key2=value2:NoSchedule\n") ||
!strings.Contains(out, "key3=value3:NoExecute for 300s\n") ||