mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
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:
parent
70948498bc
commit
0bd9a4c6c5
@ -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)
|
||||
}
|
||||
|
@ -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") ||
|
||||
|
Loading…
Reference in New Issue
Block a user