Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 7e7b80c

Browse files
authored
Merge pull request #99 from lucab/to-upstream/exec-error
runtime/exec: do not mix errors and status codes
2 parents e1e9414 + acadef4 commit 7e7b80c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

rktlet/runtime/exec.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ func (r *RktRuntime) ExecSync(ctx context.Context, req *runtimeapi.ExecSyncReque
5050
// TODO: Respect req.Timeout
5151
exitCode := int32(0)
5252
err := r.execShim.Exec(req.ContainerId, req.Cmd, nil, ioutils.WriteCloserWrapper(&stdout), ioutils.WriteCloserWrapper(&stderr), false, nil)
53-
if exitErr, ok := err.(utilexec.ExitError); ok {
53+
exitErr, ok := err.(utilexec.ExitError)
54+
if ok {
5455
exitCode = int32(exitErr.ExitStatus())
5556
}
56-
if err != nil {
57+
58+
// rktlet internal error
59+
if !ok && err != nil {
5760
return nil, err
5861
}
5962

tests/runtime/runtime_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ func TestExecSync(t *testing.T) {
185185
assert.Nil(t, err, "could not get container ID")
186186
fmt.Printf("got containerID %s\n", containerID)
187187

188+
dummyRes, err := tc.Rktlet.ExecSync(context.TODO(), &runtime.ExecSyncRequest{
189+
ContainerId: containerID,
190+
Cmd: []string{"sh", "-c", "exit 17"},
191+
})
192+
assert.Nil(t, err)
193+
assert.NotNil(t, dummyRes)
194+
assert.Equal(t, int32(17), dummyRes.ExitCode)
195+
188196
execRes, err := tc.Rktlet.ExecSync(context.TODO(), &runtime.ExecSyncRequest{
189197
ContainerId: containerID,
190198
Cmd: []string{"sh", "-c", "echo 42 > /exit; echo success; sleep 0.5"},

0 commit comments

Comments
 (0)