Skip to content

Conversation

cpuguy83
Copy link
Member

@cpuguy83 cpuguy83 commented Sep 28, 2022

This adds a new filter argument to the volume prune endpoint "all". When this is not set, or it is a false-y value, then only anonymous volumes are considered for pruning.

When all is set to a truth-y value, you get the old behavior.

This is an API change, but I think one that is what most people would want.

Copy link
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This finally makes volume pruning consistent with all our other prune experiences! LGTM 😍

@cpuguy83 cpuguy83 force-pushed the volume_unnamed_label branch 2 times, most recently from 3a6e782 to 2312731 Compare September 28, 2022 20:24
@neersighted neersighted added area/api kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. impact/changelog area/volumes labels Sep 29, 2022
@neersighted neersighted added this to the v-next milestone Sep 29, 2022
@cpuguy83 cpuguy83 force-pushed the volume_unnamed_label branch 2 times, most recently from 1ddbd45 to 7fdf167 Compare September 29, 2022 18:30
@cpuguy83 cpuguy83 force-pushed the volume_unnamed_label branch from 7fdf167 to 5ed9600 Compare September 29, 2022 20:18
@cpuguy83
Copy link
Member Author

Updated this as discussed to make sure older API versions keep the old behavior.

@thaJeztah
Copy link
Member

thaJeztah commented Oct 3, 2022

Looks like we need to skip one of the docker-py tests and/or fix in upstream. Haven't checked yet what the test does, and if it's incorrect.

That said; if it's using API v1.41, it probably should've passed 🤔

=================================== FAILURES ===================================
________________________ TestVolumes.test_prune_volumes ________________________
tests/integration/api_volume_test.py:64: in test_prune_volumes
    assert name in result['VolumesDeleted']
E   AssertionError: assert 'hopelessmasquerade' in []
------- generated xml file: /src/bundles/test-docker-py/junit-report.xml -------
=========================== short test summary info ============================

Test is https://github.com/docker/docker-py/blob/5.0.3/tests/integration/api_volume_test.py#L58-L64

(we also need to update docker-py to a newer version, to un-skip some tests that were fixed)

edit: LOL, and of course I already had a PR in draft; #43998

@neersighted
Copy link
Member

The test looks quite straightforward in the current main, but I'm not sure what version is in use here.

https://github.com/docker/docker-py/blob/923e067dddc3d4b86e4e620a99fcdcdafbd17a98/tests/integration/api_volume_test.py#L58-L64

If this is actually what is failing here, I think the bug is in this PR; however I haven't dug in any further.

cpuguy83 added a commit to cpuguy83/docker-py that referenced this pull request Oct 3, 2022
This is related to moby/moby#44216
Prunes will, by default, no longer prune named volumes, only anonymous ones.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@thaJeztah
Copy link
Member

I see brian is already testing a change in that code. Perhaps the docker-py tests don't specify an API version, in which case they could be using "latest" (not a fixed version).

I also dusted off #43998, which shows how tests can be skipped temporarily (we probably can do so if we know why it's failing)

@cpuguy83
Copy link
Member Author

cpuguy83 commented Oct 3, 2022

It seems like it should be using 1.41 (it's what's in the docker-py makefile).
Looking into it.

@cpuguy83
Copy link
Member Author

cpuguy83 commented Oct 3, 2022

The daemon logs from the docker-py run shows it is using API v1.43

https://github.com/moby/moby/actions/runs/3154324955/jobs/5131882252#step:8:17308

@cpuguy83
Copy link
Member Author

cpuguy83 commented Oct 3, 2022

Ah, that's because we are running pytest directly.

@thaJeztah
Copy link
Member

I see it's calling /version before various tests; is it using that to find the version to use? (and not negotiation based on the version it supports?)

cpuguy83 added a commit to cpuguy83/docker-py that referenced this pull request Oct 3, 2022
This is related to moby/moby#44216
Prunes will, by default, no longer prune named volumes, only anonymous ones.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@thaJeztah
Copy link
Member

As isn't merged yet, and it looks like needs some work, perhaps you can update PY_TEST_OPTIONS

: "${PY_TEST_OPTIONS:=--junitxml=${DEST}/junit-report.xml --deselect=tests/integration/api_container_test.py::AttachContainerTest::test_attach_no_stream --deselect=tests/integration/api_container_test.py::CreateContainerTest::test_create_with_device_cgroup_rules}"

# TODO re-enable test_attach_no_stream after https://github.com/docker/docker-py/issues/2513 is resolved
# TODO re-enable test_create_with_device_cgroup_rules after https://github.com/docker/docker-py/issues/2939 is resolved
# TODO re-enable test_prune_volumes after https://github.com/docker/docker-py/pull/3051 is resolved
: "${PY_TEST_OPTIONS:=--junitxml=${DEST}/junit-report.xml --deselect=tests/integration/api_container_test.py::AttachContainerTest::test_attach_no_stream --deselect=tests/integration/api_container_test.py::CreateContainerTest::test_create_with_device_cgroup_rules --deselect=tests/integration/api_volume_test.py::TestVolumes::test_prune_volumes}"

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two comments; I have the changes locally, so let me open a quick PR against your branch

@@ -9700,6 +9700,7 @@ paths:

Available filters:
- `label` (`label=<key>`, `label=<key>=<value>`, `label!=<key>`, or `label!=<key>=<value>`) Prune volumes with (or without, in case `label!=...` is used) the specified labels.
- `all` (`all=true`) - Consider all (local) volumes for pruning and not just anonymous volumes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this PR was implemented to be included in API v1.42 (22.06); could you apply this change to the docs/api/v1.42.yaml file as well?

@thaJeztah
Copy link
Member

opened cpuguy83#5 <-- PTAL @cpuguy83

@cpuguy83 cpuguy83 force-pushed the volume_unnamed_label branch from 97c4744 to 07f46f6 Compare October 4, 2022 18:35
This adds a new filter argument to the volume prune endpoint "all".
When this is not set, or it is a false-y value, then only anonymous
volumes are considered for pruning.

When `all` is set to a truth-y value, you get the old behavior.

This is an API change, but I think one that is what most people would
want.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@cpuguy83 cpuguy83 force-pushed the volume_unnamed_label branch from 07f46f6 to 618f26c Compare October 4, 2022 20:55
@cpuguy83
Copy link
Member Author

cpuguy83 commented Oct 5, 2022

All green

@@ -60,18 +60,23 @@ func (s *VolumesService) GetDriverList() []string {
return s.ds.GetDriverList()
}

// AnonymousLabel is the label used to indicate that a volume is anonymous
// This is set automatically on a volume when a volume is created without a name specified, and as such an id is generated for it.
const AnonymousLabel = "com.docker.volume.anonymous"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I wonder; will this have an effect on volumes that "started as anonymous", but later on became "named"?

Thinking of situations like

docker run -d --name container1 some-image-with-volumes

docker run --volumes-from=container2 some-image

Yes, the volume is still "anonymous", but no longer really "ephemeral"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The volume is still anonymous, but if a container is holding a reference to it, it won't be pruned anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit 49940ab into moby:master Oct 5, 2022
milas pushed a commit to docker/docker-py that referenced this pull request Oct 5, 2022
This is related to moby/moby#44216

Prunes will, by default, no longer prune named volumes, only anonymous ones.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@cpuguy83 cpuguy83 deleted the volume_unnamed_label branch October 5, 2022 18:23
DeliciousHouse added a commit to DeliciousHouse/docker-py that referenced this pull request Oct 20, 2022
This is related to moby/moby#44216

Prunes will, by default, no longer prune named volumes, only anonymous ones.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api area/volumes impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. process/cherry-picked status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider not to delete named volumes by default when running system prune
4 participants