Support for rollback config in compose 3.7

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2018-05-29 11:37:51 +02:00
parent df6e38b81a
commit 4e6e5d583c
No known key found for this signature in database
GPG Key ID: 083CC6FD6EB699A3
9 changed files with 192 additions and 51 deletions

View File

@ -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

View File

@ -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))
}

View File

@ -1,4 +1,4 @@
version: "3.6"
version: "3.7"
services:
foo:
@ -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

View File

@ -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(),
@ -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),
@ -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:
@ -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"

View File

@ -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)

View File

@ -467,44 +467,44 @@ DoTuq9lAU9Q4O1xV/59X/w8AAP//zRo7vm9CAAA=
"/data/config_schema_v3.7.json": {
local: "data/config_schema_v3.7.json",
size: 17007,
size: 17540,
modtime: 1518458244,
compressed: `
H4sIAAAAAAAC/+xbS4/jNhK++1cYTG7pxwAb7GLntsc97Z634RFoqmwzTZFMkfK0M/B/X+jZEkWKtK2e
7iATIJi2VHzUg1VfFUvfVus1+dmwAxSUfF6Tg7X68+Pjb0bJ++bpg8L9Y450Z+8//frYPPuJ3FXjeF4N
YUru+D5r3mTHvz3846Ea3pDYk4aKSG1/A2abZwi/lxyhGvxEjoCGK0k2d6vqnUalAS0HQz6vq82t1z1J
92AwrbHI5Z7Uj8/1DOs1MYBHzgYz9Fv96fF1/see7M6ddbDZ+rmm1gLK/073Vr/+8kTv//jX/f8+3f/z
Ibvf/PLz6HUlX4Rds3wO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yXzxtDeqgHNAHpf7H2R+Fyd
7DnDOVu+pgXEqq7O9S0MSYO9IPM9FKH+BqbJxroJciGWylDw4AZOYeSFYJBZVzodJh1CJ9Af8+LDsAJk
aa6FnQTN5cDV7hQbtKN0VyhzJjSgtC3oaXBB2JRTgmYSgzNA5PXVVRQoQVCcUaJDwO+G4j1KzjeEPmdt
W9MlYHsGZSuChHPgTBcxqDXNgZPjVZbT3EERxkuEjNCIq45WV4IZidcvWZDXrFu2Jgn4beOnmINvTRD1
+WHjxsYz7rcMtWnKC1K1v43D+slbsomt8p+PBJUTA58m8WkSw8pbjfn1UubgTO6X6dxTZew9RFpAIUON
G7eX8i2VI+gKJvguFj+KABzUOxCAjGYja/AcOVPaN7odud2yG+whOWtSxyXMm0rR7CMm8twY6qq4Q4yB
QhkdFVpfmMjly+UwawFpK04oWNDsVkFrg4QJc3EPgi0WhbAFBEFh1i2ntaCZetByhXaFQPJ3uAq6Vfk3
JIPOcDOH56cDJonhWHsOrfm1NdMomDNNEQz0K/f9hqt4S5i3gvS5rVUFA3V6ILyMuNu4qhvEVxOIGHxy
fp4U0mlHtkCCFtN4FdUe1FJlUi1/PxFuAVqHq+NMkWKpCBvdMJU6E4aPEDvLjfCUnz927LybNkV6tPrU
F6Tuelmto1XsdYzl9l/XxuxLRVcRjRhD6D6q3nZh2eOGk2hSXneGqpbqM1JdEKn+7Hb942yw/dIy+DVf
TRX+OPIGy4v4LOID6PWd1TU5DJ3qaqk+1fXe6rKaVQZqm16uzEkyuqN2NbxL6bdhkzn+fwNfBuPdlO+K
z1q0FeI85wueHw+/zCDFuc73N4JYC7QJunVqlShWfVOg/Xm2P0Z04ycfa1d8iuPk8u/7uDGk+dB6PZKP
RdJ8cDI4sNdRia/rE267LaX7lNrTKTfODlfV39Pq/wEAAP//il2qfYREAAA=
`,
},

View File

@ -348,6 +348,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": {

View File

@ -114,3 +114,92 @@ func TestValidateIsolation(t *testing.T) {
}
assert.NilError(t, Validate(config, "3.5"))
}
func TestValidateRollbackConfig(t *testing.T) {
config := dict{
"version": "3.4",
"services": dict{
"foo": dict{
"image": "busybox",
"deploy": dict{
"rollback_config": dict{
"parallelism": 1,
},
},
},
},
}
assert.NilError(t, Validate(config, "3.7"))
}
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.NilError(t, Validate(config, "3.7"))
}
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.NilError(t, Validate(config, "3.7"))
}
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.NilError(t, Validate(config, "3.7"))
}

View File

@ -190,14 +190,15 @@ type LoggingConfig struct {
// DeployConfig the deployment configuration for a service
type DeployConfig struct {
Mode string `yaml:",omitempty"`
Replicas *uint64 `yaml:",omitempty"`
Labels Labels `yaml:",omitempty"`
UpdateConfig *UpdateConfig `mapstructure:"update_config" yaml:"update_config,omitempty"`
Resources Resources `yaml:",omitempty"`
RestartPolicy *RestartPolicy `mapstructure:"restart_policy" yaml:"restart_policy,omitempty"`
Placement Placement `yaml:",omitempty"`
EndpointMode string `mapstructure:"endpoint_mode" yaml:"endpoint_mode,omitempty"`
Mode string `yaml:",omitempty"`
Replicas *uint64 `yaml:",omitempty"`
Labels Labels `yaml:",omitempty"`
UpdateConfig *UpdateConfig `mapstructure:"update_config" yaml:"update_config,omitempty"`
RollbackConfig *UpdateConfig `mapstructure:"rollback_config" yaml:"rollback_config,omitempty"`
Resources Resources `yaml:",omitempty"`
RestartPolicy *RestartPolicy `mapstructure:"restart_policy" yaml:"restart_policy,omitempty"`
Placement Placement `yaml:",omitempty"`
EndpointMode string `mapstructure:"endpoint_mode" yaml:"endpoint_mode,omitempty"`
}
// HealthCheckConfig the healthcheck configuration for a service