volume/mounts: fix anonymous volume not being labeled#48754
volume/mounts: fix anonymous volume not being labeled#48754thaJeztah merged 1 commit intomoby:masterfrom
Conversation
`Parser.ParseMountRaw()` labels anonymous volumes with a `AnonymousLabel` label (`com.docker.volume.anonymous`) label based on whether a volume has a name (named volume) or no name (anonymous) (see [1]). However both `VolumesService.Create()` (see [1]) and `Parser.ParseMountRaw()` (see [2], [3]) were generating a random name for anonymous volumes. The latter is called before `VolumesService.Create()` is called, resulting in such volumes not being labeled as anonymous. Generating the name was originally done in Create (fc7b904), but duplicated in b3b7eb2 with the introduction of the new Mounts field in HostConfig. Duplicating this effort didn't have a real effect until (`Create` would just skip generating the name), until 618f26c introduced the `AnonymousLabel` in (v24.0.0, backported to v23.0.0). Parsing generally should not fill in defaults / generate names, so this patch; - Removes generating volume names from `Parser.ParseMountRaw()` - Adds a debug-log entry to `VolumesService.Create()` - Touches up some logs to use structured logs for easier correlating logs With this patch applied: docker run --rm --mount=type=volume,target=/toto hello-world DEBU[2024-10-24T22:50:36.359990376Z] creating anonymous volume volume-name=0cfd63d4df363571e7b3e9c04e37c74054cc16ff1d00d9a005232d83e92eda02 DEBU[2024-10-24T22:50:36.360069209Z] probing all drivers for volume volume-name=0cfd63d4df363571e7b3e9c04e37c74054cc16ff1d00d9a005232d83e92eda02 DEBU[2024-10-24T22:50:36.360341209Z] Registering new volume reference driver=local volume-name=0cfd63d4df363571e7b3e9c04e37c74054cc16ff1d00d9a005232d83e92eda02 [1]: https://github.com/moby/moby/blob/032721ff75fe4a71a45b4a7a9b7e7c4c80c6431b/volume/service/service.go#L72-L83 [2]: https://github.com/moby/moby/blob/032721ff75fe4a71a45b4a7a9b7e7c4c80c6431b/volume/mounts/linux_parser.go#L330-L336 [3]: https://github.com/moby/moby/blob/032721ff75fe4a71a45b4a7a9b7e7c4c80c6431b/volume/mounts/windows_parser.go#L394-L400 Signed-off-by: Sebastiaan van Stijn <[email protected]>
|
@neersighted this one's for you (docker/compose#10833) 😄 |
Thanks for @ndeloof for finding the discrepancy. I initially thought the problem was here; with Lines 210 to 216 in d3c3a74 And moby/volume/service/service.go Lines 72 to 76 in 032721f Because if they are applied in the reverse order, then moby/volume/service/opts/opts.go Lines 15 to 22 in d3c3a74 moby/volume/service/opts/opts.go Lines 26 to 30 in d3c3a74 |
|
three LGTM's - works for me; thanks! |
| log.G(ctx).WithField("volume-name", name).Error("Creating anonymous volume") | ||
| } else { | ||
| log.G(ctx).WithField("volume-name", name).Error("Creating named volume") |
There was a problem hiding this comment.
Whoops; I left these as Error() log instead of Debug() 🙈
--mountdon't get AnonymousLabel set #48748HostConfigfield,Mounts. #22373volume/mounts: fix anonymous volume not being labeled
Parser.ParseMountRaw()labels anonymous volumes with aAnonymousLabellabel (com.docker.volume.anonymous) label based on whether a volume has a name (named volume) or no name (anonymous) (see 1).However both
VolumesService.Create()(see 1) andParser.ParseMountRaw()(see 2, 3) were generating a random name for anonymous volumes. The latter is called beforeVolumesService.Create()is called, resulting in such volumes not being labeled as anonymous.Generating the name was originally done in Create (fc7b904), but duplicated in b3b7eb2 with the introduction of the new Mounts field in HostConfig. Duplicating this effort didn't have a real effect until (
Createwould just skip generating the name), until 618f26c introduced theAnonymousLabelin (v24.0.0, backported to v23.0.0).Parsing generally should not fill in defaults / generate names, so this patch;
Parser.ParseMountRaw()VolumesService.Create()With this patch applied:
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)