Skip to content

Commit

Permalink
Merge pull request #431 from openSUSE/exec-sync-code
Browse files Browse the repository at this point in the history
Change exec-sync on exit code != 0
  • Loading branch information
k8s-ci-robot authored Jan 31, 2019
2 parents 99551e7 + 0bb541f commit e392824
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions cmd/crictl/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ var runtimeExecCommand = cli.Command{
cmd: context.Args()[1:],
}
if context.Bool("sync") {
err := ExecSync(runtimeClient, opts)
exitCode, err := ExecSync(runtimeClient, opts)
if err != nil {
return fmt.Errorf("execing command in container synchronously failed: %v", err)
}
if exitCode != 0 {
return cli.NewExitError("non-zero exit code", exitCode)
}
return nil
}
err := Exec(runtimeClient, opts)
Expand All @@ -94,8 +97,9 @@ var runtimeExecCommand = cli.Command{
}

// ExecSync sends an ExecSyncRequest to the server, and parses
// the returned ExecSyncResponse.
func ExecSync(client pb.RuntimeServiceClient, opts execOptions) error {
// the returned ExecSyncResponse. The function returns the corresponding exit
// code beside an general error.
func ExecSync(client pb.RuntimeServiceClient, opts execOptions) (int, error) {
request := &pb.ExecSyncRequest{
ContainerId: opts.id,
Cmd: opts.cmd,
Expand All @@ -105,15 +109,11 @@ func ExecSync(client pb.RuntimeServiceClient, opts execOptions) error {
r, err := client.ExecSync(context.Background(), request)
logrus.Debugf("ExecSyncResponse: %v", r)
if err != nil {
return err
return 1, err
}
fmt.Println(string(r.Stdout))
fmt.Println(string(r.Stderr))
if r.ExitCode != 0 {
fmt.Printf("Exit code: %v\n", r.ExitCode)
}

return nil
return int(r.ExitCode), nil
}

// Exec sends an ExecRequest to server, and parses the returned ExecResponse
Expand Down

0 comments on commit e392824

Please sign in to comment.