Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

cli: allow to kill a stopped container and sandbox #1085

Merged
merged 1 commit into from
Jan 8, 2019

Conversation

bergwolf
Copy link
Member

@bergwolf bergwolf commented Jan 3, 2019

cri containerd calls kill on stopped sandbox and if we
fail the call, it can cause cri stopp command to fail
too.

Also add a few logs to track container state transitioning.

Fixes: #1084

// container MUST be created, running or paused
if status.State.State == vc.StateReady || status.State.State == vc.StateRunning || status.State.State == vc.StatePaused {
if err := vci.KillContainer(ctx, sandboxID, containerID, signum, all); err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the sandbox/container has stopped, will the following vci.StopSandbox/vci.StopContainer return another err?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's ignored in sandbox.stop()

@bergwolf
Copy link
Member Author

bergwolf commented Jan 3, 2019

/test

@lifupan
Copy link
Member

lifupan commented Jan 3, 2019

It seems there's something wrong with the CI.
LGTM!

Approved with PullApprove

Copy link

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bergwolf
I understand what you're doing by making the kill more permissive and the Sandbox stop idempotent, but I'm worried we might not be OCI compliant anymore.
If you take a look here: https://github.com/opencontainers/runtime-spec/blob/master/runtime.md#kill, it specifies clearly that sending a signal to a container that is not running or created must return an error.

I'm wondering if instead we should try to fix the behavior at the crictl level, by making sure that crictl ignores an error coming from a kill, since the container might already be stopped. WDYT?

@bergwolf
Copy link
Member Author

bergwolf commented Jan 3, 2019

@sboeuf Good point! After taking a closer look, it is because of a tiny difference with how we handle kill -a compared with runc. The -a option is not documented in OCI runtime spec. As a result we have to follow runc behavior and do not fail on container status when -a is specified, see https://github.com/opencontainers/runc/blob/master/libcontainer/container_linux.go#L378

I've updated the PR to include above change. PTAL.

@egernst
Copy link
Member

egernst commented Jan 3, 2019

/test

@sboeuf
Copy link

sboeuf commented Jan 4, 2019

/test

@bergwolf
Copy link
Member Author

bergwolf commented Jan 7, 2019

/test

virtcontainers/sandbox.go Show resolved Hide resolved
return err
}
} else if !all {
return fmt.Errorf("container not running")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a unit test for this scenario (and the one above in the if)?

cri containerd calls kill on stopped sandbox and if we
fail the call, it can cause `cri stopp` command to fail
too.

Fixes: kata-containers#1084

Signed-off-by: Peng Tao <[email protected]>
@bergwolf
Copy link
Member Author

bergwolf commented Jan 8, 2019

/test

@sboeuf
Copy link

sboeuf commented Jan 8, 2019

@jodh-intel unit test has been added, if this is okay for you, please merge the PR!

@jodh-intel
Copy link
Contributor

jodh-intel commented Jan 8, 2019

Thanks @bergwolf!

lgtm

Approved with PullApprove

@jodh-intel jodh-intel merged commit 36c267a into kata-containers:master Jan 8, 2019
@bergwolf bergwolf deleted the containerd branch March 27, 2019 07:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants