mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
f1f2461e09
Change `docker service update` to replace attributes of the target
service rather than augment them. One particular occurrence where the
previous behavior proved problematic is when trying to update a port
mapping: the merge semantics provided no way of removing published
ports, but strictly of adding more.
The utility merge* functions where renamed accordingly to update*.
Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>
(cherry picked from commit 1f8ab93b44
)
39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
// +build !windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"github.com/docker/docker/pkg/integration/checker"
|
|
"github.com/docker/engine-api/types/swarm"
|
|
"github.com/go-check/check"
|
|
)
|
|
|
|
func setPortConfig(portConfig []swarm.PortConfig) serviceConstructor {
|
|
return func(s *swarm.Service) {
|
|
if s.Spec.EndpointSpec == nil {
|
|
s.Spec.EndpointSpec = &swarm.EndpointSpec{}
|
|
}
|
|
s.Spec.EndpointSpec.Ports = portConfig
|
|
}
|
|
}
|
|
|
|
func (s *DockerSwarmSuite) TestApiServiceUpdatePort(c *check.C) {
|
|
d := s.AddDaemon(c, true, true)
|
|
|
|
// Create a service with a port mapping of 8080:8081.
|
|
portConfig := []swarm.PortConfig{{TargetPort: 8081, PublishedPort: 8080}}
|
|
serviceID := d.createService(c, simpleTestService, setInstances(1), setPortConfig(portConfig))
|
|
waitAndAssert(c, defaultReconciliationTimeout, d.checkActiveContainerCount, checker.Equals, 1)
|
|
|
|
// Update the service: changed the port mapping from 8080:8081 to 8082:8083.
|
|
updatedPortConfig := []swarm.PortConfig{{TargetPort: 8083, PublishedPort: 8082}}
|
|
remoteService := d.getService(c, serviceID)
|
|
d.updateService(c, remoteService, setPortConfig(updatedPortConfig))
|
|
|
|
// Inspect the service and verify port mapping.
|
|
updatedService := d.getService(c, serviceID)
|
|
c.Assert(updatedService.Spec.EndpointSpec, check.NotNil)
|
|
c.Assert(len(updatedService.Spec.EndpointSpec.Ports), check.Equals, 1)
|
|
c.Assert(updatedService.Spec.EndpointSpec.Ports[0].TargetPort, check.Equals, uint32(8083))
|
|
c.Assert(updatedService.Spec.EndpointSpec.Ports[0].PublishedPort, check.Equals, uint32(8082))
|
|
}
|