From 68a70347c9060f6047f53007c81fbc40a4fb73d9 Mon Sep 17 00:00:00 2001 From: Yusuke KUOKA Date: Fri, 20 Jul 2018 17:26:10 +0900 Subject: [PATCH] feat(helm): Detailed exit code for helm plugins Resolves #4170 --- cmd/helm/helm.go | 7 ++++++- cmd/helm/load_plugins.go | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 4c7ca9290..8ba50a152 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -158,7 +158,12 @@ func init() { func main() { cmd := newRootCmd(os.Args[1:]) if err := cmd.Execute(); err != nil { - os.Exit(1) + switch e := err.(type) { + case pluginError: + os.Exit(e.code) + default: + os.Exit(1) + } } } diff --git a/cmd/helm/load_plugins.go b/cmd/helm/load_plugins.go index ef24e7883..2c786bed3 100644 --- a/cmd/helm/load_plugins.go +++ b/cmd/helm/load_plugins.go @@ -22,12 +22,18 @@ import ( "os/exec" "path/filepath" "strings" + "syscall" "github.com/spf13/cobra" "k8s.io/helm/pkg/plugin" ) +type pluginError struct { + error + code int +} + // loadPlugins loads plugins into the command list. // // This follows a different pattern than the other commands because it has @@ -87,7 +93,11 @@ func loadPlugins(baseCmd *cobra.Command, out io.Writer) { if err := prog.Run(); err != nil { if eerr, ok := err.(*exec.ExitError); ok { os.Stderr.Write(eerr.Stderr) - return fmt.Errorf("plugin %q exited with error", md.Name) + status := eerr.Sys().(syscall.WaitStatus) + return pluginError{ + error: fmt.Errorf("plugin %q exited with error", md.Name), + code: status.ExitStatus(), + } } return err }