Fix service rollback options being cross-wired

The "update" and "rollback" configurations were cross-wired, as a result, setting
`--rollback-*` options would override the service's update-options.

Creating a service with both update, and rollback configuration:

    docker service create \
      --name=test \
      --update-failure-action=pause \
      --update-max-failure-ratio=0.6 \
      --update-monitor=3s \
      --update-order=stop-first \
      --update-parallelism=3 \
      --rollback-failure-action=continue \
      --rollback-max-failure-ratio=0.5 \
      --rollback-monitor=4s \
      --rollback-order=start-first \
      --rollback-parallelism=2 \
      --tty \
      busybox

Before this change:

    docker service inspect --format '{{json .Spec.UpdateConfig}}' test \
    && docker service inspect --format '{{json .Spec.RollbackConfig}}' test

Produces:

    {"Parallelism":3,"FailureAction":"pause","Monitor":3000000000,"MaxFailureRatio":0.6,"Order":"stop-first"}
    {"Parallelism":3,"FailureAction":"pause","Monitor":3000000000,"MaxFailureRatio":0.6,"Order":"stop-first"}

After this change:

    {"Parallelism":3,"FailureAction":"pause","Monitor":3000000000,"MaxFailureRatio":0.6,"Order":"stop-first"}
    {"Parallelism":2,"FailureAction":"continue","Monitor":4000000000,"MaxFailureRatio":0.5,"Order":"start-first"}

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2018-05-11 11:47:05 +02:00
parent ab1d49a313
commit f367aa9330
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 63 additions and 1 deletions

View File

@ -645,7 +645,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N
},
Mode: serviceMode,
UpdateConfig: options.update.updateConfig(flags),
RollbackConfig: options.update.rollbackConfig(flags),
RollbackConfig: options.rollback.rollbackConfig(flags),
EndpointSpec: options.endpoint.ToEndpointSpec(),
}

View File

@ -162,3 +162,65 @@ func TestToServiceNetwork(t *testing.T) {
assert.NilError(t, err)
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id111"}, {Target: "id555"}, {Target: "id999"}}, service.TaskTemplate.Networks))
}
func TestToServiceUpdateRollback(t *testing.T) {
expected := swarm.ServiceSpec{
UpdateConfig: &swarm.UpdateConfig{
Parallelism: 23,
Delay: 34 * time.Second,
Monitor: 54321 * time.Nanosecond,
FailureAction: "pause",
MaxFailureRatio: 0.6,
Order: "stop-first",
},
RollbackConfig: &swarm.UpdateConfig{
Parallelism: 12,
Delay: 23 * time.Second,
Monitor: 12345 * time.Nanosecond,
FailureAction: "continue",
MaxFailureRatio: 0.5,
Order: "start-first",
},
}
// Note: in test-situation, the flags are only used to detect if an option
// was set; the actual value itself is read from the serviceOptions below.
flags := newCreateCommand(nil).Flags()
flags.Set("update-parallelism", "23")
flags.Set("update-delay", "34s")
flags.Set("update-monitor", "54321ns")
flags.Set("update-failure-action", "pause")
flags.Set("update-max-failure-ratio", "0.6")
flags.Set("update-order", "stop-first")
flags.Set("rollback-parallelism", "12")
flags.Set("rollback-delay", "23s")
flags.Set("rollback-monitor", "12345ns")
flags.Set("rollback-failure-action", "continue")
flags.Set("rollback-max-failure-ratio", "0.5")
flags.Set("rollback-order", "start-first")
o := newServiceOptions()
o.mode = "replicated"
o.update = updateOptions{
parallelism: 23,
delay: 34 * time.Second,
monitor: 54321 * time.Nanosecond,
onFailure: "pause",
maxFailureRatio: 0.6,
order: "stop-first",
}
o.rollback = updateOptions{
parallelism: 12,
delay: 23 * time.Second,
monitor: 12345 * time.Nanosecond,
onFailure: "continue",
maxFailureRatio: 0.5,
order: "start-first",
}
service, err := o.ToService(context.Background(), &fakeClient{}, flags)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(service.UpdateConfig, expected.UpdateConfig))
assert.Check(t, is.DeepEqual(service.RollbackConfig, expected.RollbackConfig))
}