mirror of https://github.com/docker/cli.git
Change the type of interval, timeout and start_period of healthcheck from string to * time.Duration
Signed-off-by: Li Yi <denverdino@gmail.com>
This commit is contained in:
parent
0abdad615f
commit
e02fcfd34e
|
@ -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)
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -757,10 +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: "15s",
|
StartPeriod: durationPtr(15 * time.Second),
|
||||||
},
|
},
|
||||||
Hostname: "foo",
|
Hostname: "foo",
|
||||||
Image: "redis",
|
Image: "redis",
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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,8 +324,8 @@
|
||||||
{"type": "array", "items": {"type": "string"}}
|
{"type": "array", "items": {"type": "string"}}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"timeout": {"type": "string"},
|
"timeout": {"type": "string", "format": "duration"},
|
||||||
"start_period": {"type": "string"}
|
"start_period": {"type": "string", "format": "duration"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"deployment": {
|
"deployment": {
|
||||||
|
|
|
@ -169,10 +169,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 `mapstructure:"start_period"`
|
StartPeriod *time.Duration `mapstructure:"start_period"`
|
||||||
Disable bool
|
Disable bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue