mirror of https://github.com/k3s-io/k3s
Merge pull request #47380 from kevin-wangzefeng/pod-tolerations-with-no-value
Automatic merge from submit-queue hide operator when describe pod with empty value tolerations **What this PR does / why we need it**: The tolerations printing in `kubectl descirbe pod` is not correct when toleration.value is empty, this PR is to fix it. Before: ``` Tolerations: node.alpha.kubernetes.io/notReady=:Exists:NoExecute for 300s node.alpha.kubernetes.io/unreachable=:Exists:NoExecute for 300s ``` After: ``` Tolerations: node.alpha.kubernetes.io/notReady:NoExecute for 300s node.alpha.kubernetes.io/unreachable:NoExecute for 300s ``` Also updated tests to cover all possible cases of describing pod with tolerations. See changes in of `TestDescribePodTolerations()` in `describe_test.go` **Which issue this PR fixes**: **Special notes for your reviewer**: **Release note**: ```release-note NONE ```pull/6/head
commit
a8968810fd
|
@ -3321,9 +3321,9 @@ func printTolerationsMultilineWithIndent(w PrefixWriter, initialIndent, title, i
|
|||
w.Write(LEVEL_0, "%s", initialIndent)
|
||||
w.Write(LEVEL_0, "%s", innerIndent)
|
||||
}
|
||||
w.Write(LEVEL_0, "%s=%s", toleration.Key, toleration.Value)
|
||||
if len(toleration.Operator) != 0 {
|
||||
w.Write(LEVEL_0, ":%s", toleration.Operator)
|
||||
w.Write(LEVEL_0, "%s", toleration.Key)
|
||||
if len(toleration.Value) != 0 {
|
||||
w.Write(LEVEL_0, "=%s", toleration.Value)
|
||||
}
|
||||
if len(toleration.Effect) != 0 {
|
||||
w.Write(LEVEL_0, ":%s", toleration.Effect)
|
||||
|
|
|
@ -102,8 +102,11 @@ func TestDescribePodTolerations(t *testing.T) {
|
|||
},
|
||||
Spec: api.PodSpec{
|
||||
Tolerations: []api.Toleration{
|
||||
{Key: "key0", Operator: api.TolerationOpExists},
|
||||
{Key: "key1", Value: "value1"},
|
||||
{Key: "key2", Value: "value2", Effect: api.TaintEffectNoExecute, TolerationSeconds: &[]int64{300}[0]},
|
||||
{Key: "key2", Operator: api.TolerationOpEqual, Value: "value2", Effect: api.TaintEffectNoSchedule},
|
||||
{Key: "key3", Value: "value3", Effect: api.TaintEffectNoExecute, TolerationSeconds: &[]int64{300}[0]},
|
||||
{Key: "key4", Effect: api.TaintEffectNoExecute, TolerationSeconds: &[]int64{60}[0]},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -113,8 +116,13 @@ func TestDescribePodTolerations(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if !strings.Contains(out, "key1=value1") || !strings.Contains(out, "key2=value2:NoExecute for 300s") || !strings.Contains(out, "Tolerations:") {
|
||||
t.Errorf("unexpected out: %s", out)
|
||||
if !strings.Contains(out, "key0\n") ||
|
||||
!strings.Contains(out, "key1=value1\n") ||
|
||||
!strings.Contains(out, "key2=value2:NoSchedule\n") ||
|
||||
!strings.Contains(out, "key3=value3:NoExecute for 300s\n") ||
|
||||
!strings.Contains(out, "key4:NoExecute for 60s\n") ||
|
||||
!strings.Contains(out, "Tolerations:") {
|
||||
t.Errorf("unexpected out:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue