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 <mathieu.champlon@docker.com>
Upstream-commit: 297866ebbe
Component: cli
This commit is contained in:
Mathieu Champlon
2018-05-24 15:24:23 +02:00
parent b8ca625f10
commit 79dd15d857
2 changed files with 6 additions and 8 deletions
@@ -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
@@ -75,7 +75,8 @@ func TestServiceFiltersLabelSelectorGen(t *testing.T) {
),
expectedSelectorParts: []string{
"com.docker.stack.namespace=test",
"label1 in (test,test2)",
"label1=test",
"label1=test2",
},
},
{