-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Recreate on volume change #12223
base: main
Are you sure you want to change the base?
Recreate on volume change #12223
Conversation
IMHO the right way to address this issue is for volumes/networks to have a config-hash label just like services, so we detect those need to be recreated, and then in cascade we re-create the attached containers |
4032d1b
to
dd57c3d
Compare
pkg/compose/hash.go
Outdated
if o.Driver == "" { // (TODO: jhrotko) This probably should be fixed in compose-go | ||
o.Driver = "local" | ||
} | ||
o.External = false // the name can change. Need to think about this case |
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.
if volume is external you should just never enter this func
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.
there is an edge case where you can change the name
of an external volume and we need to update the service. The current code does not comtemplate this case. I need to implement this
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.
by nature, external resources are not managed by compose. There's nothing we can and should do to cover this scenario
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.
I better understand your point, the issue you refer to is a special case for a feature we don't support (yet): recreate services when referred resource is reconfigured. I agree we could kill 2 birds with one stone here, but this makes many changes at once.
Maybe split this into 2 separate PRs ?
- 1 to recreate volumes on config changes
- 1 to detect named resource changed (ensureService to inspect mounted volumes for container and check name matches expectation)
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.
I applied both solutions to this PR
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.
sure, I mean it could be simpler to review if we split this effort into two separate PRs
fb72af3
to
2823c25
Compare
@@ -148,6 +148,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c | |||
flags.BoolVar(&create.noBuild, "no-build", false, "Don't build an image, even if it's policy") | |||
flags.StringVar(&create.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`) | |||
flags.BoolVar(&create.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file") | |||
flags.BoolVar(&create.recreateVolumes, "recreate-volumes", false, "Recreate volumes when volume configuration in the Compose file changes.") |
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.
we can rename it :P
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.
I also wonder this could be ambiguous, considering we have --renew-anon-volumes
. Need to noun that make it clear we recreate volumes when config has diverged
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.
how about update-volumes
?
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.
@ndeloof the recreate-volumes
makes somewhat sense to me, also given the 'pattern' for force-recreate
flag. I don't think it is ambiguous with the flag --renew-anon-volumes
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, as we only recreate diverged volumes. Not all volumes (and not anonymous ones)
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.
@ndeloof I can add that at the flag description: that this will ignore anonymous volumes. As for the names maybe? If you have any other ideas please feel free to suggest
--recreate-volumes-if-changed
--force-recreate-volumes
--sync-volumes
--update-volumes
--refresh-named-volumes
--rebuild-volumes
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.
Or do you prefer to make this the default behaviour with a prompt?
c430b99
to
0b886e9
Compare
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.
ensureService doesn't need to be updated for this feature AFAICT, as we remove containers mounting a volume before we recreate volume, so ensureService
will start from scratch - possibly just requires observedState
to be updated after Remove
?
@@ -148,6 +148,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c | |||
flags.BoolVar(&create.noBuild, "no-build", false, "Don't build an image, even if it's policy") | |||
flags.StringVar(&create.Pull, "pull", "policy", `Pull image before running ("always"|"missing"|"never")`) | |||
flags.BoolVar(&create.removeOrphans, "remove-orphans", false, "Remove containers for services not defined in the Compose file") | |||
flags.BoolVar(&create.recreateVolumes, "recreate-volumes", false, "Recreate volumes when volume configuration in the Compose file changes.") |
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.
I also wonder this could be ambiguous, considering we have --renew-anon-volumes
. Need to noun that make it clear we recreate volumes when config has diverged
0b886e9
to
f9a8185
Compare
52a5d2e
to
e83964b
Compare
if !shouldRecreateVolume { | ||
continue | ||
} | ||
if !recreateVolumes && shouldRecreateVolume { |
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.
we could rely on user interaction to confirm recreation, the way we do on https://github.com/docker/compose/blob/main/pkg/compose/remove.go#L88
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.
looks really nice, but I will defer it for a follow-up PR
e83964b
to
b80222b
Compare
Signed-off-by: Joana Hrotko <[email protected]>
b80222b
to
43d3b27
Compare
What I did
Add volumes on configuration hash in order to recreate container when
volumes
changesRelated issue
(not mandatory) A picture of a cute animal, if possible in relation to what you did