Skip to content

daemon returns errors when receiving unsupported prune filters#33023

Merged
thaJeztah merged 1 commit intomoby:masterfrom
gdevillele:pr-fix-prune-filter
May 16, 2017
Merged

daemon returns errors when receiving unsupported prune filters#33023
thaJeztah merged 1 commit intomoby:masterfrom
gdevillele:pr-fix-prune-filter

Conversation

@gdevillele
Copy link
Contributor

@gdevillele gdevillele commented May 4, 2017

- What I did

  • container prune
  • volume prune
  • image prune
  • network prune

...now return errors if an unsupported filter is received.

container prune only accepts the following filters:

  • label
  • until

volume prune only accepts the following filters:

  • label

image prune only accepts the following filters:

  • dangling
  • label
  • until

network prune only accepts the following filters:

  • label
  • until

- How to verify it

Example:

docker container prune --filter <filter>=<key>=<value>

if is not "label" or "until", you should get a daemon error.

- Description for the changelog

return errors to the client when receiving unsupported prune filters

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

gp-7

cc @thaJeztah @vdemeester

@gdevillele gdevillele changed the title daemon returns error when receiving unsuppo unknown filters in prune functions daemon returns error when receiving unsupported prune filters May 4, 2017
@gdevillele gdevillele changed the title daemon returns error when receiving unsupported prune filters daemon returns errors when receiving unsupported prune filters May 4, 2017
@gdevillele gdevillele force-pushed the pr-fix-prune-filter branch 2 times, most recently from f83ec12 to 7722e4f Compare May 5, 2017 16:36
- container prune
- volume prune
- image prune
- network prune

Signed-off-by: Gaetan de Villele <gdevillele@gmail.com>
@@ -25,6 +25,27 @@ var (
// ErrPruneRunning is returned when a prune request is received while
// one is in progress
ErrPruneRunning = fmt.Errorf("a prune operation is already running")
Copy link
Contributor

Choose a reason for hiding this comment

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

I am also wondering if we could disable the export of error ErrPruneRunning ?
Since it is only used here.
But maybe out of the scope of this PR. 🐱

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.
Might be a candidate for another PR.


containersAcceptedFilters = map[string]bool{
"label": true,
"label!": true,
Copy link
Member

Choose a reason for hiding this comment

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

Should the ! actually be part of the filter name? Not sure how it's handled later on, but looks a bit tricky (i.e. label!=foo.bar would be accepted, but not label != foo.bar, correct?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the later is a valid syntax for filters (e.g. filters="label != foo.bar")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thaJeztah

  • I agree that this is strange, following our discussion, I will open another PR to rewrite this logic.
  • I don't think filters can contain any space, either.

Copy link
Member

@thaJeztah thaJeztah May 16, 2017

Choose a reason for hiding this comment

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

Looked up the PR that implemented it, and indeed the format is label!=key=val or label!=key. Negative matches on value alone don't seem to be supported (i.e., no label=key!=val), nor spaces in between (label != key=val etc.)

moby/cli/command/utils.go

Lines 95 to 116 in 7025247

for _, f := range dockerCli.ConfigFile().PruneFilters {
parts := strings.SplitN(f, "=", 2)
if len(parts) != 2 {
continue
}
if parts[0] == "label" {
// CLI label filter supersede config.json.
// If CLI label filter conflict with config.json,
// skip adding label! filter in config.json.
if pruneFilters.Include("label!") && pruneFilters.ExactMatch("label!", parts[1]) {
continue
}
} else if parts[0] == "label!" {
// CLI label! filter supersede config.json.
// If CLI label! filter conflict with config.json,
// skip adding label filter in config.json.
if pruneFilters.Include("label") && pruneFilters.ExactMatch("label", parts[1]) {
continue
}
}
pruneFilters.Add(parts[0], parts[1])
}

Copy link
Contributor

@mlaventure mlaventure left a comment

Choose a reason for hiding this comment

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

LGTM

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
Copy link
Member

@gdevillele can you open an issue for tracking the changes on the way we match the filters? (perhaps write out which formats we want to support, if we want to support whitespace)

@gdevillele
Copy link
Contributor Author

@thaJeztah will do. Thanks for merging!

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.

6 participants