Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change exec-sync on exit code != 0 #431

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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