From 2e61cacc45cf0260782d33693caa37989cff5ca7 Mon Sep 17 00:00:00 2001 From: Manu Gupta Date: Thu, 29 Jul 2021 23:26:07 +0000 Subject: [PATCH] fix: 81134: display conflicted taint without a json representation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pkg/cmd/taint/taint.go | 2 +- pkg/cmd/taint/taint_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/taint/taint.go b/pkg/cmd/taint/taint.go index ec59d14c..2a74323c 100644 --- a/pkg/cmd/taint/taint.go +++ b/pkg/cmd/taint/taint.go @@ -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) } } diff --git a/pkg/cmd/taint/taint_test.go b/pkg/cmd/taint/taint_test.go index a154c97d..02fd13be 100644 --- a/pkg/cmd/taint/taint_test.go +++ b/pkg/cmd/taint/taint_test.go @@ -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{{