Skip to content

Commit

Permalink
exit with correct exit code on plugin failure
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Oct 18, 2017
1 parent dfdfb89 commit 96d3f45
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/kubectl/cmd/plugin.go
Expand Up @@ -19,6 +19,9 @@ package cmd
import (
"fmt"
"io"
"os"
"os/exec"
"syscall"

"github.com/golang/glog"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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)
}
},
Expand Down

0 comments on commit 96d3f45

Please sign in to comment.