Skip to content

fix: allow removing containers without network annotations - #5211

Merged
AkihiroSuda merged 1 commit into
containerd:mainfrom
Arman16-1998:fix/cri-rm-missing-network-annotations
Sep 17, 2026
Merged

AkihiroSuda merged 1 commit into
containerd:mainfrom
Arman16-1998:fix/cri-rm-missing-network-annotations

Conversation

@Arman16-1998

Copy link
Copy Markdown

Fixes #5207

Removing stopped CRI-created containers could fail when their OCI spec did not contain the nerdctl/networks annotation.

NetworkOptionsFromSpec errors are now treated as non-fatal during removal, preserving the previous behavior while keeping port mapping cleanup for containers with valid nerdctl network metadata.

A regression test was added to verify that a container can still be removed after the network annotation is absent.

@Arman16-1998
Arman16-1998 force-pushed the fix/cri-rm-missing-network-annotations branch from 802006b to 7dcd9c6 Compare September 16, 2026 07:27
testCase.Run(t)
}

func TestRemoveContainerWithoutNetworkAnnotation(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use an actual Kubernetes cluster for testing

func TestKubeCommitSave(t *testing.T) {
testCase := nerdtest.Setup()
testCase.Require = nerdtest.OnlyKubernetes
testCase.Setup = func(data test.Data, helpers test.Helpers) {
identifier := data.Identifier()
containerID := ""
// NOTE: kubectl namespaces are not the same as containerd namespaces.
// We still want kube test objects segregated in their own Kube API namespace.
nerdtest.KubeCtlCommand(helpers, "create", "namespace", "nerdctl-test-k8s").Run(&test.Expected{})
nerdtest.KubeCtlCommand(helpers, "run", "--image", testutil.CommonImage, identifier, "--", "sleep", nerdtest.Infinity).Run(&test.Expected{})
nerdtest.KubeCtlCommand(helpers, "wait", "pod", identifier, "--for=condition=ready", "--timeout=1m").Run(&test.Expected{})
nerdtest.KubeCtlCommand(helpers, "exec", identifier, "--", "mkdir", "-p", "/tmp/whatever").Run(&test.Expected{})
nerdtest.KubeCtlCommand(helpers, "get", "pods", identifier, "-o", "jsonpath={ .status.containerStatuses[0].containerID }").Run(&test.Expected{
Output: func(stdout string, t tig.T) {
containerID = strings.TrimPrefix(stdout, "containerd://")
},
})
data.Labels().Set("containerID", containerID)
}
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
nerdtest.KubeCtlCommand(helpers, "delete", "pod", "--all").Run(nil)
}

testCase.Run(t)
}

func TestRemoveContainerWithoutNetworkAnnotation(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test needs comment lines to explain the context

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please squash the commits

Signed-off-by: Arman Balian <arman.blain16@gmail.com>
@Arman16-1998
Arman16-1998 force-pushed the fix/cri-rm-missing-network-annotations branch from 130e5bf to 8acf877 Compare September 16, 2026 11:56
@Arman16-1998

Arman16-1998 commented Sep 16, 2026 •

Copy link
Copy Markdown
Author

@AkihiroSuda Updated the regression test to use a Kubernetes-created CRI container, added context comments, isolated the test namespace, and squashed the commits. CI has been rerun.

@AkihiroSuda AkihiroSuda added this to the v2.4.0 milestone Sep 16, 2026

@AkihiroSuda AkihiroSuda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda
AkihiroSuda merged commit 33bd720 into containerd:main Sep 17, 2026
66 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression since v2.1.3: removing CRI containers fails on missing network annotations

2 participants