From ad11a1b7a638dbfb4081fbab07ae747110288e30 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Fri, 27 Jul 2018 15:54:18 -0400 Subject: [PATCH] update exit code to 0 if patch not needed --- pkg/kubectl/cmd/patch.go | 8 +------- test/cmd/core.sh | 8 ++++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pkg/kubectl/cmd/patch.go b/pkg/kubectl/cmd/patch.go index bfd50e0899..51e967aa11 100644 --- a/pkg/kubectl/cmd/patch.go +++ b/pkg/kubectl/cmd/patch.go @@ -245,14 +245,8 @@ func (o *PatchOptions) RunPatch() error { if err != nil { return err } - printer.PrintObj(info.Object, o.Out) - // if object was not successfully patched, exit with error code 1 - if !didPatch { - return cmdutil.ErrExit - } - - return nil + return printer.PrintObj(info.Object, o.Out) } count++ diff --git a/test/cmd/core.sh b/test/cmd/core.sh index 28ab0cf3c1..62c8ff8446 100755 --- a/test/cmd/core.sh +++ b/test/cmd/core.sh @@ -435,8 +435,12 @@ run_pod_tests() { ## Patch can modify a local object kubectl patch --local -f pkg/kubectl/validation/testdata/v1/validPod.yaml --patch='{"spec": {"restartPolicy":"Never"}}' -o yaml | grep -q "Never" - ## Patch fails with error message "not patched" and exit code 1 - output_message=$(! kubectl patch "${kube_flags[@]}" pod valid-pod -p='{"spec":{"replicas":7}}' 2>&1) + ## Patch fails with type restore error and exit code 1 + output_message=$(! kubectl patch "${kube_flags[@]}" pod valid-pod -p='{"metadata":{"labels":"invalid"}}' 2>&1) + kube::test::if_has_string "${output_message}" 'cannot restore map from string' + + ## Patch exits with error message "not patched" and exit code 0 when no-op occurs + output_message=$(kubectl patch "${kube_flags[@]}" pod valid-pod -p='{"metadata":{"labels":{"name":"valid-pod"}}}' 2>&1) kube::test::if_has_string "${output_message}" 'not patched' ## Patch pod can change image