Jelajahi Sumber

return err when stack name does not exist

Signed-off-by: allencloud <allen.sun@daocloud.io>
allencloud 9 tahun lalu
induk
melakukan
416613f2e5

+ 1 - 1
api/client/node/cmd.go

@@ -35,7 +35,7 @@ func NewNodeCommand(dockerCli *client.DockerCli) *cobra.Command {
 	return cmd
 	return cmd
 }
 }
 
 
-// Reference return the reference of a node. The special value "self" for a node
+// Reference returns the reference of a node. The special value "self" for a node
 // reference is mapped to the current node, hence the node ID is retrieved using
 // reference is mapped to the current node, hence the node ID is retrieved using
 // the `/info` endpoint.
 // the `/info` endpoint.
 func Reference(client apiclient.APIClient, ctx context.Context, ref string) (string, error) {
 func Reference(client apiclient.APIClient, ctx context.Context, ref string) (string, error) {

+ 1 - 1
api/client/stack/cmd.go

@@ -29,7 +29,7 @@ func NewStackCommand(dockerCli *client.DockerCli) *cobra.Command {
 	return cmd
 	return cmd
 }
 }
 
 
-// NewTopLevelDeployCommand return a command for `docker deploy`
+// NewTopLevelDeployCommand returns a command for `docker deploy`
 func NewTopLevelDeployCommand(dockerCli *client.DockerCli) *cobra.Command {
 func NewTopLevelDeployCommand(dockerCli *client.DockerCli) *cobra.Command {
 	cmd := newDeployCommand(dockerCli)
 	cmd := newDeployCommand(dockerCli)
 	// Remove the aliases at the top level
 	// Remove the aliases at the top level

+ 5 - 0
api/client/stack/remove.go

@@ -63,6 +63,11 @@ func runRemove(dockerCli *client.DockerCli, opts removeOptions) error {
 		}
 		}
 	}
 	}
 
 
+	if len(services) == 0 && len(networks) == 0 {
+		fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace)
+		return nil
+	}
+
 	if hasError {
 	if hasError {
 		return fmt.Errorf("Failed to remove some resources")
 		return fmt.Errorf("Failed to remove some resources")
 	}
 	}

+ 8 - 0
api/client/stack/tasks.go

@@ -3,6 +3,8 @@
 package stack
 package stack
 
 
 import (
 import (
+	"fmt"
+
 	"golang.org/x/net/context"
 	"golang.org/x/net/context"
 
 
 	"github.com/docker/docker/api/client"
 	"github.com/docker/docker/api/client"
@@ -43,6 +45,7 @@ func newTasksCommand(dockerCli *client.DockerCli) *cobra.Command {
 }
 }
 
 
 func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error {
 func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error {
+	namespace := opts.namespace
 	client := dockerCli.Client()
 	client := dockerCli.Client()
 	ctx := context.Background()
 	ctx := context.Background()
 
 
@@ -58,5 +61,10 @@ func runTasks(dockerCli *client.DockerCli, opts tasksOptions) error {
 		return err
 		return err
 	}
 	}
 
 
+	if len(tasks) == 0 {
+		fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace)
+		return nil
+	}
+
 	return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve))
 	return task.Print(dockerCli, ctx, tasks, idresolver.New(client, opts.noResolve))
 }
 }

+ 28 - 0
integration-cli/docker_cli_stack_test.go

@@ -0,0 +1,28 @@
+// +build experimental
+
+package main
+
+import (
+	"github.com/docker/docker/pkg/integration/checker"
+	"github.com/go-check/check"
+)
+
+func (s *DockerSwarmSuite) TestStackRemove(c *check.C) {
+	d := s.AddDaemon(c, true, true)
+
+	stackArgs := append([]string{"remove", "UNKNOWN_STACK"})
+
+	out, err := d.Cmd("stack", stackArgs...)
+	c.Assert(err, checker.IsNil)
+	c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
+}
+
+func (s *DockerSwarmSuite) TestStackTasks(c *check.C) {
+	d := s.AddDaemon(c, true, true)
+
+	stackArgs := append([]string{"tasks", "UNKNOWN_STACK"})
+
+	out, err := d.Cmd("stack", stackArgs...)
+	c.Assert(err, checker.IsNil)
+	c.Assert(out, check.Equals, "Nothing found in stack: UNKNOWN_STACK\n")
+}

+ 1 - 1
pkg/integration/checker/checker.go

@@ -1,4 +1,4 @@
-// Package checker provide Docker specific implementations of the go-check.Checker interface.
+// Package checker provides Docker specific implementations of the go-check.Checker interface.
 package checker
 package checker
 
 
 import (
 import (