Skip to content
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

Error if "until" filter is combined with "--volumes" on system prune #311

Merged
merged 1 commit into from
Jul 22, 2017

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Jul 8, 2017

fixes #310
relates to moby/moby#31122 (comment)

The "until" filter is supported by all object types, except for
volumes.

Before this patch, the "until" filter would attempted to be used for the volume
prune endpoint, resulting in an error being returned by the daemon, and
further prune endpoints (networks, images) to be skipped.

$ docker system prune --filter until=24h --filter label=label.foo=bar

WARNING! This will remove:
        - all stopped containers
        - all volumes not used by at least one container
        - all networks not used by at least one container
        - all dangling images
Are you sure you want to continue? [y/N] y
Error response from daemon: Invalid filter 'until'
Calling POST /v1.30/containers/prune?filters=%7B%22label%22%3A%7B%22label.foo%3D%3Dbar%22%3Atrue%7D%2C%22until%22%3A%7B%2224h%22%3Atrue%7D%7D
Calling POST /v1.30/volumes/prune?filters=%7B%22label%22%3A%7B%22label.foo%3D%3Dbar%22%3Atrue%7D%2C%22until%22%3A%7B%2224h%22%3Atrue%7D%7D
Handler for POST /v1.30/volumes/prune returned error: Invalid filter 'until'
Error response from daemon: Invalid filter 'until'

With this patch, an error is produced instead, preventing "partial" prune.

$ docker system prune --filter until=24h --filter label=foo==bar --volumes
ERROR: The "until" filter is not supported with "--volumes"

Note that docker volume prune does not have this problem, and produces an
error if the until filter is used;

$ docker volume prune --filter until=24h

WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Error response from daemon: Invalid filter 'until'

@thaJeztah
Copy link
Member Author

ping @cpuguy83 ptal

// TODO make `opts.FilterOpt` more flexible to prevent awkward hacks like this
// TODO version this hack once "until" filter is supported for volumes
vf := opts.NewFilterOpt()
if filter.Value().Include("label") {
Copy link
Member Author

Choose a reason for hiding this comment

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

If anyone has suggestions for doing this in a cleaner way, let me know

I didn't want to update the package upstream (moby/moby) to keep the diff small

@cpuguy83
Copy link
Collaborator

We could keep the list of supported filters in the API spec.

@codecov-io
Copy link

codecov-io commented Jul 10, 2017

Codecov Report

Merging #311 into master will decrease coverage by <.01%.
The diff coverage is 25%.

@@            Coverage Diff             @@
##           master     #311      +/-   ##
==========================================
- Coverage   46.15%   46.14%   -0.01%     
==========================================
  Files         193      193              
  Lines       16069    16073       +4     
==========================================
+ Hits         7416     7417       +1     
- Misses       8267     8269       +2     
- Partials      386      387       +1

@dnephin
Copy link
Contributor

dnephin commented Jul 11, 2017

This seems strange to me. What would be the use case for removing other things older than x, but removing all volumes? I can't think of when that would ever be useful.

Generally I don't think that system prune should support filters. The only use case I see for system prune is to remove everything. If you want to remove things with more fine grained control use docker x prune with the correct filters. Applying the same filters to a bunch of different resources types makes very little sense to me. Resources have very different lifecycles in most cases.

I think the correct fix here is to remove filters from system prune entirely.

@thaJeztah
Copy link
Member Author

It's been there since 17.04 moby/moby#29226, so if we want to remove it, it should go through a deprecation cycle

I do see value when using filtering by label (i.e. being able to prune everything, and exclude resources labeled with x.y.z), but can understand your thinking on 'until' for these.

For this PR; it's not adding a feature but fixing a bug

The "until" filter is supported by all object types, except for
volumes.

Before this patch, the "until" filter would attempted to be used for the volume
prune endpoint, resulting in an error being returned by the daemon, and
further prune endpoints (networks, images) to be skipped.

    $ docker system prune --filter until=24h --filter label=label.foo=bar

    WARNING! This will remove:
            - all stopped containers
            - all volumes not used by at least one container
            - all networks not used by at least one container
            - all dangling images
    Are you sure you want to continue? [y/N] y
    Error response from daemon: Invalid filter 'until'

    Calling POST /v1.30/containers/prune?filters=%7B%22label%22%3A%7B%22label.foo%3D%3Dbar%22%3Atrue%7D%2C%22until%22%3A%7B%2224h%22%3Atrue%7D%7D
    Calling POST /v1.30/volumes/prune?filters=%7B%22label%22%3A%7B%22label.foo%3D%3Dbar%22%3Atrue%7D%2C%22until%22%3A%7B%2224h%22%3Atrue%7D%7D
    Handler for POST /v1.30/volumes/prune returned error: Invalid filter 'until'
    Error response from daemon: Invalid filter 'until'

With this patch, an error is produced instead, preventing "partial" prune.

    $ docker system prune --filter until=24h --filter label=foo==bar --volumes
    ERROR: The "until" filter is not supported with "--volumes"

Note that `docker volume prune` does not have this problem, and produces an
error if the `until` filter is used;

    $ docker volume prune --filter until=24h

    WARNING! This will remove all volumes not used by at least one container.
    Are you sure you want to continue? [y/N] y
    Error response from daemon: Invalid filter 'until'

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah changed the title Fix system prune failing when using "until" filter Error if "until" filter is combined with "--volumes" on system prune Jul 21, 2017
@thaJeztah
Copy link
Member Author

Updated; I decided to simplify this PR, and instead error out if --filter until=... is combined with --volumes.

ping @dnephin @vdemeester PTAL

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

I think this is a good fix.

@vieux
Copy link
Contributor

vieux commented Jul 21, 2017

LGTM

@thaJeztah
Copy link
Member Author

I'll merge, but happy to do a follow-up if we want this tested

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.

system prune fails if "until" filter is used
6 participants