Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFD] Revert "Match Swarm in how to combine filters" #1085

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions cli/command/stack/kubernetes/services.go
Expand Up @@ -24,11 +24,14 @@ var supportedServicesFilters = map[string]bool{
func generateSelector(labels map[string][]string) []string {
var result []string
for k, v := range labels {
for _, val := range v {
result = append(result, fmt.Sprintf("%s=%s", k, val))
}
if len(v) == 0 {
switch len(v) {
case 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
3 changes: 1 addition & 2 deletions cli/command/stack/kubernetes/services_test.go
Expand Up @@ -75,8 +75,7 @@ func TestServiceFiltersLabelSelectorGen(t *testing.T) {
),
expectedSelectorParts: []string{
"com.docker.stack.namespace=test",
"label1=test",
"label1=test2",
"label1 in (test,test2)",
},
},
{
Expand Down