Skip to content

fix: return removal failures from rm -f - #5289

Open
sarankumar1325 wants to merge 1 commit into
containerd:mainfrom
sarankumar1325:fix-rm-force-exit-status
Open

sarankumar1325 wants to merge 1 commit into
containerd:mainfrom
sarankumar1325:fix-rm-force-exit-status

Conversation

@sarankumar1325

Copy link
Copy Markdown

Fixes #5288

nerdctl rm -f logged every error from the container walker and then returned nil, so a container whose task deletion really failed was left in place while the command exited 0.

This change keeps rm -f idempotent for names or IDs that match no container (still logged, exit 0, same as before), but returns any real removal failure, so the exit status reflects it. Without -f, behaviour is unchanged.

The walk loop moves into a small removeAll helper that takes the walk function as a parameter, so the force and non-force paths can be unit tested without a containerd daemon.

Testing

  • go test ./pkg/cmd/container/ (new TestRemoveAll covers found, missing and failing requests, with and without force)
  • go vet ./pkg/cmd/container/, golangci-lint run ./pkg/cmd/container/..., go build ./cmd/nerdctl
  • I didn't run the integration suite locally because it needs a containerd host.

AI disclosure: I used an AI coding assistant to help with this change (noted with an Assisted-by trailer). I reviewed the change and the tests myself.

`nerdctl rm -f` logged every error from the container walker and exited 0,
so a container whose task deletion failed was left behind while the
command reported success.

In force mode, only ignore requests that match no container, which keeps
`rm -f` idempotent, and return any real removal failure.

Fixes containerd#5288

Assisted-by: Grok Bot
Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@AkihiroSuda

Copy link
Copy Markdown
Member

I didn't run the integration suite locally because it needs a containerd host.

So why not run containerd?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nerdctl rm -f exits 0 when task deletion fails, so callers cannot detect a failed removal

2 participants