-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -714,3 +714,17 @@ 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, I will use the same function in both places. |
||
logrus.Debugf("Checking if container %s should restart", c.ID()) | ||
if !c.batched { | ||
c.lock.Lock() | ||
defer c.lock.Unlock() | ||
|
||
if err := c.syncContainer(); err != nil { | ||
return false | ||
} | ||
} | ||
return c.shouldRestart() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the bindings proved to fail testing. So I added them back. |
||
conn, err := bindings.GetClient(ctx) | ||
if err != nil { | ||
return false, err | ||
} | ||
response, err := conn.DoRequest(nil, http.MethodPost, "/containers/%s/shouldrestart", nil, nil, nameOrID) | ||
if err != nil { | ||
return false, err | ||
} | ||
return response.IsSuccess(), nil | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 asRestartPolicyOnFailure
.The same for
no
it should beRestartPolicyNo
.podman/libpod/container.go
Line 99 in dc58d4e
There was a problem hiding this comment.
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?