mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
add endpoint mode a default value
Signed-off-by: allencloud <allen.sun@daocloud.io>
This commit is contained in:
parent
3c32e1775a
commit
9eacabbfb7
3 changed files with 34 additions and 24 deletions
|
@ -346,6 +346,25 @@ func newServiceOptions() *serviceOptions {
|
|||
}
|
||||
}
|
||||
|
||||
func (opts *serviceOptions) ToServiceMode() (swarm.ServiceMode, error) {
|
||||
serviceMode := swarm.ServiceMode{}
|
||||
switch opts.mode {
|
||||
case "global":
|
||||
if opts.replicas.Value() != nil {
|
||||
return serviceMode, fmt.Errorf("replicas can only be used with replicated mode")
|
||||
}
|
||||
|
||||
serviceMode.Global = &swarm.GlobalService{}
|
||||
case "replicated":
|
||||
serviceMode.Replicated = &swarm.ReplicatedService{
|
||||
Replicas: opts.replicas.Value(),
|
||||
}
|
||||
default:
|
||||
return serviceMode, fmt.Errorf("Unknown mode: %s, only replicated and global supported", opts.mode)
|
||||
}
|
||||
return serviceMode, nil
|
||||
}
|
||||
|
||||
func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
||||
var service swarm.ServiceSpec
|
||||
|
||||
|
@ -368,6 +387,16 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
|||
currentEnv = append(currentEnv, env)
|
||||
}
|
||||
|
||||
healthConfig, err := opts.healthcheck.toHealthConfig()
|
||||
if err != nil {
|
||||
return service, err
|
||||
}
|
||||
|
||||
serviceMode, err := opts.ToServiceMode()
|
||||
if err != nil {
|
||||
return service, err
|
||||
}
|
||||
|
||||
service = swarm.ServiceSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
Name: opts.name,
|
||||
|
@ -393,6 +422,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
|||
Hosts: convertExtraHostsToSwarmHosts(opts.hosts.GetAll()),
|
||||
StopGracePeriod: opts.stopGrace.Value(),
|
||||
Secrets: nil,
|
||||
Healthcheck: healthConfig,
|
||||
},
|
||||
Networks: convertNetworks(opts.networks.GetAll()),
|
||||
Resources: opts.resources.ToResourceRequirements(),
|
||||
|
@ -403,7 +433,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
|||
LogDriver: opts.logDriver.toLogDriver(),
|
||||
},
|
||||
Networks: convertNetworks(opts.networks.GetAll()),
|
||||
Mode: swarm.ServiceMode{},
|
||||
Mode: serviceMode,
|
||||
UpdateConfig: &swarm.UpdateConfig{
|
||||
Parallelism: opts.update.parallelism,
|
||||
Delay: opts.update.delay,
|
||||
|
@ -414,26 +444,6 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
|||
EndpointSpec: opts.endpoint.ToEndpointSpec(),
|
||||
}
|
||||
|
||||
healthConfig, err := opts.healthcheck.toHealthConfig()
|
||||
if err != nil {
|
||||
return service, err
|
||||
}
|
||||
service.TaskTemplate.ContainerSpec.Healthcheck = healthConfig
|
||||
|
||||
switch opts.mode {
|
||||
case "global":
|
||||
if opts.replicas.Value() != nil {
|
||||
return service, fmt.Errorf("replicas can only be used with replicated mode")
|
||||
}
|
||||
|
||||
service.Mode.Global = &swarm.GlobalService{}
|
||||
case "replicated":
|
||||
service.Mode.Replicated = &swarm.ReplicatedService{
|
||||
Replicas: opts.replicas.Value(),
|
||||
}
|
||||
default:
|
||||
return service, fmt.Errorf("Unknown mode: %s", opts.mode)
|
||||
}
|
||||
return service, nil
|
||||
}
|
||||
|
||||
|
@ -465,7 +475,7 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
|
|||
flags.StringVar(&opts.update.onFailure, flagUpdateFailureAction, "pause", "Action on update failure (pause|continue)")
|
||||
flags.Var(&opts.update.maxFailureRatio, flagUpdateMaxFailureRatio, "Failure rate to tolerate during an update")
|
||||
|
||||
flags.StringVar(&opts.endpoint.mode, flagEndpointMode, "", "Endpoint mode (vip or dnsrr)")
|
||||
flags.StringVar(&opts.endpoint.mode, flagEndpointMode, "vip", "Endpoint mode (vip or dnsrr)")
|
||||
|
||||
flags.BoolVar(&opts.registryAuth, flagRegistryAuth, false, "Send registry authentication details to swarm agents")
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ Options:
|
|||
--dns list Set custom DNS servers (default [])
|
||||
--dns-option list Set DNS options (default [])
|
||||
--dns-search list Set custom DNS search domains (default [])
|
||||
--endpoint-mode string Endpoint mode (vip or dnsrr)
|
||||
--endpoint-mode string Endpoint mode (vip or dnsrr) (default "vip")
|
||||
-e, --env list Set environment variables (default [])
|
||||
--env-file list Read in a file of environment variables (default [])
|
||||
--group list Set one or more supplementary user groups for the container (default [])
|
||||
|
|
|
@ -32,7 +32,7 @@ Options:
|
|||
--dns-rm list Remove a custom DNS server (default [])
|
||||
--dns-search-add list Add or update a custom DNS search domain (default [])
|
||||
--dns-search-rm list Remove a DNS search domain (default [])
|
||||
--endpoint-mode string Endpoint mode (vip or dnsrr)
|
||||
--endpoint-mode string Endpoint mode (vip or dnsrr) (default "vip")
|
||||
--env-add list Add or update an environment variable (default [])
|
||||
--env-rm list Remove an environment variable (default [])
|
||||
--force Force update even if no changes require it
|
||||
|
|
Loading…
Reference in a new issue