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.
This commit is contained in:
Jan Chaloupka 2020-05-12 15:59:52 +02:00
parent 70948498bc
commit 0bd9a4c6c5
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 { if len(toleration.Effect) != 0 {
w.Write(LEVEL_0, ":%s", toleration.Effect) 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 { if toleration.TolerationSeconds != nil {
w.Write(LEVEL_0, " for %ds", *toleration.TolerationSeconds) w.Write(LEVEL_0, " for %ds", *toleration.TolerationSeconds)
} }

View File

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