From 04185f4e533b9b8ebaabe1ed09516e85c5ed1ae1 Mon Sep 17 00:00:00 2001 From: Quan Tian Date: Mon, 21 Sep 2020 23:45:31 +0800 Subject: [PATCH] kubectl: add a space between effect and operator when printing tolerations Empty key and non-empty effect means to match all keys and values and the specified effect. However "kubectl describe" prints it without space between effect and operator. This patch adds the space for this case. --- staging/src/k8s.io/kubectl/pkg/describe/describe.go | 2 +- staging/src/k8s.io/kubectl/pkg/describe/describe_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe.go b/staging/src/k8s.io/kubectl/pkg/describe/describe.go index 2adf30c574b..da1e74f2ae6 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe.go @@ -4841,7 +4841,7 @@ func printTolerationsMultilineWithIndent(w PrefixWriter, initialIndent, title, i // - operator: "Exists" // is a special case which tolerates everything if toleration.Operator == corev1.TolerationOpExists && len(toleration.Value) == 0 { - if len(toleration.Key) != 0 { + if len(toleration.Key) != 0 || len(toleration.Effect) != 0 { w.Write(LEVEL_0, " op=Exists") } else { w.Write(LEVEL_0, "op=Exists") diff --git a/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go b/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go index d5e754542c1..1eec9c70093 100644 --- a/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go +++ b/staging/src/k8s.io/kubectl/pkg/describe/describe_test.go @@ -180,6 +180,7 @@ func TestDescribePodTolerations(t *testing.T) { Spec: corev1.PodSpec{ Tolerations: []corev1.Toleration{ {Operator: corev1.TolerationOpExists}, + {Effect: corev1.TaintEffectNoSchedule, Operator: corev1.TolerationOpExists}, {Key: "key0", Operator: corev1.TolerationOpExists}, {Key: "key1", Value: "value1"}, {Key: "key2", Operator: corev1.TolerationOpEqual, Value: "value2", Effect: corev1.TaintEffectNoSchedule}, @@ -195,6 +196,7 @@ func TestDescribePodTolerations(t *testing.T) { t.Errorf("unexpected error: %v", err) } if !strings.Contains(out, " op=Exists\n") || + !strings.Contains(out, ":NoSchedule op=Exists\n") || !strings.Contains(out, "key0 op=Exists\n") || !strings.Contains(out, "key1=value1\n") || !strings.Contains(out, "key2=value2:NoSchedule\n") ||