-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
prune commands : make sure label filters are considered #21
Conversation
cli/command/utils.go
Outdated
@@ -115,5 +117,23 @@ func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args { | |||
pruneFilters.Add(parts[0], parts[1]) | |||
} | |||
|
|||
// Server APIs older than 1.29 will just ignore label filters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we should do that server side though (the cli
should be as dumb as possible)
cc @thaJeztah @dnephin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be more correct, but the problem is that the issue is with old servers, so it's hard to fix now.
The server should actually already error with it receives invalid filters. I'm not sure why it isn't.
We already do something like this on the client to hide flags based on version. This is just a little more fine grained. If we do need this we should find a way to do that is easily extend as more fields are added to labels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vdemeester @dnephin is right. This client-side fix fixes it for older daemons. I have a moby/moby PR that is almost ready, fixing it server side (returning error for unknown prune filters).
It is gonna be part of 17.06 as 17.05 is about to get released, and we still have to design and discuss a part of this server-side fix. I am having troubles with docker system prune --filter ...
as the CLI, for system prune
, calls container prune
, volume prune
, image prune
and network prune
passing the same filters to all of them... so my to-be PR is currently braking because of this.
Thanks for reading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gdevillele yep, I did mis-understand the fix at first 😅.
We might (or should have) validates filters by version (for any api endpoint that supports them) in docker
/moby
😓
cli/command/utils.go
Outdated
@@ -2,6 +2,7 @@ package command | |||
|
|||
import ( | |||
"bufio" | |||
"context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are still using golang.org/x/net/context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on if we support go 1.6 for docker/cli
or not, it's no big deal in the usage of it (as the interface is the same)
cli/command/utils.go
Outdated
// would just remove all stopped containers without considering the label | ||
// The remote API should reject requests using unknown filters. | ||
if pruneFilters.Get("label") != nil { | ||
serverVersion, err := dockerCli.Client().ServerVersion(context.Background()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API version should already be available as dockerCli.Client().ClientVersion()
which is set by querying the server API version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ClientVersion returns the version string associated with this instance of the Client
Are you sure? What's important is to detect the version server side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup,
Lines 200 to 203 in 0a61397
// if server version is lower than the current cli, downgrade | |
if versions.LessThan(ping.APIVersion, cli.client.ClientVersion()) { | |
cli.client.UpdateClientVersion(ping.APIVersion) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnephin oh! good to know! thanks, I'll update this part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Do we still want this change? Daemon side validation was added in moby/moby#33023. "label" filtering was added in docker 17.05 through moby/moby#30740 (which is an edge release, so not supported after 17.06 is released), and the |
That happens to me sometimes, I still have a few older daemons here and there... I guess it won't happen very often, and I would be ok to drop this if the command was not |
Actually (we were discussing on slack); it looks like the Hold on, I'll add an example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left an example (double check, but I think docker 17.04 was API version 1.28)
cli/command/system/prune.go
Outdated
@@ -34,7 +34,7 @@ func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command { | |||
flags := cmd.Flags() | |||
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation") | |||
flags.BoolVarP(&opts.all, "all", "a", false, "Remove all unused images not just dangling ones") | |||
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')") | |||
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'label=<key>=<value>')") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have an annotation (like in cli/command/stack/deploy.go#L46)
flags.SetAnnotation("filter", "version", []string{"1.28"})
Same for the other prune --filter
flags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! I did't know about this!
I'll update the PR then, it's much simpler this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also see see moby/moby#30187 and moby/moby#30186 for some more info about that :)
ping @aduermael looks like this needs a rebase (also can you address my comment, so that we can get this in for 17.06?) |
dfa4003
to
86d9eac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes LGTM; can you squash the commits?
…i v1.28) and newer Signed-off-by: Gaetan de Villele <gdevillele@gmail.com>
86d9eac
to
1cc1f54
Compare
LGTM |
Fixes #17
Related to moby/moby#33023
Checking server API version is at least 1.29 to accept prune commands with label filters.
Signed-off-by: Adrien Duermael adrien@duermael.com