Browse code

Merge pull request #27516 from allencloud/change-remove-multi-nodes

make every node and plugin removal call api

Aaron Lehmann authored on 2016/10/21 02:10:52
Showing 2 changed files
... ...
@@ -2,6 +2,7 @@ package node
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"strings"
5 6
 
6 7
 	"golang.org/x/net/context"
7 8
 
... ...
@@ -35,12 +36,21 @@ func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
35 35
 func runRemove(dockerCli *command.DockerCli, args []string, opts removeOptions) error {
36 36
 	client := dockerCli.Client()
37 37
 	ctx := context.Background()
38
+
39
+	var errs []string
40
+
38 41
 	for _, nodeID := range args {
39 42
 		err := client.NodeRemove(ctx, nodeID, types.NodeRemoveOptions{Force: opts.force})
40 43
 		if err != nil {
41
-			return err
44
+			errs = append(errs, err.Error())
45
+			continue
42 46
 		}
43 47
 		fmt.Fprintf(dockerCli.Out(), "%s\n", nodeID)
44 48
 	}
49
+
50
+	if len(errs) > 0 {
51
+		return fmt.Errorf("%s", strings.Join(errs, "\n"))
52
+	}
53
+
45 54
 	return nil
46 55
 }
... ...
@@ -45,14 +45,16 @@ func runRemove(dockerCli *command.DockerCli, opts *rmOptions) error {
45 45
 	for _, name := range opts.plugins {
46 46
 		named, err := reference.ParseNamed(name) // FIXME: validate
47 47
 		if err != nil {
48
-			return err
48
+			errs = append(errs, err)
49
+			continue
49 50
 		}
50 51
 		if reference.IsNameOnly(named) {
51 52
 			named = reference.WithDefaultTag(named)
52 53
 		}
53 54
 		ref, ok := named.(reference.NamedTagged)
54 55
 		if !ok {
55
-			return fmt.Errorf("invalid name: %s", named.String())
56
+			errs = append(errs, fmt.Errorf("invalid name: %s", named.String()))
57
+			continue
56 58
 		}
57 59
 		// TODO: pass names to api instead of making multiple api calls
58 60
 		if err := dockerCli.Client().PluginRemove(ctx, ref.String(), types.PluginRemoveOptions{Force: opts.force}); err != nil {