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

View File

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

View File

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

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

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