Skip to content

Commit

Permalink
Match Swarm in how to combine filters
Browse files Browse the repository at this point in the history
`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>
  • Loading branch information
mat007 committed May 24, 2018
1 parent 1f7aa1c commit 5dff68f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cli/command/stack/kubernetes/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5dff68f

Please sign in to comment.