Skip to content

[27.x backport] volume/mounts: fix anonymous volume not being labeled#48755

Merged
thaJeztah merged 1 commit intomoby:27.xfrom
thaJeztah:27.x_backport_fix_anonymous_volumes_labels
Oct 25, 2024
Merged

[27.x backport] volume/mounts: fix anonymous volume not being labeled#48755
thaJeztah merged 1 commit intomoby:27.xfrom
thaJeztah:27.x_backport_fix_anonymous_volumes_labels

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

volume/mounts: fix anonymous volume not being labeled

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

- How to verify it

make TEST_FILTER='TestContainerVolumeAnonymous' TEST_SKIP_INTEGRATION_CLI=1 DOCKER_GRAPHDRIVER=vfs test-integration

=== RUN   TestContainerVolumeAnonymous
--- PASS: TestContainerVolumeAnonymous (0.02s)
PASS

DONE 1 tests in 1.225s

- Description for the changelog

Fix anonymous volumes being created through the `--mount` option not being marked as anonymous.

- A picture of a cute animal (not mandatory but encouraged)

`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]>
(cherry picked from commit 10d57fd)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah added this to the 27.4.0 milestone Oct 25, 2024
@thaJeztah thaJeztah self-assigned this Oct 25, 2024
@thaJeztah thaJeztah marked this pull request as ready for review October 25, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants