fix: 81134: display conflicted taint without a json representation.

1. string is formatted as unsafe json. Since this is created on the fly;
TaintKey and Effect are formatted as a 'key=effect' instead of '{key=effect}'
eliminating unsafe json representation.

2. Adds a fail test case for the case where a taint with same key and effect is added
and removed together.

Manual Testing

```
▶ ./_output/bin/kubectl taint nodes kind-control-plane key1=:NoSchedule key1=:NoSchedule-
error: can not both modify and remove the following taint(s) in the same command: key1=NoSchedule
```

Kubernetes-commit: 1a3eda9394b7ff473434506f2756cc9df6288cea
This commit is contained in:
Manu Gupta 2021-07-29 23:26:07 +00:00 committed by Kubernetes Publisher
parent 2a6bb49405
commit 2e61cacc45
2 changed files with 7 additions and 1 deletions

View File

@ -248,7 +248,7 @@ func (o TaintOptions) Validate() error {
continue
}
if len(taintRemove.Effect) == 0 || taintAdd.Effect == taintRemove.Effect {
conflictTaint := fmt.Sprintf("{\"%s\":\"%s\"}", taintRemove.Key, taintRemove.Effect)
conflictTaint := fmt.Sprintf("%s=%s", taintRemove.Key, taintRemove.Effect)
conflictTaints = append(conflictTaints, conflictTaint)
}
}

View File

@ -216,6 +216,12 @@ func TestTaint(t *testing.T) {
expectFatal: true,
expectTaint: false,
},
{
description: "add and remove taint with same key and effect should be rejected",
args: []string{"node", "node-name", "foo=:NoExcute", "foo=:NoExcute-"},
expectFatal: true,
expectTaint: false,
},
{
description: "can't update existing taint on the node, since 'overwrite' flag is not set",
oldTaints: []corev1.Taint{{