Skip to content

Commit c2ee139

Browse files
committed
Adding support for Rollback config in compose 3.4
Signed-off-by: Ali Al-Shabibi <alshabibi.ali@gmail.com>
1 parent 2950667 commit c2ee139

File tree

8 files changed

+86
-17
lines changed

8 files changed

+86
-17
lines changed

cli/compose/convert/service.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ func Service(
157157
Preferences: getPlacementPreference(service.Deploy.Placement.Preferences),
158158
},
159159
},
160-
EndpointSpec: endpoint,
161-
Mode: mode,
162-
UpdateConfig: convertUpdateConfig(service.Deploy.UpdateConfig),
160+
EndpointSpec: endpoint,
161+
Mode: mode,
162+
UpdateConfig: convertUpdateConfig(service.Deploy.UpdateConfig),
163+
RollbackConfig: convertUpdateConfig(service.Deploy.RollbackConfig),
163164
}
164165

165166
// add an image label to serviceSpec

cli/compose/convert/service_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ func TestConvertCredentialSpec(t *testing.T) {
342342
})
343343
assert.Error(t, err)
344344
assert.Nil(t, swarmSpec)
345+
345346
}
346347

347348
func TestConvertUpdateConfigOrder(t *testing.T) {

cli/compose/loader/full-example.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ services:
2525
mode: replicated
2626
replicas: 6
2727
labels: [FOO=BAR]
28+
rollback_config:
29+
parallelism: 3
30+
delay: 10s
31+
failure_action: continue
32+
monitor: 60s
33+
max_failure_ratio: 0.3
34+
order: start-first
2835
update_config:
2936
parallelism: 3
3037
delay: 10s

cli/compose/loader/loader_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,14 @@ func TestFullExample(t *testing.T) {
689689
MaxFailureRatio: 0.3,
690690
Order: "start-first",
691691
},
692+
RollbackConfig: &types.UpdateConfig{
693+
Parallelism: uint64Ptr(3),
694+
Delay: time.Duration(10 * time.Second),
695+
FailureAction: "continue",
696+
Monitor: time.Duration(60 * time.Second),
697+
MaxFailureRatio: 0.3,
698+
Order: "start-first",
699+
},
692700
Resources: types.Resources{
693701
Limits: &types.Resource{
694702
NanoCPUs: "0.001",

cli/compose/schema/bindata.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/compose/schema/data/config_schema_v3.4.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,20 @@
332332
"endpoint_mode": {"type": "string"},
333333
"replicas": {"type": "integer"},
334334
"labels": {"$ref": "#/definitions/list_or_dict"},
335+
"rollback_config": {
336+
"type": "object",
337+
"properties": {
338+
"parallelism": {"type": "integer"},
339+
"delay": {"type": "string", "format": "duration"},
340+
"failure_action": {"type": "string"},
341+
"monitor": {"type": "string", "format": "duration"},
342+
"max_failure_ratio": {"type": "number"},
343+
"order": {"type": "string", "enum": [
344+
"start-first", "stop-first"
345+
]}
346+
},
347+
"additionalProperties": false
348+
},
335349
"update_config": {
336350
"type": "object",
337351
"properties": {

cli/compose/schema/schema_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,40 @@ func TestValidatePlacement(t *testing.T) {
7474

7575
assert.NoError(t, Validate(config, "3.3"))
7676
}
77+
78+
func TestValidateRollbackConfig(t *testing.T) {
79+
config := dict{
80+
"version": "3.4",
81+
"services": dict{
82+
"foo": dict{
83+
"image": "busybox",
84+
"deploy": dict{
85+
"rollback_config": dict{
86+
"parallelism": 1,
87+
},
88+
},
89+
},
90+
},
91+
}
92+
93+
assert.NoError(t, Validate(config, "3.4"))
94+
}
95+
96+
func TestValidateRollbackConfigWithOrder(t *testing.T) {
97+
config := dict{
98+
"version": "3.4",
99+
"services": dict{
100+
"foo": dict{
101+
"image": "busybox",
102+
"deploy": dict{
103+
"rollback_config": dict{
104+
"parallelism": 1,
105+
"order": "start-first",
106+
},
107+
},
108+
},
109+
},
110+
}
111+
112+
assert.NoError(t, Validate(config, "3.4"))
113+
}

cli/compose/types/types.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,15 @@ type LoggingConfig struct {
157157

158158
// DeployConfig the deployment configuration for a service
159159
type DeployConfig struct {
160-
Mode string
161-
Replicas *uint64
162-
Labels Labels
163-
UpdateConfig *UpdateConfig `mapstructure:"update_config"`
164-
Resources Resources
165-
RestartPolicy *RestartPolicy `mapstructure:"restart_policy"`
166-
Placement Placement
167-
EndpointMode string `mapstructure:"endpoint_mode"`
160+
Mode string
161+
Replicas *uint64
162+
Labels Labels
163+
UpdateConfig *UpdateConfig `mapstructure:"update_config"`
164+
RollbackConfig *UpdateConfig `mapstructure:"rollback_config"`
165+
Resources Resources
166+
RestartPolicy *RestartPolicy `mapstructure:"restart_policy"`
167+
Placement Placement
168+
EndpointMode string `mapstructure:"endpoint_mode"`
168169
}
169170

170171
// HealthCheckConfig the healthcheck configuration for a service

0 commit comments

Comments
 (0)