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.
if volume is external you should just never enter this func
There was a problem hiding this comment.
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.
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.
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.
I applied both solutions to this PR
There was a problem hiding this comment.
sure, I mean it could be simpler to review if we split this effort into two separate PRs
fb72af3 to
2823c25
Compare
| 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.
we can rename it :P
There was a problem hiding this comment.
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.
how about update-volumes?
There was a problem hiding this comment.
@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.
it is, as we only recreate diverged volumes. Not all volumes (and not anonymous ones)
There was a problem hiding this comment.
@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.
Or do you prefer to make this the default behaviour with a prompt?
c430b99 to
0b886e9
Compare
ndeloof
left a comment
There was a problem hiding this comment.
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?
| 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.
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.
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.
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
volumeschangesRelated issue
(not mandatory) A picture of a cute animal, if possible in relation to what you did
