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
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -757,10 +757,10 @@ func TestFullExample(t *testing.T) {
|
|||
},
|
||||
HealthCheck: &types.HealthCheckConfig{
|
||||
Test: types.HealthCheckTest([]string{"CMD-SHELL", "echo \"hello world\""}),
|
||||
Interval: "10s",
|
||||
Timeout: "1s",
|
||||
Interval: durationPtr(10 * time.Second),
|
||||
Timeout: durationPtr(1 * time.Second),
|
||||
Retries: uint64Ptr(5),
|
||||
StartPeriod: "15s",
|
||||
StartPeriod: durationPtr(15 * time.Second),
|
||||
},
|
||||
Hostname: "foo",
|
||||
Image: "redis",
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -316,7 +316,7 @@
|
|||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"disable": {"type": "boolean"},
|
||||
"interval": {"type": "string"},
|
||||
"interval": {"type": "string", "format": "duration"},
|
||||
"retries": {"type": "number"},
|
||||
"test": {
|
||||
"oneOf": [
|
||||
|
@ -324,8 +324,8 @@
|
|||
{"type": "array", "items": {"type": "string"}}
|
||||
]
|
||||
},
|
||||
"timeout": {"type": "string"},
|
||||
"start_period": {"type": "string"}
|
||||
"timeout": {"type": "string", "format": "duration"},
|
||||
"start_period": {"type": "string", "format": "duration"}
|
||||
}
|
||||
},
|
||||
"deployment": {
|
||||
|
|
|
@ -169,10 +169,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 `mapstructure:"start_period"`
|
||||
StartPeriod *time.Duration `mapstructure:"start_period"`
|
||||
Disable bool
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue