From 297866ebbe843dd20b867fa15b3e3de34c169bf3 Mon Sep 17 00:00:00 2001 From: Mathieu Champlon Date: Thu, 24 May 2018 14:14:37 +0200 Subject: [PATCH] Match Swarm in how to combine filters `docker stack services --filter=label=foo=bar --filter=label=foo=baz my-stack` with Swarm gets handled as `filter on (a label named foo with value bar) AND (a label named foo with value baz). This obviously yields an empty result set every time, but if and how this should be changed is out of scope here, so simply align Kubernetes with Swarm for now. Signed-off-by: Mathieu Champlon --- cli/command/stack/kubernetes/services.go | 11 ++++------- cli/command/stack/kubernetes/services_test.go | 3 ++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cli/command/stack/kubernetes/services.go b/cli/command/stack/kubernetes/services.go index 9cf89f4f0f..5a1db529dd 100644 --- a/cli/command/stack/kubernetes/services.go +++ b/cli/command/stack/kubernetes/services.go @@ -24,14 +24,11 @@ var supportedServicesFilters = map[string]bool{ func generateSelector(labels map[string][]string) []string { var result []string for k, v := range labels { - switch len(v) { - case 0: + for _, val := range v { + result = append(result, fmt.Sprintf("%s=%s", k, val)) + } + if len(v) == 0 { result = append(result, k) - case 1: - result = append(result, fmt.Sprintf("%s=%s", k, v[0])) - default: - sort.Strings(v) - result = append(result, fmt.Sprintf("%s in (%s)", k, strings.Join(v, ","))) } } return result diff --git a/cli/command/stack/kubernetes/services_test.go b/cli/command/stack/kubernetes/services_test.go index 9537f203f9..41a3348e0b 100644 --- a/cli/command/stack/kubernetes/services_test.go +++ b/cli/command/stack/kubernetes/services_test.go @@ -75,7 +75,8 @@ func TestServiceFiltersLabelSelectorGen(t *testing.T) { ), expectedSelectorParts: []string{ "com.docker.stack.namespace=test", - "label1 in (test,test2)", + "label1=test", + "label1=test2", }, }, {