Commit 27cf62ac authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #43940 from xlgao-zju/rm-all-containers

Automatic merge from submit-queue (batch tested with PRs 42025, 44169, 43940) [CRI] Remove all containers in the sandbox Remove all containers in the sandbox, when we remove the sandbox. /cc @feiskyer @Random-Liu Signed-off-by: 's avatarXianglin Gao <xlgao@zju.edu.cn>
parents 0653751f b9c1d6c7
......@@ -218,14 +218,34 @@ func (ds *dockerService) StopPodSandbox(podSandboxID string) error {
// sandbox, they should be forcibly removed.
func (ds *dockerService) RemovePodSandbox(podSandboxID string) error {
var errs []error
opts := dockertypes.ContainerListOptions{All: true}
opts.Filter = dockerfilters.NewArgs()
f := newDockerFilter(&opts.Filter)
f.AddLabel(sandboxIDLabelKey, podSandboxID)
containers, err := ds.client.ListContainers(opts)
if err != nil {
errs = append(errs, err)
}
// Remove all containers in the sandbox.
for i := range containers {
if err := ds.RemoveContainer(containers[i].ID); err != nil && !dockertools.IsContainerNotFoundError(err) {
errs = append(errs, err)
}
}
// Remove the sandbox container.
if err := ds.client.RemoveContainer(podSandboxID, dockertypes.ContainerRemoveOptions{RemoveVolumes: true}); err != nil && !dockertools.IsContainerNotFoundError(err) {
errs = append(errs, err)
}
// Remove the checkpoint of the sandbox.
if err := ds.checkpointHandler.RemoveCheckpoint(podSandboxID); err != nil {
errs = append(errs, err)
}
return utilerrors.NewAggregate(errs)
// TODO: remove all containers in the sandbox.
}
// getIPFromPlugin interrogates the network plugin for an IP.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment