mirror of https://github.com/docker/cli.git
Fix stack deploy re-deploying service after --force
When updating a service with the `--force` option, the `ForceUpdate` property of the taskspec is incremented. Stack deploy did not take this into account, and reset this field to its default value (0), causing the service to be re-deployed. This patch copies the existing value before updating the service. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c1b58a9096
commit
76439457d2
|
@ -249,6 +249,12 @@ func deployServices(
|
||||||
// service update.
|
// service update.
|
||||||
serviceSpec.TaskTemplate.ContainerSpec.Image = service.Spec.TaskTemplate.ContainerSpec.Image
|
serviceSpec.TaskTemplate.ContainerSpec.Image = service.Spec.TaskTemplate.ContainerSpec.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stack deploy does not have a `--force` option. Preserve existing ForceUpdate
|
||||||
|
// value so that tasks are not re-deployed if not updated.
|
||||||
|
// TODO move this to API client?
|
||||||
|
serviceSpec.TaskTemplate.ForceUpdate = service.Spec.TaskTemplate.ForceUpdate
|
||||||
|
|
||||||
response, err := apiClient.ServiceUpdate(
|
response, err := apiClient.ServiceUpdate(
|
||||||
ctx,
|
ctx,
|
||||||
service.ID,
|
service.ID,
|
||||||
|
|
|
@ -27,7 +27,8 @@ func TestPruneServices(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestServiceUpdateResolveImageChanged tests that the service's
|
// TestServiceUpdateResolveImageChanged tests that the service's
|
||||||
// image digest is preserved if the image did not change in the compose file
|
// image digest, and "ForceUpdate" is preserved if the image did not change in
|
||||||
|
// the compose file
|
||||||
func TestServiceUpdateResolveImageChanged(t *testing.T) {
|
func TestServiceUpdateResolveImageChanged(t *testing.T) {
|
||||||
namespace := convert.NewNamespace("mystack")
|
namespace := convert.NewNamespace("mystack")
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) {
|
||||||
ContainerSpec: &swarm.ContainerSpec{
|
ContainerSpec: &swarm.ContainerSpec{
|
||||||
Image: "foobar:1.2.3@sha256:deadbeef",
|
Image: "foobar:1.2.3@sha256:deadbeef",
|
||||||
},
|
},
|
||||||
|
ForceUpdate: 123,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -65,18 +67,21 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) {
|
||||||
image string
|
image string
|
||||||
expectedQueryRegistry bool
|
expectedQueryRegistry bool
|
||||||
expectedImage string
|
expectedImage string
|
||||||
|
expectedForceUpdate uint64
|
||||||
}{
|
}{
|
||||||
// Image not changed
|
// Image not changed
|
||||||
{
|
{
|
||||||
image: "foobar:1.2.3",
|
image: "foobar:1.2.3",
|
||||||
expectedQueryRegistry: false,
|
expectedQueryRegistry: false,
|
||||||
expectedImage: "foobar:1.2.3@sha256:deadbeef",
|
expectedImage: "foobar:1.2.3@sha256:deadbeef",
|
||||||
|
expectedForceUpdate: 123,
|
||||||
},
|
},
|
||||||
// Image changed
|
// Image changed
|
||||||
{
|
{
|
||||||
image: "foobar:1.2.4",
|
image: "foobar:1.2.4",
|
||||||
expectedQueryRegistry: true,
|
expectedQueryRegistry: true,
|
||||||
expectedImage: "foobar:1.2.4",
|
expectedImage: "foobar:1.2.4",
|
||||||
|
expectedForceUpdate: 123,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +100,9 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) {
|
||||||
}
|
}
|
||||||
err := deployServices(ctx, client, spec, namespace, false, ResolveImageChanged)
|
err := deployServices(ctx, client, spec, namespace, false, ResolveImageChanged)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, is.Equal(testcase.expectedQueryRegistry, receivedOptions.QueryRegistry))
|
assert.Check(t, is.Equal(receivedOptions.QueryRegistry, testcase.expectedQueryRegistry))
|
||||||
assert.Check(t, is.Equal(testcase.expectedImage, receivedService.TaskTemplate.ContainerSpec.Image))
|
assert.Check(t, is.Equal(receivedService.TaskTemplate.ContainerSpec.Image, testcase.expectedImage))
|
||||||
|
assert.Check(t, is.Equal(receivedService.TaskTemplate.ForceUpdate, testcase.expectedForceUpdate))
|
||||||
|
|
||||||
receivedService = swarm.ServiceSpec{}
|
receivedService = swarm.ServiceSpec{}
|
||||||
receivedOptions = types.ServiceUpdateOptions{}
|
receivedOptions = types.ServiceUpdateOptions{}
|
||||||
|
|
Loading…
Reference in New Issue