Skip to content

fix(compose): honor deploy.restart_policy condition on-failure - #5331

Open
lbarrosby wants to merge 1 commit into
containerd:mainfrom
lbarrosby:fix/compose-deploy-restart-on-failure
Open

lbarrosby wants to merge 1 commit into
containerd:mainfrom
lbarrosby:fix/compose-deploy-restart-on-failure

Conversation

@lbarrosby

Copy link
Copy Markdown

A compose service with

deploy:
  restart_policy:
    condition: on-failure
    max_attempts: 5

was logged as deploy.restart_policy.condition="on-failure" (unimplemented) and the container was created with the default --restart=no, so it was never restarted after a failure. nerdctl run already supports --restart=on-failure[:N], so there is nothing missing on the runtime side.

This maps the condition to --restart=on-failure, or --restart=on-failure:N when max_attempts is set, which is what docker compose does. max_attempts only makes sense with on-failure, so for the other conditions it is ignored with a warning (as it was before, through the unknown-field warning).

Testing: added TestParseDeployRestartPolicy in pkg/composer/serviceparser. It fails on main (--restart=on-failure is not in the run args) and passes with this change; the rest of the package tests pass too.

AI disclosure: written with the help of Claude Code, reviewed and tested by me.

A service with deploy.restart_policy.condition set to on-failure was
logged as unimplemented and the container was created with the default
--restart=no, so it was never restarted after a failure, even though
nerdctl run supports --restart=on-failure[:N].

Map the condition to --restart=on-failure, and to on-failure:N when
max_attempts is set, matching what docker compose does. max_attempts
is only meaningful with on-failure, so warn and ignore it for the
other conditions.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
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.

1 participant