{"action":"created","comment":{"url":"https://api.github.com/repos/docker/cli/pulls/comments/187707829","pull_request_review_id":119549537,"id":187707829,"diff_hunk":"@@ -57,3 +57,96 @@ func getStacks(kubeCli *KubeCli, allNamespaces bool) ([]*formatter.Stack, error)\n \t}\n \treturn formattedStacks, nil\n }\n+\n+func getStacksWithAllNamespaces(dockerCli command.Cli, opts options.List, kopts Options) ([]*formatter.Stack, error) {\n+\tstacks, err := getStacks(dockerCli, opts, kopts)\n+\tif err == nil || !apierrs.IsForbidden(err) {\n+\t\treturn stacks, err\n+\t}\n+\tnms, err2 := getUserVisibleNamespaces(dockerCli)\n+\tif err2 != nil {\n+\t\tlogrus.Warnf(\"Failed to query user visible namespaces: %s\", err2)\n+\t\treturn nil, err\n+\t}\n+\topts.AllNamespaces = false\n+\tfor _, namespace := range nms.Items {\n+\t\tkopts.Namespace = namespace.Name\n+\t\tss, err := getStacks(dockerCli, opts, kopts)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\tstacks = append(stacks, ss...)\n+\t}\n+\treturn stacks, nil\n+}\n+\n+func getUserVisibleNamespaces(dockerCli command.Cli) (*core_v1.NamespaceList, error) {\n+\thost := dockerCli.Client().DaemonHost()\n+\tendpoint, err := url.Parse(host)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tendpoint.Scheme = \"https\"\n+\tendpoint.Path = \"/kubernetesNamespaces\"","path":"cli/command/stack/kubernetes/list.go","position":105,"original_position":105,"commit_id":"09ffc292ddab53b0df3bccabf7b05522243de8bd","original_commit_id":"09ffc292ddab53b0df3bccabf7b05522243de8bd","user":{"login":"mat007","id":2386884,"avatar_url":"https://avatars0.githubusercontent.com/u/2386884?v=4","gravatar_id":"","url":"https://api.github.com/users/mat007","html_url":"https://github.com/mat007","followers_url":"https://api.github.com/users/mat007/followers","following_url":"https://api.github.com/users/mat007/following{/other_user}","gists_url":"https://api.github.com/users/mat007/gists{/gist_id}","starred_url":"https://api.github.com/users/mat007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mat007/subscriptions","organizations_url":"https://api.github.com/users/mat007/orgs","repos_url":"https://api.github.com/users/mat007/repos","events_url":"https://api.github.com/users/mat007/events{/privacy}","received_events_url":"https://api.github.com/users/mat007/received_events","type":"User","site_admin":false},"body":"You're right, this is really fragile and ad hoc, however this is indeed a UX requirement and Kubernetes does not provide this feature…\r\nIf you have any suggestion on how to better manage this I'll be happy to update the code.","created_at":"2018-05-11T19:13:34Z","updated_at":"2018-05-11T19:13:34Z","html_url":"https://github.com/docker/cli/pull/1034#discussion_r187707829","pull_request_url":"https://api.github.com/repos/docker/cli/pulls/1034","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/docker/cli/pulls/comments/187707829"},"html":{"href":"https://github.com/docker/cli/pull/1034#discussion_r187707829"},"pull_request":{"href":"https://api.github.com/repos/docker/cli/pulls/1034"}},"in_reply_to_id":187698425},"pull_request":{"url":"https://api.github.com/repos/docker/cli/pulls/1034","id":185446077,"html_url":"https://github.com/docker/cli/pull/1034","diff_url":"https://github.com/docker/cli/pull/1034.diff","patch_url":"https://github.com/docker/cli/pull/1034.patch","issue_url":"https://api.github.com/repos/docker/cli/issues/1034","number":1034,"state":"open","locked":false,"title":"[WIP] Better user experience with Kubernetes namespaces in docker stack ls","user":{"login":"mat007","id":2386884,"avatar_url":"https://avatars0.githubusercontent.com/u/2386884?v=4","gravatar_id":"","url":"https://api.github.com/users/mat007","html_url":"https://github.com/mat007","followers_url":"https://api.github.com/users/mat007/followers","following_url":"https://api.github.com/users/mat007/following{/other_user}","gists_url":"https://api.github.com/users/mat007/gists{/gist_id}","starred_url":"https://api.github.com/users/mat007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mat007/subscriptions","organizations_url":"https://api.github.com/users/mat007/orgs","repos_url":"https://api.github.com/users/mat007/repos","events_url":"https://api.github.com/users/mat007/events{/privacy}","received_events_url":"https://api.github.com/users/mat007/received_events","type":"User","site_admin":false},"body":"**- What I did**\r\n\r\nMade docker stack ls with the Kubernetes orchestrator list the namespaces a non-administrator user\r\nhas access to.\r\n\r\n**- How I did it**\r\n\r\nAs this use case cannot be handled using the native Kubernetes API, I had to use an ad hoc workaround in the form of a call to the UCP API as a backup in the event of the call to the Kubernetes API failing.\r\n\r\nAlso as there is no simple means to retrieve the http client from the docker client, a new http client is being created…\r\n\r\n**- How to verify it**\r\n\r\nCreate a Kubernetes user 'my-user' and grant it only access to the namespace of some installed services.\r\n\r\nWithout this PR docker stack ls fails when\r\n```\r\n> docker stack ls  --orchestrator=kubernetes --all-namespaces\r\nstacks.compose.docker.com is forbidden: User \"my-user\" cannot list stacks.compose.docker.com at the cluster scope: access denied\r\n```\r\nwhereas with the PR\r\n```\r\n> docker stack ls  --orchestrator=kubernetes --all-namespaces\r\nNAME                SERVICES            ORCHESTRATOR        NAMESPACE\r\ndtc                 5                   Kubernetes          tutu\r\n\r\nAlso without ```--all-namespaces``` it falls back to the default ```--namespace=default``` and correctly fails\r\n> docker stack ls  --orchestrator=kubernetes --all-namespaces\r\nstacks.compose.docker.com is forbidden: User \"my-user\" cannot list stacks.compose.docker.com in the namespace \"default\": access denied\r\n```\r\n\r\n**- Description for the changelog**\r\n\r\nNone as this is merely a tweak for what was added in https://github.com/docker/cli/pull/1031\r\n\r\n**- A picture of a cute animal (not mandatory but encouraged)**\r\n\r\n![image](https://user-images.githubusercontent.com/2386884/39527155-12d0a028-4e21-11e8-9617-a162ccae4105.png)\r\n","created_at":"2018-05-02T13:54:39Z","updated_at":"2018-05-11T19:13:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d2e7334222bf8ca9de874c16b97895d1ba6b8a04","assignee":null,"assignees":[],"requested_reviewers":[{"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}],"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":585916071,"url":"https://api.github.com/repos/docker/cli/labels/status/2-code-review","name":"status/2-code-review","color":"fad8c7","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/docker/cli/pulls/1034/commits","review_comments_url":"https://api.github.com/repos/docker/cli/pulls/1034/comments","review_comment_url":"https://api.github.com/repos/docker/cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/cli/issues/1034/comments","statuses_url":"https://api.github.com/repos/docker/cli/statuses/09ffc292ddab53b0df3bccabf7b05522243de8bd","head":{"label":"mat007:kubernetes-orchestrator-query-ucp","ref":"kubernetes-orchestrator-query-ucp","sha":"09ffc292ddab53b0df3bccabf7b05522243de8bd","user":{"login":"mat007","id":2386884,"avatar_url":"https://avatars0.githubusercontent.com/u/2386884?v=4","gravatar_id":"","url":"https://api.github.com/users/mat007","html_url":"https://github.com/mat007","followers_url":"https://api.github.com/users/mat007/followers","following_url":"https://api.github.com/users/mat007/following{/other_user}","gists_url":"https://api.github.com/users/mat007/gists{/gist_id}","starred_url":"https://api.github.com/users/mat007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mat007/subscriptions","organizations_url":"https://api.github.com/users/mat007/orgs","repos_url":"https://api.github.com/users/mat007/repos","events_url":"https://api.github.com/users/mat007/events{/privacy}","received_events_url":"https://api.github.com/users/mat007/received_events","type":"User","site_admin":false},"repo":{"id":130710798,"name":"cli","full_name":"mat007/cli","owner":{"login":"mat007","id":2386884,"avatar_url":"https://avatars0.githubusercontent.com/u/2386884?v=4","gravatar_id":"","url":"https://api.github.com/users/mat007","html_url":"https://github.com/mat007","followers_url":"https://api.github.com/users/mat007/followers","following_url":"https://api.github.com/users/mat007/following{/other_user}","gists_url":"https://api.github.com/users/mat007/gists{/gist_id}","starred_url":"https://api.github.com/users/mat007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mat007/subscriptions","organizations_url":"https://api.github.com/users/mat007/orgs","repos_url":"https://api.github.com/users/mat007/repos","events_url":"https://api.github.com/users/mat007/events{/privacy}","received_events_url":"https://api.github.com/users/mat007/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mat007/cli","description":"The Docker CLI","fork":true,"url":"https://api.github.com/repos/mat007/cli","forks_url":"https://api.github.com/repos/mat007/cli/forks","keys_url":"https://api.github.com/repos/mat007/cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mat007/cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mat007/cli/teams","hooks_url":"https://api.github.com/repos/mat007/cli/hooks","issue_events_url":"https://api.github.com/repos/mat007/cli/issues/events{/number}","events_url":"https://api.github.com/repos/mat007/cli/events","assignees_url":"https://api.github.com/repos/mat007/cli/assignees{/user}","branches_url":"https://api.github.com/repos/mat007/cli/branches{/branch}","tags_url":"https://api.github.com/repos/mat007/cli/tags","blobs_url":"https://api.github.com/repos/mat007/cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mat007/cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mat007/cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/mat007/cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mat007/cli/statuses/{sha}","languages_url":"https://api.github.com/repos/mat007/cli/languages","stargazers_url":"https://api.github.com/repos/mat007/cli/stargazers","contributors_url":"https://api.github.com/repos/mat007/cli/contributors","subscribers_url":"https://api.github.com/repos/mat007/cli/subscribers","subscription_url":"https://api.github.com/repos/mat007/cli/subscription","commits_url":"https://api.github.com/repos/mat007/cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/mat007/cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/mat007/cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/mat007/cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/mat007/cli/contents/{+path}","compare_url":"https://api.github.com/repos/mat007/cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mat007/cli/merges","archive_url":"https://api.github.com/repos/mat007/cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mat007/cli/downloads","issues_url":"https://api.github.com/repos/mat007/cli/issues{/number}","pulls_url":"https://api.github.com/repos/mat007/cli/pulls{/number}","milestones_url":"https://api.github.com/repos/mat007/cli/milestones{/number}","notifications_url":"https://api.github.com/repos/mat007/cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mat007/cli/labels{/name}","releases_url":"https://api.github.com/repos/mat007/cli/releases{/id}","deployments_url":"https://api.github.com/repos/mat007/cli/deployments","created_at":"2018-04-23T14:36:44Z","updated_at":"2018-05-10T09:08:43Z","pushed_at":"2018-05-11T15:20:02Z","git_url":"git://github.com/mat007/cli.git","ssh_url":"git@github.com:mat007/cli.git","clone_url":"https://github.com/mat007/cli.git","svn_url":"https://github.com/mat007/cli","homepage":null,"size":17329,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"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":"ab1d49a31357e0b1761e3759592300bad61301e6","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-11T16:06:34Z","pushed_at":"2018-05-11T18:03:33Z","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":17295,"stargazers_count":655,"watchers_count":655,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":411,"mirror_url":null,"archived":false,"open_issues_count":222,"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":411,"open_issues":222,"watchers":655,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/cli/pulls/1034"},"html":{"href":"https://github.com/docker/cli/pull/1034"},"issue":{"href":"https://api.github.com/repos/docker/cli/issues/1034"},"comments":{"href":"https://api.github.com/repos/docker/cli/issues/1034/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/cli/pulls/1034/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/cli/pulls/1034/commits"},"statuses":{"href":"https://api.github.com/repos/docker/cli/statuses/09ffc292ddab53b0df3bccabf7b05522243de8bd"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mat007"}}