From 66059a925b0f27e4f99972e0c410686f84f24bf6 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Wed, 30 May 2018 15:19:45 +0200 Subject: [PATCH] Fix always listing nodes during docker stack ps command on Kubernetes. A user without node listing rights could not use this command as it always fails. Signed-off-by: Silvin Lubecki --- cli/command/stack/kubernetes/ps.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/command/stack/kubernetes/ps.go b/cli/command/stack/kubernetes/ps.go index 1895ac7cd7..a4ee14f636 100644 --- a/cli/command/stack/kubernetes/ps.go +++ b/cli/command/stack/kubernetes/ps.go @@ -68,7 +68,7 @@ func printTasks(dockerCli command.Cli, options options.PS, namespace string, cli names := map[string]string{} nodes := map[string]string{} - n, err := client.Nodes().List(metav1.ListOptions{}) + n, err := listNodes(client, options.NoResolve) if err != nil { return err } @@ -103,3 +103,10 @@ func resolveNode(name string, nodes *apiv1.NodeList, noResolve bool) (string, er } return name, nil } + +func listNodes(client corev1.NodesGetter, noResolve bool) (*apiv1.NodeList, error) { + if noResolve { + return client.Nodes().List(metav1.ListOptions{}) + } + return nil, nil +}