From dfef8574cfc71f5b148f3f1d687b50660794b305 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 13 Sep 2017 17:55:26 -0400 Subject: [PATCH] error msg fixes Miscellaneous error message tweaks. Makes the error message displayed in `kubectl get` more visible. Returns exit code 1 if a patch fails. --- pkg/kubectl/cmd/cmd.go | 3 ++- pkg/kubectl/cmd/patch.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index cb85111db26..87d81079e31 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -239,7 +239,8 @@ __custom_func() { * services (aka 'svc') * statefulsets * storageclasses - ` + +` ) var ( diff --git a/pkg/kubectl/cmd/patch.go b/pkg/kubectl/cmd/patch.go index f0de9caa192..02fae07d152 100644 --- a/pkg/kubectl/cmd/patch.go +++ b/pkg/kubectl/cmd/patch.go @@ -183,6 +183,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin if !options.Local { dataChangedMsg := "not patched" + didPatch := false helper := resource.NewHelper(client, mapping) patchedObj, err := helper.Patch(namespace, name, patchType, patchBytes) if err != nil { @@ -213,6 +214,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin return err } if !reflect.DeepEqual(oldData, newData) { + didPatch = true dataChangedMsg = "patched" } @@ -229,6 +231,12 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin return err } cmdutil.PrintSuccess(mapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg) + + // if object was not successfully patched, exit with error code 1 + if !didPatch { + return cmdutil.ErrExit + } + return nil }