|
@@ -38,11 +38,13 @@ func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
|
|
|
|
flags.Var(newListOptsVar(), flagEnvRemove, "Remove an environment variable")
|
|
|
flags.Var(newListOptsVar(), flagLabelRemove, "Remove a label by its key")
|
|
|
+ flags.Var(newListOptsVar(), flagContainerLabelRemove, "Remove a container label by its key")
|
|
|
flags.Var(newListOptsVar(), flagMountRemove, "Remove a mount by its target path")
|
|
|
flags.Var(newListOptsVar(), flagPublishRemove, "Remove a published port by its target port")
|
|
|
flags.Var(newListOptsVar(), flagNetworkRemove, "Remove a network by name")
|
|
|
flags.Var(newListOptsVar(), flagConstraintRemove, "Remove a constraint")
|
|
|
flags.Var(&opts.labels, flagLabelAdd, "Add or update service labels")
|
|
|
+ flags.Var(&opts.containerLabels, flagContainerLabelAdd, "Add or update container labels")
|
|
|
flags.Var(&opts.env, flagEnvAdd, "Add or update environment variables")
|
|
|
flags.Var(&opts.mounts, flagMountAdd, "Add or update a mount on a service")
|
|
|
flags.StringSliceVar(&opts.constraints, flagConstraintAdd, []string{}, "Add or update placement constraints")
|
|
@@ -96,7 +98,6 @@ func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID stri
|
|
|
}
|
|
|
|
|
|
func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|
|
-
|
|
|
updateString := func(flag string, field *string) {
|
|
|
if flags.Changed(flag) {
|
|
|
*field, _ = flags.GetString(flag)
|
|
@@ -115,9 +116,10 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- updateDurationOpt := func(flag string, field *time.Duration) {
|
|
|
+ updateDurationOpt := func(flag string, field **time.Duration) {
|
|
|
if flags.Changed(flag) {
|
|
|
- *field = *flags.Lookup(flag).Value.(*DurationOpt).Value()
|
|
|
+ val := *flags.Lookup(flag).Value.(*DurationOpt).Value()
|
|
|
+ *field = &val
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -127,9 +129,10 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- updateUint64Opt := func(flag string, field *uint64) {
|
|
|
+ updateUint64Opt := func(flag string, field **uint64) {
|
|
|
if flags.Changed(flag) {
|
|
|
- *field = *flags.Lookup(flag).Value.(*Uint64Opt).Value()
|
|
|
+ val := *flags.Lookup(flag).Value.(*Uint64Opt).Value()
|
|
|
+ *field = &val
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -145,6 +148,7 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|
|
|
|
|
updateString(flagName, &spec.Name)
|
|
|
updateLabels(flags, &spec.Labels)
|
|
|
+ updateContainerLabels(flags, &cspec.Labels)
|
|
|
updateString("image", &cspec.Image)
|
|
|
updateStringToSlice(flags, "args", &cspec.Args)
|
|
|
updateEnvironment(flags, &cspec.Env)
|
|
@@ -156,7 +160,6 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|
|
taskResources().Limits = &swarm.Resources{}
|
|
|
updateInt64Value(flagLimitCPU, &task.Resources.Limits.NanoCPUs)
|
|
|
updateInt64Value(flagLimitMemory, &task.Resources.Limits.MemoryBytes)
|
|
|
-
|
|
|
}
|
|
|
if flags.Changed(flagReserveCPU) || flags.Changed(flagReserveMemory) {
|
|
|
taskResources().Reservations = &swarm.Resources{}
|
|
@@ -164,7 +167,7 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|
|
updateInt64Value(flagReserveMemory, &task.Resources.Reservations.MemoryBytes)
|
|
|
}
|
|
|
|
|
|
- updateDurationOpt(flagStopGracePeriod, cspec.StopGracePeriod)
|
|
|
+ updateDurationOpt(flagStopGracePeriod, &cspec.StopGracePeriod)
|
|
|
|
|
|
if anyChanged(flags, flagRestartCondition, flagRestartDelay, flagRestartMaxAttempts, flagRestartWindow) {
|
|
|
if task.RestartPolicy == nil {
|
|
@@ -175,9 +178,9 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|
|
value, _ := flags.GetString(flagRestartCondition)
|
|
|
task.RestartPolicy.Condition = swarm.RestartPolicyCondition(value)
|
|
|
}
|
|
|
- updateDurationOpt(flagRestartDelay, task.RestartPolicy.Delay)
|
|
|
- updateUint64Opt(flagRestartMaxAttempts, task.RestartPolicy.MaxAttempts)
|
|
|
- updateDurationOpt((flagRestartWindow), task.RestartPolicy.Window)
|
|
|
+ updateDurationOpt(flagRestartDelay, &task.RestartPolicy.Delay)
|
|
|
+ updateUint64Opt(flagRestartMaxAttempts, &task.RestartPolicy.MaxAttempts)
|
|
|
+ updateDurationOpt(flagRestartWindow, &task.RestartPolicy.Window)
|
|
|
}
|
|
|
|
|
|
if anyChanged(flags, flagConstraintAdd, flagConstraintRemove) {
|
|
@@ -203,6 +206,9 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|
|
updateNetworks(flags, &spec.Networks)
|
|
|
if flags.Changed(flagEndpointMode) {
|
|
|
value, _ := flags.GetString(flagEndpointMode)
|
|
|
+ if spec.EndpointSpec == nil {
|
|
|
+ spec.EndpointSpec = &swarm.EndpointSpec{}
|
|
|
+ }
|
|
|
spec.EndpointSpec.Mode = swarm.ResolutionMode(value)
|
|
|
}
|
|
|
|
|
@@ -248,6 +254,26 @@ func updatePlacement(flags *pflag.FlagSet, placement *swarm.Placement) {
|
|
|
placement.Constraints = removeItems(placement.Constraints, toRemove, itemKey)
|
|
|
}
|
|
|
|
|
|
+func updateContainerLabels(flags *pflag.FlagSet, field *map[string]string) {
|
|
|
+ if flags.Changed(flagContainerLabelAdd) {
|
|
|
+ if *field == nil {
|
|
|
+ *field = map[string]string{}
|
|
|
+ }
|
|
|
+
|
|
|
+ values := flags.Lookup(flagContainerLabelAdd).Value.(*opts.ListOpts).GetAll()
|
|
|
+ for key, value := range runconfigopts.ConvertKVStringsToMap(values) {
|
|
|
+ (*field)[key] = value
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if *field != nil && flags.Changed(flagContainerLabelRemove) {
|
|
|
+ toRemove := flags.Lookup(flagContainerLabelRemove).Value.(*opts.ListOpts).GetAll()
|
|
|
+ for _, label := range toRemove {
|
|
|
+ delete(*field, label)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
|
|
|
if flags.Changed(flagLabelAdd) {
|
|
|
if *field == nil {
|
|
@@ -386,7 +412,7 @@ func updateReplicas(flags *pflag.FlagSet, serviceMode *swarm.ServiceMode) error
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- if serviceMode.Replicated == nil {
|
|
|
+ if serviceMode == nil || serviceMode.Replicated == nil {
|
|
|
return fmt.Errorf("replicas can only be used with replicated mode")
|
|
|
}
|
|
|
serviceMode.Replicated.Replicas = flags.Lookup(flagReplicas).Value.(*Uint64Opt).Value()
|