mirror of https://github.com/docker/cli.git
Add `label` filter for `docker system prune`
This fix tries to address the issue raised in 29999 where it was not possible to mask these items (like important non-removable stuff) from `docker system prune`. This fix adds `label` and `label!` field for `--filter` in `system prune`, so that it is possible to selectively prune items like: ``` $ docker container prune --filter label=foo $ docker container prune --filter label!=bar ``` Additional unit tests and integration tests have been added. This fix fixes 29999. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
4dcceaf70e
commit
c3bfcc372c
|
@ -40,6 +40,11 @@ func TestContainersPrune(t *testing.T) {
|
||||||
danglingUntilFilters.Add("dangling", "true")
|
danglingUntilFilters.Add("dangling", "true")
|
||||||
danglingUntilFilters.Add("until", "2016-12-15T14:00")
|
danglingUntilFilters.Add("until", "2016-12-15T14:00")
|
||||||
|
|
||||||
|
labelFilters := filters.NewArgs()
|
||||||
|
labelFilters.Add("dangling", "true")
|
||||||
|
labelFilters.Add("label", "label1=foo")
|
||||||
|
labelFilters.Add("label", "label2!=bar")
|
||||||
|
|
||||||
listCases := []struct {
|
listCases := []struct {
|
||||||
filters filters.Args
|
filters filters.Args
|
||||||
expectedQueryParams map[string]string
|
expectedQueryParams map[string]string
|
||||||
|
@ -76,6 +81,14 @@ func TestContainersPrune(t *testing.T) {
|
||||||
"filters": `{"dangling":{"false":true}}`,
|
"filters": `{"dangling":{"false":true}}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filters: labelFilters,
|
||||||
|
expectedQueryParams: map[string]string{
|
||||||
|
"until": "",
|
||||||
|
"filter": "",
|
||||||
|
"filters": `{"dangling":{"true":true},"label":{"label1=foo":true,"label2!=bar":true}}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, listCase := range listCases {
|
for _, listCase := range listCases {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
|
|
|
@ -36,6 +36,11 @@ func TestImagesPrune(t *testing.T) {
|
||||||
noDanglingFilters := filters.NewArgs()
|
noDanglingFilters := filters.NewArgs()
|
||||||
noDanglingFilters.Add("dangling", "false")
|
noDanglingFilters.Add("dangling", "false")
|
||||||
|
|
||||||
|
labelFilters := filters.NewArgs()
|
||||||
|
labelFilters.Add("dangling", "true")
|
||||||
|
labelFilters.Add("label", "label1=foo")
|
||||||
|
labelFilters.Add("label", "label2!=bar")
|
||||||
|
|
||||||
listCases := []struct {
|
listCases := []struct {
|
||||||
filters filters.Args
|
filters filters.Args
|
||||||
expectedQueryParams map[string]string
|
expectedQueryParams map[string]string
|
||||||
|
@ -64,6 +69,14 @@ func TestImagesPrune(t *testing.T) {
|
||||||
"filters": `{"dangling":{"false":true}}`,
|
"filters": `{"dangling":{"false":true}}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filters: labelFilters,
|
||||||
|
expectedQueryParams: map[string]string{
|
||||||
|
"until": "",
|
||||||
|
"filter": "",
|
||||||
|
"filters": `{"dangling":{"true":true},"label":{"label1=foo":true,"label2!=bar":true}}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, listCase := range listCases {
|
for _, listCase := range listCases {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
|
|
|
@ -38,6 +38,11 @@ func TestNetworksPrune(t *testing.T) {
|
||||||
noDanglingFilters := filters.NewArgs()
|
noDanglingFilters := filters.NewArgs()
|
||||||
noDanglingFilters.Add("dangling", "false")
|
noDanglingFilters.Add("dangling", "false")
|
||||||
|
|
||||||
|
labelFilters := filters.NewArgs()
|
||||||
|
labelFilters.Add("dangling", "true")
|
||||||
|
labelFilters.Add("label", "label1=foo")
|
||||||
|
labelFilters.Add("label", "label2!=bar")
|
||||||
|
|
||||||
listCases := []struct {
|
listCases := []struct {
|
||||||
filters filters.Args
|
filters filters.Args
|
||||||
expectedQueryParams map[string]string
|
expectedQueryParams map[string]string
|
||||||
|
@ -66,6 +71,14 @@ func TestNetworksPrune(t *testing.T) {
|
||||||
"filters": `{"dangling":{"false":true}}`,
|
"filters": `{"dangling":{"false":true}}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filters: labelFilters,
|
||||||
|
expectedQueryParams: map[string]string{
|
||||||
|
"until": "",
|
||||||
|
"filter": "",
|
||||||
|
"filters": `{"dangling":{"true":true},"label":{"label1=foo":true,"label2!=bar":true}}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, listCase := range listCases {
|
for _, listCase := range listCases {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
|
|
Loading…
Reference in New Issue