mirror of https://github.com/docker/cli.git
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>
This commit is contained in:
parent
1f7aa1c036
commit
297866ebbe
|
@ -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",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue