From 96d3f4552f763e1951c23e1b957e28d25f689873 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Tue, 17 Oct 2017 17:28:29 -0400 Subject: [PATCH] exit with correct exit code on plugin failure --- pkg/kubectl/cmd/plugin.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/kubectl/cmd/plugin.go b/pkg/kubectl/cmd/plugin.go index e883d1a65df..b69e7a89c68 100644 --- a/pkg/kubectl/cmd/plugin.go +++ b/pkg/kubectl/cmd/plugin.go @@ -19,6 +19,9 @@ package cmd import ( "fmt" "io" + "os" + "os/exec" + "syscall" "github.com/golang/glog" "github.com/spf13/cobra" @@ -109,6 +112,15 @@ func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.P } if err := runner.Run(plugin, runningContext); err != nil { + if exiterr, ok := err.(*exec.ExitError); ok { + // check for (and exit with) the correct exit code + // from a failed plugin command execution + if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { + fmt.Fprintf(errout, "error: %v\n", err) + os.Exit(status.ExitStatus()) + } + } + cmdutil.CheckErr(err) } },