From 66059a925b0f27e4f99972e0c410686f84f24bf6 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Wed, 30 May 2018 15:19:45 +0200 Subject: [PATCH 1/2] 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 1895ac7cd793..a4ee14f6367b 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 +} From a252cb119748616ad5bf16d980155f49e64d9133 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Wed, 30 May 2018 15:20:44 +0200 Subject: [PATCH 2/2] Fix outputting twice the docker stack rm error message Signed-off-by: Silvin Lubecki --- cli/command/stack/kubernetes/remove.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/command/stack/kubernetes/remove.go b/cli/command/stack/kubernetes/remove.go index af68db7f306e..311c7597af65 100644 --- a/cli/command/stack/kubernetes/remove.go +++ b/cli/command/stack/kubernetes/remove.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/docker/cli/cli/command/stack/options" + "github.com/pkg/errors" ) // RunRemove is the kubernetes implementation of docker stack remove @@ -18,10 +19,8 @@ func RunRemove(dockerCli *KubeCli, opts options.Remove) error { } for _, stack := range opts.Namespaces { fmt.Fprintf(dockerCli.Out(), "Removing stack: %s\n", stack) - err := stacks.Delete(stack) - if err != nil { - fmt.Fprintf(dockerCli.Out(), "Failed to remove stack %s: %s\n", stack, err) - return err + if err := stacks.Delete(stack); err != nil { + return errors.Wrapf(err, "Failed to remove stack %s", stack) } } return nil