Skip to content

Commit

Permalink
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 Aug 1, 2017
1 parent 1cd402b commit e16b999
Show file tree
Hide file tree
Showing 8 changed files with 148 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 @@ -158,9 +158,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
16 changes: 16 additions & 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 All @@ -361,3 +362,18 @@ func TestConvertUpdateConfigOrder(t *testing.T) {
})
assert.Equal(t, updateConfig.Order, "stop-first")
}

func TestConvertUpdateConfigParallelism(t *testing.T) {
parallel := uint64(4)

// test default behavior
updateConfig := convertUpdateConfig(&composetypes.UpdateConfig{})
assert.Equal(t, uint64(1), updateConfig.Parallelism)

// Non default value
updateConfig = convertUpdateConfig(&composetypes.UpdateConfig{
Parallelism: &parallel,
})
assert.Equal(t, parallel, updateConfig.Parallelism)

}
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
89 changes: 89 additions & 0 deletions cli/compose/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,92 @@ 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"))
}

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

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

func TestValidateRollbackConfigWithUpdateConfigFull(t *testing.T) {
config := dict{
"version": "3.4",
"services": dict{
"foo": dict{
"image": "busybox",
"deploy": dict{
"update_config": dict{
"parallelism": 1,
"order": "start-first",
"delay": "10s",
"failure_action": "pause",
"monitor": "10s",
},
"rollback_config": dict{
"parallelism": 1,
"order": "start-first",
"delay": "10s",
"failure_action": "pause",
"monitor": "10s",
},
},
},
},
}

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 @@ -156,14 +156,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 e16b999

Please sign in to comment.