1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #23697 from dongluochen/blockServiceModeChange

Do not allow service mode change
This commit is contained in:
Brian Goff 2016-06-27 10:53:53 -04:00 committed by GitHub
commit e2a26744f9
3 changed files with 7 additions and 32 deletions

View file

@ -24,6 +24,8 @@ func newCreateCommand(dockerCli *client.DockerCli) *cobra.Command {
return runCreate(dockerCli, opts) return runCreate(dockerCli, opts)
}, },
} }
flags := cmd.Flags()
flags.StringVar(&opts.mode, flagMode, "replicated", "Service mode (replicated or global)")
addServiceFlags(cmd, opts) addServiceFlags(cmd, opts)
cmd.Flags().SetInterspersed(false) cmd.Flags().SetInterspersed(false)
return cmd return cmd

View file

@ -454,7 +454,6 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
flags.Var(&opts.resources.resMemBytes, flagReserveMemory, "Reserve Memory") flags.Var(&opts.resources.resMemBytes, flagReserveMemory, "Reserve Memory")
flags.Var(&opts.stopGrace, flagStopGracePeriod, "Time to wait before force killing a container") flags.Var(&opts.stopGrace, flagStopGracePeriod, "Time to wait before force killing a container")
flags.StringVar(&opts.mode, flagMode, "replicated", "Service mode (replicated or global)")
flags.Var(&opts.replicas, flagReplicas, "Number of tasks") flags.Var(&opts.replicas, flagReplicas, "Number of tasks")
flags.StringVar(&opts.restartPolicy.condition, flagRestartCondition, "", "Restart when condition is met (none, on_failure, or any)") flags.StringVar(&opts.restartPolicy.condition, flagRestartCondition, "", "Restart when condition is met (none, on_failure, or any)")

View file

@ -162,7 +162,7 @@ func updateService(spec *swarm.ServiceSpec, flags *pflag.FlagSet) error {
updateSlice(flagConstraint, &task.Placement.Constraints) updateSlice(flagConstraint, &task.Placement.Constraints)
} }
if err := updateMode(flags, &spec.Mode); err != nil { if err := updateReplicas(flags, &spec.Mode); err != nil {
return err return err
} }
@ -250,40 +250,14 @@ func updateNetworks(flags *pflag.FlagSet, attachments *[]swarm.NetworkAttachment
*attachments = localAttachments *attachments = localAttachments
} }
func updateMode(flags *pflag.FlagSet, serviceMode *swarm.ServiceMode) error { func updateReplicas(flags *pflag.FlagSet, serviceMode *swarm.ServiceMode) error {
if !flags.Changed(flagMode) && !flags.Changed(flagReplicas) { if !flags.Changed(flagReplicas) {
return nil return nil
} }
var mode string if serviceMode.Replicated == nil {
if flags.Changed(flagMode) {
mode, _ = flags.GetString(flagMode)
}
if !(mode == "replicated" || serviceMode.Replicated != nil) && flags.Changed(flagReplicas) {
return fmt.Errorf("replicas can only be used with replicated mode") return fmt.Errorf("replicas can only be used with replicated mode")
} }
serviceMode.Replicated.Replicas = flags.Lookup(flagReplicas).Value.(*Uint64Opt).Value()
if mode == "global" {
serviceMode.Replicated = nil
serviceMode.Global = &swarm.GlobalService{}
return nil
}
if flags.Changed(flagReplicas) {
replicas := flags.Lookup(flagReplicas).Value.(*Uint64Opt).Value()
serviceMode.Replicated = &swarm.ReplicatedService{Replicas: replicas}
serviceMode.Global = nil
return nil
}
if mode == "replicated" {
if serviceMode.Replicated != nil {
return nil
}
serviceMode.Replicated = &swarm.ReplicatedService{Replicas: &DefaultReplicas}
serviceMode.Global = nil
}
return nil return nil
} }