Skip to content

Commit

Permalink
Change the type of interval, timeout and start_period of healthcheck …
Browse files Browse the repository at this point in the history
…from string to * time.Duration

Signed-off-by: Li Yi <denverdino@gmail.com>
  • Loading branch information
denverdino committed Aug 30, 2017
1 parent 0abdad6 commit e02fcfd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
22 changes: 6 additions & 16 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
return nil, nil
}
var (
err error
timeout, interval, startPeriod time.Duration
retries int
)
Expand All @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions cli/compose/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
6 changes: 3 additions & 3 deletions cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cli/compose/schema/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cli/compose/schema/data/config_schema_v3.4.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,16 @@
"additionalProperties": false,
"properties": {
"disable": {"type": "boolean"},
"interval": {"type": "string"},
"interval": {"type": "string", "format": "duration"},
"retries": {"type": "number"},
"test": {
"oneOf": [
{"type": "string"},
{"type": "array", "items": {"type": "string"}}
]
},
"timeout": {"type": "string"},
"start_period": {"type": "string"}
"timeout": {"type": "string", "format": "duration"},
"start_period": {"type": "string", "format": "duration"}
}
},
"deployment": {
Expand Down
6 changes: 3 additions & 3 deletions cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit e02fcfd

Please sign in to comment.