mirror of https://github.com/docker/cli.git
internal/test/builders: don't set EndpointSpec by default
Also rewrite `Service()` to use the available options Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
1de18a9b98
commit
270defa177
|
@ -6,20 +6,12 @@ import (
|
||||||
|
|
||||||
// Service creates a service with default values.
|
// Service creates a service with default values.
|
||||||
// Any number of service builder functions can be passed to augment it.
|
// Any number of service builder functions can be passed to augment it.
|
||||||
// Currently, only ServiceName is implemented
|
|
||||||
func Service(builders ...func(*swarm.Service)) *swarm.Service {
|
func Service(builders ...func(*swarm.Service)) *swarm.Service {
|
||||||
service := &swarm.Service{
|
service := &swarm.Service{}
|
||||||
ID: "serviceID",
|
defaults := []func(*swarm.Service){ServiceID("serviceID"), ServiceName("defaultServiceName")}
|
||||||
Spec: swarm.ServiceSpec{
|
|
||||||
Annotations: swarm.Annotations{
|
|
||||||
Name: "defaultServiceName",
|
|
||||||
},
|
|
||||||
EndpointSpec: &swarm.EndpointSpec{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, builder := range builders {
|
for _, opt := range append(defaults, builders...) {
|
||||||
builder(service)
|
opt(service)
|
||||||
}
|
}
|
||||||
|
|
||||||
return service
|
return service
|
||||||
|
@ -77,13 +69,19 @@ func ServiceStatus(desired, running uint64) func(*swarm.Service) {
|
||||||
// ServiceImage sets the service's image
|
// ServiceImage sets the service's image
|
||||||
func ServiceImage(image string) func(*swarm.Service) {
|
func ServiceImage(image string) func(*swarm.Service) {
|
||||||
return func(service *swarm.Service) {
|
return func(service *swarm.Service) {
|
||||||
service.Spec.TaskTemplate = swarm.TaskSpec{ContainerSpec: &swarm.ContainerSpec{Image: image}}
|
if service.Spec.TaskTemplate.ContainerSpec == nil {
|
||||||
|
service.Spec.TaskTemplate.ContainerSpec = &swarm.ContainerSpec{}
|
||||||
|
}
|
||||||
|
service.Spec.TaskTemplate.ContainerSpec.Image = image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServicePort sets the service's port
|
// ServicePort sets the service's port
|
||||||
func ServicePort(port swarm.PortConfig) func(*swarm.Service) {
|
func ServicePort(port swarm.PortConfig) func(*swarm.Service) {
|
||||||
return func(service *swarm.Service) {
|
return func(service *swarm.Service) {
|
||||||
|
if service.Spec.EndpointSpec == nil {
|
||||||
|
service.Spec.EndpointSpec = &swarm.EndpointSpec{}
|
||||||
|
}
|
||||||
service.Spec.EndpointSpec.Ports = append(service.Spec.EndpointSpec.Ports, port)
|
service.Spec.EndpointSpec.Ports = append(service.Spec.EndpointSpec.Ports, port)
|
||||||
|
|
||||||
assignedPort := port
|
assignedPort := port
|
||||||
|
|
Loading…
Reference in New Issue