update exit code to 0 if patch not needed

parent 4d5d2664
......@@ -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++
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment