Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow containers to --restart on-failure with --rm #8263

Merged
merged 1 commit into from
Nov 23, 2020

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Nov 6, 2020

Fixes: #7906

Signed-off-by: Daniel J Walsh [email protected]

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 6, 2020
@rhatdan rhatdan force-pushed the restart branch 2 times, most recently from 2eed98d to 7fa9206 Compare November 6, 2020 15:31
@rhatdan rhatdan changed the title Allow containers to restart-on-failure with --rm-s Allow containers to --restart on-failure with --rm Nov 6, 2020
@@ -714,3 +714,39 @@ func (c *Container) Restore(ctx context.Context, options ContainerCheckpointOpti
defer c.newContainerEvent(events.Restore)
return c.restore(ctx, options)
}

// Indicate whether or not the container should restart
func (c *Container) ShouldRestart(ctx context.Context) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Did you duplicate all of this logic? It looks like it was copied from container_internal

Copy link
Member Author

Choose a reason for hiding this comment

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

It is, I will use the same function in both places.

@@ -9,7 +9,7 @@ import (
// by validate must not need any state information on the flag (i.e. changed)
func (c *ContainerCLIOpts) validate() error {
var ()
if c.Rm && c.Restart != "" && c.Restart != "no" {
if c.Rm && (c.Restart != "" && c.Restart != "no" && c.Restart != "on-failure") {
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to have "on-failure" defined in a variable somewhere rather than a bare string scattered about. Not for this pr though.

Copy link
Member

Choose a reason for hiding this comment

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

It is defined in the libpod package as RestartPolicyOnFailure.
The same for no it should be RestartPolicyNo.

RestartPolicyOnFailure = "on-failure"

Copy link
Member

Choose a reason for hiding this comment

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

@rhatdan are you going to change per @Luap99 's suggestion?

@rhatdan rhatdan force-pushed the restart branch 4 times, most recently from 2f8e18f to f87b474 Compare November 12, 2020 15:22
@rhatdan
Copy link
Member Author

rhatdan commented Nov 12, 2020

@containers/podman-maintainers PTAL

@baude
Copy link
Member

baude commented Nov 12, 2020

lgtm

Copy link
Contributor

@QiWang19 QiWang19 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -390,3 +390,15 @@ func ContainerInit(ctx context.Context, nameOrID string) error {
}
return response.Process(nil)
}

func ShouldRestart(ctx context.Context, nameOrID string) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this in the API and Bindings? This should be local-only, podman container cleanup should never be invoked remotely

Copy link
Member Author

Choose a reason for hiding this comment

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

In pkg/domain/infra/tunnel/containers.go when we do a non detached container, we Remove the container when it completes. Added this ShouldRestart check to make sure that this does not happen.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if it's worth adding a complete new API endpoint to handle this. Maybe we should just disable removing the container in that case if it detects that the container has this restart policy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Then we end up with the race conditions again. But for only a small subset of calls.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the bindings and just stopped rm the container in run if the restart policy is set to something other then no.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing the bindings proved to fail testing. So I added them back.

@TomSweeneyRedHat
Copy link
Member

Tests aren't hip.

@rhatdan rhatdan added the lgtm Indicates that a PR is ready to be merged. label Nov 23, 2020
@openshift-merge-robot openshift-merge-robot merged commit dd34341 into containers:master Nov 23, 2020
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More flexible options when combining '--rm' and '--restart'
8 participants