Skip to content

Commit a3205d1

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 a3205d1

File tree

8 files changed

+148
-12
lines changed

8 files changed

+148
-12
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: 16 additions & 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) {
@@ -361,3 +362,18 @@ func TestConvertUpdateConfigOrder(t *testing.T) {
361362
})
362363
assert.Equal(t, updateConfig.Order, "stop-first")
363364
}
365+
366+
func TestConvertUpdateConfigParallelism(t *testing.T) {
367+
parallel := uint64(4)
368+
369+
// test default behavior
370+
updateConfig := convertUpdateConfig(&composetypes.UpdateConfig{})
371+
assert.Equal(t, 1, updateConfig.Parallelism)
372+
373+
// Non default value
374+
updateConfig = convertUpdateConfig(&composetypes.UpdateConfig{
375+
Parallelism: &parallel,
376+
})
377+
assert.Equal(t, updateConfig.Parallelism, parallel)
378+
379+
}

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: 1 addition & 1 deletion
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: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,92 @@ 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+
}
114+
115+
func TestValidateRollbackConfigWithUpdateConfig(t *testing.T) {
116+
config := dict{
117+
"version": "3.4",
118+
"services": dict{
119+
"foo": dict{
120+
"image": "busybox",
121+
"deploy": dict{
122+
"update_config": dict{
123+
"parallelism": 1,
124+
"order": "start-first",
125+
},
126+
"rollback_config": dict{
127+
"parallelism": 1,
128+
"order": "start-first",
129+
},
130+
},
131+
},
132+
},
133+
}
134+
135+
assert.NoError(t, Validate(config, "3.4"))
136+
}
137+
138+
func TestValidateRollbackConfigWithUpdateConfigFull(t *testing.T) {
139+
config := dict{
140+
"version": "3.4",
141+
"services": dict{
142+
"foo": dict{
143+
"image": "busybox",
144+
"deploy": dict{
145+
"update_config": dict{
146+
"parallelism": 1,
147+
"order": "start-first",
148+
"delay": "10s",
149+
"failure_action": "pause",
150+
"monitor": "10s",
151+
},
152+
"rollback_config": dict{
153+
"parallelism": 1,
154+
"order": "start-first",
155+
"delay": "10s",
156+
"failure_action": "pause",
157+
"monitor": "10s",
158+
},
159+
},
160+
},
161+
},
162+
}
163+
164+
assert.NoError(t, Validate(config, "3.4"))
165+
}

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)