Merge pull request #475 from AliyunContainerService/start_period

Support start_period for healthcheck in Docker Compose
This commit is contained in:
Daniel Nephin 2017-08-30 14:11:43 -04:00 committed by GitHub
commit e636a5388c
7 changed files with 25 additions and 30 deletions

View File

@ -366,7 +366,6 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
return nil, nil return nil, nil
} }
var ( var (
err error
timeout, interval, startPeriod time.Duration timeout, interval, startPeriod time.Duration
retries int retries int
) )
@ -379,23 +378,14 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
}, nil }, nil
} }
if healthcheck.Timeout != "" { if healthcheck.Timeout != nil {
timeout, err = time.ParseDuration(healthcheck.Timeout) timeout = *healthcheck.Timeout
if err != nil {
return nil, err
} }
if healthcheck.Interval != nil {
interval = *healthcheck.Interval
} }
if healthcheck.Interval != "" { if healthcheck.StartPeriod != nil {
interval, err = time.ParseDuration(healthcheck.Interval) startPeriod = *healthcheck.StartPeriod
if err != nil {
return nil, err
}
}
if healthcheck.StartPeriod != "" {
startPeriod, err = time.ParseDuration(healthcheck.StartPeriod)
if err != nil {
return nil, err
}
} }
if healthcheck.Retries != nil { if healthcheck.Retries != nil {
retries = int(*healthcheck.Retries) retries = int(*healthcheck.Retries)

View File

@ -109,16 +109,18 @@ func TestConvertResourcesOnlyMemory(t *testing.T) {
func TestConvertHealthcheck(t *testing.T) { func TestConvertHealthcheck(t *testing.T) {
retries := uint64(10) retries := uint64(10)
timeout := 30 * time.Second
interval := 2 * time.Millisecond
source := &composetypes.HealthCheckConfig{ source := &composetypes.HealthCheckConfig{
Test: []string{"EXEC", "touch", "/foo"}, Test: []string{"EXEC", "touch", "/foo"},
Timeout: "30s", Timeout: &timeout,
Interval: "2ms", Interval: &interval,
Retries: &retries, Retries: &retries,
} }
expected := &container.HealthConfig{ expected := &container.HealthConfig{
Test: source.Test, Test: source.Test,
Timeout: 30 * time.Second, Timeout: timeout,
Interval: 2 * time.Millisecond, Interval: interval,
Retries: 10, Retries: 10,
} }

View File

@ -114,6 +114,7 @@ services:
interval: 10s interval: 10s
timeout: 1s timeout: 1s
retries: 5 retries: 5
start_period: 15s
# Any valid image reference - repo, tag, id, sha # Any valid image reference - repo, tag, id, sha
image: redis image: redis

View File

@ -757,9 +757,10 @@ func TestFullExample(t *testing.T) {
}, },
HealthCheck: &types.HealthCheckConfig{ HealthCheck: &types.HealthCheckConfig{
Test: types.HealthCheckTest([]string{"CMD-SHELL", "echo \"hello world\""}), Test: types.HealthCheckTest([]string{"CMD-SHELL", "echo \"hello world\""}),
Interval: "10s", Interval: durationPtr(10 * time.Second),
Timeout: "1s", Timeout: durationPtr(1 * time.Second),
Retries: uint64Ptr(5), Retries: uint64Ptr(5),
StartPeriod: durationPtr(15 * time.Second),
}, },
Hostname: "foo", Hostname: "foo",
Image: "redis", Image: "redis",

File diff suppressed because one or more lines are too long

View File

@ -316,7 +316,7 @@
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"disable": {"type": "boolean"}, "disable": {"type": "boolean"},
"interval": {"type": "string"}, "interval": {"type": "string", "format": "duration"},
"retries": {"type": "number"}, "retries": {"type": "number"},
"test": { "test": {
"oneOf": [ "oneOf": [
@ -324,7 +324,8 @@
{"type": "array", "items": {"type": "string"}} {"type": "array", "items": {"type": "string"}}
] ]
}, },
"timeout": {"type": "string"} "timeout": {"type": "string", "format": "duration"},
"start_period": {"type": "string", "format": "duration"}
} }
}, },
"deployment": { "deployment": {

View File

@ -170,10 +170,10 @@ type DeployConfig struct {
// HealthCheckConfig the healthcheck configuration for a service // HealthCheckConfig the healthcheck configuration for a service
type HealthCheckConfig struct { type HealthCheckConfig struct {
Test HealthCheckTest Test HealthCheckTest
Timeout string Timeout *time.Duration
Interval string Interval *time.Duration
Retries *uint64 Retries *uint64
StartPeriod string StartPeriod *time.Duration `mapstructure:"start_period"`
Disable bool Disable bool
} }