From c3bfcc372c7e36a7c511a3c1761f065ddaa16992 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sat, 4 Feb 2017 09:10:05 -0800 Subject: [PATCH] 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 --- container_prune_test.go | 13 +++++++++++++ image_prune_test.go | 13 +++++++++++++ network_prune_test.go | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/container_prune_test.go b/container_prune_test.go index 5f06ea0664..55e551bb4b 100644 --- a/container_prune_test.go +++ b/container_prune_test.go @@ -40,6 +40,11 @@ func TestContainersPrune(t *testing.T) { danglingUntilFilters.Add("dangling", "true") 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 { filters filters.Args expectedQueryParams map[string]string @@ -76,6 +81,14 @@ func TestContainersPrune(t *testing.T) { "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 { client := &Client{ diff --git a/image_prune_test.go b/image_prune_test.go index 68cd995d37..5dfb173acc 100644 --- a/image_prune_test.go +++ b/image_prune_test.go @@ -36,6 +36,11 @@ func TestImagesPrune(t *testing.T) { noDanglingFilters := filters.NewArgs() noDanglingFilters.Add("dangling", "false") + labelFilters := filters.NewArgs() + labelFilters.Add("dangling", "true") + labelFilters.Add("label", "label1=foo") + labelFilters.Add("label", "label2!=bar") + listCases := []struct { filters filters.Args expectedQueryParams map[string]string @@ -64,6 +69,14 @@ func TestImagesPrune(t *testing.T) { "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 { client := &Client{ diff --git a/network_prune_test.go b/network_prune_test.go index 07a5d41f20..2bf4af4716 100644 --- a/network_prune_test.go +++ b/network_prune_test.go @@ -38,6 +38,11 @@ func TestNetworksPrune(t *testing.T) { noDanglingFilters := filters.NewArgs() noDanglingFilters.Add("dangling", "false") + labelFilters := filters.NewArgs() + labelFilters.Add("dangling", "true") + labelFilters.Add("label", "label1=foo") + labelFilters.Add("label", "label2!=bar") + listCases := []struct { filters filters.Args expectedQueryParams map[string]string @@ -66,6 +71,14 @@ func TestNetworksPrune(t *testing.T) { "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 { client := &Client{