Skip to content

Commit

Permalink
Return non-zero exit code in case of errors
Browse files Browse the repository at this point in the history
At the moment, k8s and k8sd return 0 even if the command fails,
which is a problem especially when used inside scripts.

We'll ensure that a non-zero exit code is returned if the commands
fail.
  • Loading branch information
petrutlucian94 committed Sep 23, 2024
1 parent 5fe3c27 commit 9e29bf9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/k8s/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ func main() {

// choose command based on the binary name
base := filepath.Base(os.Args[0])
var err error
switch base {
case "k8s-apiserver-proxy":
k8s_apiserver_proxy.NewRootCmd(env).ExecuteContext(ctx)
err = k8s_apiserver_proxy.NewRootCmd(env).ExecuteContext(ctx)
case "k8sd":
k8sd.NewRootCmd(env).ExecuteContext(ctx)
err = k8sd.NewRootCmd(env).ExecuteContext(ctx)
case "k8s":
k8s.NewRootCmd(env).ExecuteContext(ctx)
err = k8s.NewRootCmd(env).ExecuteContext(ctx)
default:
panic(fmt.Errorf("invalid entrypoint name %q", base))
}

// Return a non-zero exit code if the command failed.
if err != nil {
os.Exit(1);
}
}

0 comments on commit 9e29bf9

Please sign in to comment.