Skip to content

Commit

Permalink
Support for rollback config in compose 3.7
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Al-Shabibi <alshabibi.ali@gmail.com>
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
  • Loading branch information
alshabib authored and vdemeester committed May 29, 2018
1 parent 824a0b4 commit 53a4921
Show file tree
Hide file tree
Showing 9 changed files with 815 additions and 49 deletions.
7 changes: 4 additions & 3 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,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
14 changes: 14 additions & 0 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,17 @@ func (c *fakeClient) ConfigList(ctx context.Context, options types.ConfigListOpt
}
return []swarm.Config{}, nil
}

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

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

// Non default value
updateConfig = convertUpdateConfig(&composetypes.UpdateConfig{
Parallelism: &parallel,
})
assert.Check(t, is.Equal(parallel, updateConfig.Parallelism))
}
9 changes: 8 additions & 1 deletion cli/compose/loader/full-example.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.6"
version: "3.7"

services:
foo:
Expand Down Expand Up @@ -39,6 +39,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
19 changes: 17 additions & 2 deletions cli/compose/loader/full-struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func fullExampleConfig(workingDir, homeDir string) *types.Config {
return &types.Config{
Version: "3.6",
Version: "3.7",
Services: services(workingDir, homeDir),
Networks: networks(),
Volumes: volumes(),
Expand Down Expand Up @@ -41,6 +41,14 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
Mode: "replicated",
Replicas: uint64Ptr(6),
Labels: map[string]string{"FOO": "BAR"},
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",
},
UpdateConfig: &types.UpdateConfig{
Parallelism: uint64Ptr(3),
Delay: time.Duration(10 * time.Second),
Expand Down Expand Up @@ -393,7 +401,7 @@ func volumes() map[string]types.VolumeConfig {
}

func fullExampleYAML(workingDir string) string {
return fmt.Sprintf(`version: "3.6"
return fmt.Sprintf(`version: "3.7"
services:
foo:
build:
Expand Down Expand Up @@ -436,6 +444,13 @@ services:
monitor: 1m0s
max_failure_ratio: 0.3
order: start-first
rollback_config:
parallelism: 3
delay: 10s
failure_action: continue
monitor: 1m0s
max_failure_ratio: 0.3
order: start-first
resources:
limits:
cpus: "0.001"
Expand Down
2 changes: 1 addition & 1 deletion cli/compose/loader/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestMarshallConfig(t *testing.T) {
assert.Check(t, is.Equal(expected, string(actual)))

// Make sure the expected still
dict, err := ParseYAML([]byte("version: '3.6'\n" + expected))
dict, err := ParseYAML([]byte("version: '3.7'\n" + expected))
assert.NilError(t, err)
_, err = Load(buildConfigDetails(dict, map[string]string{}))
assert.NilError(t, err)
Expand Down
111 changes: 77 additions & 34 deletions cli/compose/schema/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 53a4921

Please sign in to comment.