fix --update-order and --rollback-order flags

Signed-off-by: Jim Lin <b04705003@ntu.edu.tw>
(cherry picked from commit 26a6a724aa)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Jim Lin 2021-01-18 22:33:45 +08:00 committed by Sebastiaan van Stijn
parent 48d30b5b32
commit 1fdf84b8e9
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 18 additions and 2 deletions

View File

@ -165,7 +165,7 @@ func updateConfigFromDefaults(defaultUpdateConfig *api.UpdateConfig) *swarm.Upda
}
func (opts updateOptions) updateConfig(flags *pflag.FlagSet) *swarm.UpdateConfig {
if !anyChanged(flags, flagUpdateParallelism, flagUpdateDelay, flagUpdateMonitor, flagUpdateFailureAction, flagUpdateMaxFailureRatio) {
if !anyChanged(flags, flagUpdateParallelism, flagUpdateDelay, flagUpdateMonitor, flagUpdateFailureAction, flagUpdateMaxFailureRatio, flagUpdateOrder) {
return nil
}
@ -194,7 +194,7 @@ func (opts updateOptions) updateConfig(flags *pflag.FlagSet) *swarm.UpdateConfig
}
func (opts updateOptions) rollbackConfig(flags *pflag.FlagSet) *swarm.UpdateConfig {
if !anyChanged(flags, flagRollbackParallelism, flagRollbackDelay, flagRollbackMonitor, flagRollbackFailureAction, flagRollbackMaxFailureRatio) {
if !anyChanged(flags, flagRollbackParallelism, flagRollbackDelay, flagRollbackMonitor, flagRollbackFailureAction, flagRollbackMaxFailureRatio, flagRollbackOrder) {
return nil
}

View File

@ -289,6 +289,22 @@ func TestToServiceUpdateRollback(t *testing.T) {
assert.Check(t, is.DeepEqual(service.RollbackConfig, expected.RollbackConfig))
}
func TestToServiceUpdateRollbackOrder(t *testing.T) {
flags := newCreateCommand(nil).Flags()
flags.Set("update-order", "start-first")
flags.Set("rollback-order", "start-first")
o := newServiceOptions()
o.mode = "replicated"
o.update = updateOptions{order: "start-first"}
o.rollback = updateOptions{order: "start-first"}
service, err := o.ToService(context.Background(), &fakeClient{}, flags)
assert.NilError(t, err)
assert.Check(t, is.Equal(service.UpdateConfig.Order, o.update.order))
assert.Check(t, is.Equal(service.RollbackConfig.Order, o.rollback.order))
}
func TestToServiceMaxReplicasGlobalModeConflict(t *testing.T) {
opt := serviceOptions{
mode: "global",