{"action":"created","comment":{"url":"https://api.github.com/repos/docker/cli/pulls/comments/189285095","pull_request_review_id":121435568,"id":189285095,"diff_hunk":"@@ -2,43 +2,136 @@ package kubernetes\n \n import (\n \t\"fmt\"\n+\t\"sort\"\n+\t\"strings\"\n \n \t\"github.com/docker/cli/cli/command/formatter\"\n \t\"github.com/docker/cli/cli/command/stack/options\"\n \t\"github.com/docker/cli/kubernetes/labels\"\n+\t\"github.com/docker/docker/api/types/filters\"\n+\tappsv1beta2 \"k8s.io/api/apps/v1beta2\"\n+\tcorev1 \"k8s.io/api/core/v1\"\n+\tapierrs \"k8s.io/apimachinery/pkg/api/errors\"\n \tmetav1 \"k8s.io/apimachinery/pkg/apis/meta/v1\"\n )\n \n+var supportedServicesFilters = map[string]bool{\n+\t\"mode\":  true,\n+\t\"name\":  true,\n+\t\"label\": true,\n+}\n+\n+func generateValuedLabelsSelector(valuedLabels map[string][]string) []string {\n+\tvar result []string\n+\tfor k, v := range valuedLabels {\n+\t\tif len(v) == 1 {\n+\t\t\tresult = append(result, fmt.Sprintf(\"%s=%s\", k, v[0]))\n+\t\t} else {\n+\t\t\tsort.Strings(v)\n+\t\t\tresult = append(result, fmt.Sprintf(\"%s in (%s)\", k, strings.Join(v, \",\")))","path":"cli/command/stack/kubernetes/services.go","position":30,"original_position":30,"commit_id":"249a3f30b5d1a7ef61a8fc037ddc62bfa2eedd4f","original_commit_id":"249a3f30b5d1a7ef61a8fc037ddc62bfa2eedd4f","user":{"login":"thaJeztah","id":1804568,"avatar_url":"https://avatars2.githubusercontent.com/u/1804568?v=4","gravatar_id":"","url":"https://api.github.com/users/thaJeztah","html_url":"https://github.com/thaJeztah","followers_url":"https://api.github.com/users/thaJeztah/followers","following_url":"https://api.github.com/users/thaJeztah/following{/other_user}","gists_url":"https://api.github.com/users/thaJeztah/gists{/gist_id}","starred_url":"https://api.github.com/users/thaJeztah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thaJeztah/subscriptions","organizations_url":"https://api.github.com/users/thaJeztah/orgs","repos_url":"https://api.github.com/users/thaJeztah/repos","events_url":"https://api.github.com/users/thaJeztah/events{/privacy}","received_events_url":"https://api.github.com/users/thaJeztah/received_events","type":"User","site_admin":false},"body":"is the `in (x)` operator less efficient than `x=y`, or will the selector be smart enough to optimise if there's a single value?\r\n\r\nIf so, we could simplify to;\r\n\r\n```go\r\nfor k, v := range valuedLabels {\r\n    sort.Strings(v)\r\n    result = append(result, fmt.Sprintf(\"%s in (%s)\", k, strings.Join(v, \",\")))\r\n}\r\n```","created_at":"2018-05-18T14:23:30Z","updated_at":"2018-05-18T14:57:21Z","html_url":"https://github.com/docker/cli/pull/1023#discussion_r189285095","pull_request_url":"https://api.github.com/repos/docker/cli/pulls/1023","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/docker/cli/pulls/comments/189285095"},"html":{"href":"https://github.com/docker/cli/pull/1023#discussion_r189285095"},"pull_request":{"href":"https://api.github.com/repos/docker/cli/pulls/1023"}}},"pull_request":{"url":"https://api.github.com/repos/docker/cli/pulls/1023","id":183728777,"html_url":"https://github.com/docker/cli/pull/1023","diff_url":"https://github.com/docker/cli/pull/1023.diff","patch_url":"https://github.com/docker/cli/pull/1023.patch","issue_url":"https://api.github.com/repos/docker/cli/issues/1023","number":1023,"state":"open","locked":false,"title":"[Kubernetes] stack services filters","user":{"login":"simonferquel","id":1677333,"avatar_url":"https://avatars3.githubusercontent.com/u/1677333?v=4","gravatar_id":"","url":"https://api.github.com/users/simonferquel","html_url":"https://github.com/simonferquel","followers_url":"https://api.github.com/users/simonferquel/followers","following_url":"https://api.github.com/users/simonferquel/following{/other_user}","gists_url":"https://api.github.com/users/simonferquel/gists{/gist_id}","starred_url":"https://api.github.com/users/simonferquel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonferquel/subscriptions","organizations_url":"https://api.github.com/users/simonferquel/orgs","repos_url":"https://api.github.com/users/simonferquel/repos","events_url":"https://api.github.com/users/simonferquel/events{/privacy}","received_events_url":"https://api.github.com/users/simonferquel/received_events","type":"User","site_admin":false},"body":"This PR implements stack services filtering, to align the `docker stack services` experience better.\r\n \r\nThis also fix an issue where global services where missing from the list in Kubernetes mode.\r\n\r\nTo do that, I leveraged Kubernetes LabelSelectors (so everything is done server side), and translated as closely as possible existing supported filters.\r\n\r\nOne occurrence of behavior consistency, is that k8s label selectors only support perfect matches while in Swarm mode, name filters behave as a StartsWith comparison","created_at":"2018-04-24T13:03:56Z","updated_at":"2018-05-18T14:57:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3e73551a91769fabfb31e681dd127da67c7834e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":795078200,"url":"https://api.github.com/repos/docker/cli/labels/area/kubernetes","name":"area/kubernetes","color":"fef2c0","default":false},{"id":617717114,"url":"https://api.github.com/repos/docker/cli/labels/area/stack","name":"area/stack","color":"fef2c0","default":false},{"id":585916070,"url":"https://api.github.com/repos/docker/cli/labels/status/1-design-review","name":"status/1-design-review","color":"fef2c0","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/docker/cli/pulls/1023/commits","review_comments_url":"https://api.github.com/repos/docker/cli/pulls/1023/comments","review_comment_url":"https://api.github.com/repos/docker/cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/cli/issues/1023/comments","statuses_url":"https://api.github.com/repos/docker/cli/statuses/249a3f30b5d1a7ef61a8fc037ddc62bfa2eedd4f","head":{"label":"simonferquel:k8s-stack-services-filters","ref":"k8s-stack-services-filters","sha":"249a3f30b5d1a7ef61a8fc037ddc62bfa2eedd4f","user":{"login":"simonferquel","id":1677333,"avatar_url":"https://avatars3.githubusercontent.com/u/1677333?v=4","gravatar_id":"","url":"https://api.github.com/users/simonferquel","html_url":"https://github.com/simonferquel","followers_url":"https://api.github.com/users/simonferquel/followers","following_url":"https://api.github.com/users/simonferquel/following{/other_user}","gists_url":"https://api.github.com/users/simonferquel/gists{/gist_id}","starred_url":"https://api.github.com/users/simonferquel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonferquel/subscriptions","organizations_url":"https://api.github.com/users/simonferquel/orgs","repos_url":"https://api.github.com/users/simonferquel/repos","events_url":"https://api.github.com/users/simonferquel/events{/privacy}","received_events_url":"https://api.github.com/users/simonferquel/received_events","type":"User","site_admin":false},"repo":{"id":99563380,"name":"cli","full_name":"simonferquel/cli","owner":{"login":"simonferquel","id":1677333,"avatar_url":"https://avatars3.githubusercontent.com/u/1677333?v=4","gravatar_id":"","url":"https://api.github.com/users/simonferquel","html_url":"https://github.com/simonferquel","followers_url":"https://api.github.com/users/simonferquel/followers","following_url":"https://api.github.com/users/simonferquel/following{/other_user}","gists_url":"https://api.github.com/users/simonferquel/gists{/gist_id}","starred_url":"https://api.github.com/users/simonferquel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonferquel/subscriptions","organizations_url":"https://api.github.com/users/simonferquel/orgs","repos_url":"https://api.github.com/users/simonferquel/repos","events_url":"https://api.github.com/users/simonferquel/events{/privacy}","received_events_url":"https://api.github.com/users/simonferquel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/simonferquel/cli","description":"The Docker CLI","fork":true,"url":"https://api.github.com/repos/simonferquel/cli","forks_url":"https://api.github.com/repos/simonferquel/cli/forks","keys_url":"https://api.github.com/repos/simonferquel/cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/simonferquel/cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/simonferquel/cli/teams","hooks_url":"https://api.github.com/repos/simonferquel/cli/hooks","issue_events_url":"https://api.github.com/repos/simonferquel/cli/issues/events{/number}","events_url":"https://api.github.com/repos/simonferquel/cli/events","assignees_url":"https://api.github.com/repos/simonferquel/cli/assignees{/user}","branches_url":"https://api.github.com/repos/simonferquel/cli/branches{/branch}","tags_url":"https://api.github.com/repos/simonferquel/cli/tags","blobs_url":"https://api.github.com/repos/simonferquel/cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/simonferquel/cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/simonferquel/cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/simonferquel/cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/simonferquel/cli/statuses/{sha}","languages_url":"https://api.github.com/repos/simonferquel/cli/languages","stargazers_url":"https://api.github.com/repos/simonferquel/cli/stargazers","contributors_url":"https://api.github.com/repos/simonferquel/cli/contributors","subscribers_url":"https://api.github.com/repos/simonferquel/cli/subscribers","subscription_url":"https://api.github.com/repos/simonferquel/cli/subscription","commits_url":"https://api.github.com/repos/simonferquel/cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/simonferquel/cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/simonferquel/cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/simonferquel/cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/simonferquel/cli/contents/{+path}","compare_url":"https://api.github.com/repos/simonferquel/cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/simonferquel/cli/merges","archive_url":"https://api.github.com/repos/simonferquel/cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/simonferquel/cli/downloads","issues_url":"https://api.github.com/repos/simonferquel/cli/issues{/number}","pulls_url":"https://api.github.com/repos/simonferquel/cli/pulls{/number}","milestones_url":"https://api.github.com/repos/simonferquel/cli/milestones{/number}","notifications_url":"https://api.github.com/repos/simonferquel/cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/simonferquel/cli/labels{/name}","releases_url":"https://api.github.com/repos/simonferquel/cli/releases{/id}","deployments_url":"https://api.github.com/repos/simonferquel/cli/deployments","created_at":"2017-08-07T09:53:21Z","updated_at":"2017-08-07T09:53:24Z","pushed_at":"2018-05-18T14:21:35Z","git_url":"git://github.com/simonferquel/cli.git","ssh_url":"git@github.com:simonferquel/cli.git","clone_url":"https://github.com/simonferquel/cli.git","svn_url":"https://github.com/simonferquel/cli","homepage":null,"size":17422,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"b15c3cfec93a399609afe9414d7585d3d9605e4b","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars1.githubusercontent.com/u/5429470?v=4","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":88013053,"name":"cli","full_name":"docker/cli","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars1.githubusercontent.com/u/5429470?v=4","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/cli","description":"The Docker CLI","fork":false,"url":"https://api.github.com/repos/docker/cli","forks_url":"https://api.github.com/repos/docker/cli/forks","keys_url":"https://api.github.com/repos/docker/cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/cli/teams","hooks_url":"https://api.github.com/repos/docker/cli/hooks","issue_events_url":"https://api.github.com/repos/docker/cli/issues/events{/number}","events_url":"https://api.github.com/repos/docker/cli/events","assignees_url":"https://api.github.com/repos/docker/cli/assignees{/user}","branches_url":"https://api.github.com/repos/docker/cli/branches{/branch}","tags_url":"https://api.github.com/repos/docker/cli/tags","blobs_url":"https://api.github.com/repos/docker/cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/cli/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/cli/languages","stargazers_url":"https://api.github.com/repos/docker/cli/stargazers","contributors_url":"https://api.github.com/repos/docker/cli/contributors","subscribers_url":"https://api.github.com/repos/docker/cli/subscribers","subscription_url":"https://api.github.com/repos/docker/cli/subscription","commits_url":"https://api.github.com/repos/docker/cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/cli/contents/{+path}","compare_url":"https://api.github.com/repos/docker/cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/cli/merges","archive_url":"https://api.github.com/repos/docker/cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/cli/downloads","issues_url":"https://api.github.com/repos/docker/cli/issues{/number}","pulls_url":"https://api.github.com/repos/docker/cli/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/cli/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/cli/labels{/name}","releases_url":"https://api.github.com/repos/docker/cli/releases{/id}","deployments_url":"https://api.github.com/repos/docker/cli/deployments","created_at":"2017-04-12T05:27:42Z","updated_at":"2018-05-18T14:40:01Z","pushed_at":"2018-05-18T14:39:51Z","git_url":"git://github.com/docker/cli.git","ssh_url":"git@github.com:docker/cli.git","clone_url":"https://github.com/docker/cli.git","svn_url":"https://github.com/docker/cli","homepage":null,"size":17516,"stargazers_count":662,"watchers_count":662,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":418,"mirror_url":null,"archived":false,"open_issues_count":216,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":418,"open_issues":216,"watchers":662,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/cli/pulls/1023"},"html":{"href":"https://github.com/docker/cli/pull/1023"},"issue":{"href":"https://api.github.com/repos/docker/cli/issues/1023"},"comments":{"href":"https://api.github.com/repos/docker/cli/issues/1023/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/cli/pulls/1023/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/cli/pulls/1023/commits"},"statuses":{"href":"https://api.github.com/repos/docker/cli/statuses/249a3f30b5d1a7ef61a8fc037ddc62bfa2eedd4f"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"thaJeztah"}}