Skip to content

pkg/containerutil: update restart.StatusLabel to Stopped when stopping container - #5156

Open
VedantMadane wants to merge 2 commits into
containerd:mainfrom
VedantMadane:fix-5153-stop-restart-always-status
Open

pkg/containerutil: update restart.StatusLabel to Stopped when stopping container#5156
VedantMadane wants to merge 2 commits into
containerd:mainfrom
VedantMadane:fix-5153-stop-restart-always-status

Conversation

@VedantMadane

Copy link
Copy Markdown
Contributor

Description

Fixes #5153.

When running a container with --restart=always\ or --restart=unless-stopped, containerd's restart monitor daemon uses the \containerd.io/restart.status\ label to determine whether an exited container should be automatically restarted (when the label value is
unning).

Previously, while \containerutil.Start\ updated the
estart.StatusLabel\ to \containerd.Running\ on startup, \containerutil.Stop\ and \pkg/cmd/container.killContainer\ only updated \containerd.io/restart.explicitly-stopped\ without transitioning \containerd.io/restart.status\ to \containerd.Stopped. This caused containerd's restart monitor to still observe the status as
unning\ and restart the container after an explicit
erdctl stop\ or
erdctl kill.

This PR ensures \containerutil.Stop\ and \killContainer\ update
estart.StatusLabel\ to \containerd.Stopped\ when a container with a restart policy is stopped or killed, aligning with Docker and containerd restart behavior.

Checklist

  • Signed-off with Developer Certificate of Origin (DCO)
  • Passes local validation and tests

…g container (containerd#5153)

When a container with a restart policy (such as --restart=always) is explicitly stopped or killed via nerdctl stop / nerdctl kill, update the containerd.io/restart.status label to containerd.Stopped so that containerd's restart monitor does not automatically restart the explicitly stopped container.

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
@AkihiroSuda

Copy link
Copy Markdown
Member

Can we have an integration test?

…ll (containerd#5153)

Add TestRunRestartAlwaysStop and TestRunRestartAlwaysKill to verify that containers created with --restart=always transition containerd.io/restart.status to stopped and remain exited after being stopped or killed.

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
@VedantMadane

Copy link
Copy Markdown
Contributor Author

Added integration tests in \cmd/nerdctl/container/container_run_restart_linux_test.go\ (\TestRunRestartAlwaysStop\ and \TestRunRestartAlwaysKill) to verify that containers created with --restart=always\ transition \containerd.io/restart.status\ to \stopped\ and remain in \exited\ status when explicitly stopped or killed.

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.

incorrect restart=always restart logic

2 participants