Skip to content

Commit

Permalink
error msg fixes
Browse files Browse the repository at this point in the history
Miscellaneous error message tweaks.
Makes the error message displayed in `kubectl get` more visible.
Returns exit code 1 if a patch fails.
  • Loading branch information
juanvallejo committed Sep 13, 2017
1 parent a416534 commit dfef857
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/kubectl/cmd/cmd.go
Expand Up @@ -239,7 +239,8 @@ __custom_func() {
* services (aka 'svc')
* statefulsets
* storageclasses
`
`
)

var (
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubectl/cmd/patch.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
}

Expand All @@ -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
}

Expand Down

0 comments on commit dfef857

Please sign in to comment.