Skip to content

Commit

Permalink
Adding support for Rollback config in compose 3.4
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Al-Shabibi <[email protected]>
  • Loading branch information
alshabib committed Jul 29, 2017
1 parent 2950667 commit 4e745bd
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 12 deletions.
7 changes: 4 additions & 3 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ func Service(
Preferences: getPlacementPreference(service.Deploy.Placement.Preferences),
},
},
EndpointSpec: endpoint,
Mode: mode,
UpdateConfig: convertUpdateConfig(service.Deploy.UpdateConfig),
EndpointSpec: endpoint,
Mode: mode,
UpdateConfig: convertUpdateConfig(service.Deploy.UpdateConfig),
RollbackConfig: convertUpdateConfig(service.Deploy.RollbackConfig),
}

// add an image label to serviceSpec
Expand Down
1 change: 1 addition & 0 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func TestConvertCredentialSpec(t *testing.T) {
})
assert.Error(t, err)
assert.Nil(t, swarmSpec)

}

func TestConvertUpdateConfigOrder(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions cli/compose/loader/full-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ services:
mode: replicated
replicas: 6
labels: [FOO=BAR]
rollback_config:
parallelism: 3
delay: 10s
failure_action: continue
monitor: 60s
max_failure_ratio: 0.3
order: start-first
update_config:
parallelism: 3
delay: 10s
Expand Down
8 changes: 8 additions & 0 deletions cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,14 @@ func TestFullExample(t *testing.T) {
MaxFailureRatio: 0.3,
Order: "start-first",
},
RollbackConfig: &types.UpdateConfig{
Parallelism: uint64Ptr(3),
Delay: time.Duration(10 * time.Second),
FailureAction: "continue",
Monitor: time.Duration(60 * time.Second),
MaxFailureRatio: 0.3,
Order: "start-first",
},
Resources: types.Resources{
Limits: &types.Resource{
NanoCPUs: "0.001",
Expand Down
2 changes: 1 addition & 1 deletion cli/compose/schema/bindata.go

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions cli/compose/schema/data/config_schema_v3.4.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,20 @@
"endpoint_mode": {"type": "string"},
"replicas": {"type": "integer"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"rollback_config": {
"type": "object",
"properties": {
"parallelism": {"type": "integer"},
"delay": {"type": "string", "format": "duration"},
"failure_action": {"type": "string"},
"monitor": {"type": "string", "format": "duration"},
"max_failure_ratio": {"type": "number"},
"order": {"type": "string", "enum": [
"start-first", "stop-first"
]}
},
"additionalProperties": false
},
"update_config": {
"type": "object",
"properties": {
Expand Down
37 changes: 37 additions & 0 deletions cli/compose/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,40 @@ func TestValidatePlacement(t *testing.T) {

assert.NoError(t, Validate(config, "3.3"))
}

func TestValidateRollbackConfig(t *testing.T) {
config := dict{
"version": "3.4",
"services": dict{
"foo": dict{
"image": "busybox",
"deploy": dict{
"rollback_config": dict{
"parallelism": 1,
},
},
},
},
}

assert.NoError(t, Validate(config, "3.4"))
}

func TestValidateRollbackConfigWithOrder(t *testing.T) {
config := dict{
"version": "3.4",
"services": dict{
"foo": dict{
"image": "busybox",
"deploy": dict{
"rollback_config": dict{
"parallelism": 1,
"order": "start-first",
},
},
},
},
}

assert.NoError(t, Validate(config, "3.4"))
}
17 changes: 9 additions & 8 deletions cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ type LoggingConfig struct {

// DeployConfig the deployment configuration for a service
type DeployConfig struct {
Mode string
Replicas *uint64
Labels Labels
UpdateConfig *UpdateConfig `mapstructure:"update_config"`
Resources Resources
RestartPolicy *RestartPolicy `mapstructure:"restart_policy"`
Placement Placement
EndpointMode string `mapstructure:"endpoint_mode"`
Mode string
Replicas *uint64
Labels Labels
UpdateConfig *UpdateConfig `mapstructure:"update_config"`
RollbackConfig *UpdateConfig `mapstructure:"rollback_config"`
Resources Resources
RestartPolicy *RestartPolicy `mapstructure:"restart_policy"`
Placement Placement
EndpointMode string `mapstructure:"endpoint_mode"`
}

// HealthCheckConfig the healthcheck configuration for a service
Expand Down

0 comments on commit 4e745bd

Please sign in to comment.