Browse code

Remove --network-add and --network-rm flags from service update

These flags were not supported (daemon returns an error), and it was an
oversight. They were not present in completion scripts.

Signed-off-by: Tibor Vass <tibor@docker.com>

Tibor Vass authored on 2016/08/12 10:30:04
Showing 4 changed files
... ...
@@ -538,8 +538,6 @@ const (
538 538
 	flagMountAdd             = "mount-add"
539 539
 	flagName                 = "name"
540 540
 	flagNetwork              = "network"
541
-	flagNetworkRemove        = "network-rm"
542
-	flagNetworkAdd           = "network-add"
543 541
 	flagPublish              = "publish"
544 542
 	flagPublishRemove        = "publish-rm"
545 543
 	flagPublishAdd           = "publish-add"
... ...
@@ -42,14 +42,12 @@ func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
42 42
 	flags.Var(newListOptsVar(), flagContainerLabelRemove, "Remove a container label by its key")
43 43
 	flags.Var(newListOptsVar(), flagMountRemove, "Remove a mount by its target path")
44 44
 	flags.Var(newListOptsVar(), flagPublishRemove, "Remove a published port by its target port")
45
-	flags.Var(newListOptsVar(), flagNetworkRemove, "Remove a network by name")
46 45
 	flags.Var(newListOptsVar(), flagConstraintRemove, "Remove a constraint")
47 46
 	flags.Var(&opts.labels, flagLabelAdd, "Add or update service labels")
48 47
 	flags.Var(&opts.containerLabels, flagContainerLabelAdd, "Add or update container labels")
49 48
 	flags.Var(&opts.env, flagEnvAdd, "Add or update environment variables")
50 49
 	flags.Var(&opts.mounts, flagMountAdd, "Add or update a mount on a service")
51 50
 	flags.StringSliceVar(&opts.constraints, flagConstraintAdd, []string{}, "Add or update placement constraints")
52
-	flags.StringSliceVar(&opts.networks, flagNetworkAdd, []string{}, "Add or update network attachments")
53 51
 	flags.Var(&opts.endpoint.ports, flagPublishAdd, "Add or update a published port")
54 52
 	return cmd
55 53
 }
... ...
@@ -204,7 +202,6 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
204 204
 		updateString(flagUpdateFailureAction, &spec.UpdateConfig.FailureAction)
205 205
 	}
206 206
 
207
-	updateNetworks(flags, &spec.Networks)
208 207
 	if flags.Changed(flagEndpointMode) {
209 208
 		value, _ := flags.GetString(flagEndpointMode)
210 209
 		if spec.EndpointSpec == nil {
... ...
@@ -439,23 +436,6 @@ func equalPort(targetPort nat.Port, port swarm.PortConfig) bool {
439 439
 		port.TargetPort == uint32(targetPort.Int()))
440 440
 }
441 441
 
442
-func updateNetworks(flags *pflag.FlagSet, attachments *[]swarm.NetworkAttachmentConfig) {
443
-	if flags.Changed(flagNetworkAdd) {
444
-		networks, _ := flags.GetStringSlice(flagNetworkAdd)
445
-		for _, network := range networks {
446
-			*attachments = append(*attachments, swarm.NetworkAttachmentConfig{Target: network})
447
-		}
448
-	}
449
-	toRemove := buildToRemoveSet(flags, flagNetworkRemove)
450
-	newNetworks := []swarm.NetworkAttachmentConfig{}
451
-	for _, network := range *attachments {
452
-		if _, exists := toRemove[network.Target]; !exists {
453
-			newNetworks = append(newNetworks, network)
454
-		}
455
-	}
456
-	*attachments = newNetworks
457
-}
458
-
459 442
 func updateReplicas(flags *pflag.FlagSet, serviceMode *swarm.ServiceMode) error {
460 443
 	if !flags.Changed(flagReplicas) {
461 444
 		return nil
... ...
@@ -115,22 +115,6 @@ func TestUpdateMounts(t *testing.T) {
115 115
 	assert.Equal(t, mounts[1].Target, "/toadd")
116 116
 }
117 117
 
118
-func TestUpdateNetworks(t *testing.T) {
119
-	flags := newUpdateCommand(nil).Flags()
120
-	flags.Set("network-add", "toadd")
121
-	flags.Set("network-rm", "toremove")
122
-
123
-	attachments := []swarm.NetworkAttachmentConfig{
124
-		{Target: "toremove", Aliases: []string{"foo"}},
125
-		{Target: "tokeep"},
126
-	}
127
-
128
-	updateNetworks(flags, &attachments)
129
-	assert.Equal(t, len(attachments), 2)
130
-	assert.Equal(t, attachments[0].Target, "tokeep")
131
-	assert.Equal(t, attachments[1].Target, "toadd")
132
-}
133
-
134 118
 func TestUpdatePorts(t *testing.T) {
135 119
 	flags := newUpdateCommand(nil).Flags()
136 120
 	flags.Set("publish-add", "1000:1000")
... ...
@@ -35,8 +35,6 @@ Options:
35 35
       --mount-add value                Add or update a mount on a service
36 36
       --mount-rm value                 Remove a mount by its target path (default [])
37 37
       --name string                    Service name
38
-      --network-add value              Add or update network attachments (default [])
39
-      --network-rm value               Remove a network by name (default [])
40 38
       --publish-add value              Add or update a published port (default [])
41 39
       --publish-rm value               Remove a published port by its target port (default [])
42 40
       --replicas value                 Number of tasks (default none)