From defa52b8c6b5801ff007206e07261864f6b3f545 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Wed, 11 Oct 2023 16:35:51 +0000 Subject: [PATCH] stacks: Add support for start interval Signed-off-by: Brian Goff Signed-off-by: Sebastiaan van Stijn --- cli/compose/convert/service.go | 18 +++++++++------ cli/compose/convert/service_test.go | 23 ++++++++++++------- cli/compose/loader/full-example.yml | 1 + cli/compose/loader/full-struct_test.go | 11 +++++---- .../loader/testdata/full-example.json.golden | 3 ++- .../loader/testdata/full-example.yaml.golden | 1 + .../schema/data/config_schema_v3.12.json | 3 ++- cli/compose/types/types.go | 13 ++++++----- 8 files changed, 45 insertions(+), 28 deletions(-) diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index bb9255d581..eb5e5066d4 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -436,8 +436,8 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container return nil, nil } var ( - timeout, interval, startPeriod time.Duration - retries int + timeout, interval, startPeriod, startInterval time.Duration + retries int ) if healthcheck.Disable { if len(healthcheck.Test) != 0 { @@ -457,15 +457,19 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container if healthcheck.StartPeriod != nil { startPeriod = time.Duration(*healthcheck.StartPeriod) } + if healthcheck.StartInterval != nil { + startInterval = time.Duration(*healthcheck.StartInterval) + } if healthcheck.Retries != nil { retries = int(*healthcheck.Retries) } return &container.HealthConfig{ - Test: healthcheck.Test, - Timeout: timeout, - Interval: interval, - Retries: retries, - StartPeriod: startPeriod, + Test: healthcheck.Test, + Timeout: timeout, + Interval: interval, + Retries: retries, + StartPeriod: startPeriod, + StartInterval: startInterval, }, nil } diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index 4d48acc3ea..1293fda45e 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -124,17 +124,24 @@ func TestConvertHealthcheck(t *testing.T) { retries := uint64(10) timeout := composetypes.Duration(30 * time.Second) interval := composetypes.Duration(2 * time.Millisecond) + startPeriod := composetypes.Duration(time.Minute) + startInterval := composetypes.Duration(1 * time.Second) + source := &composetypes.HealthCheckConfig{ - Test: []string{"EXEC", "touch", "/foo"}, - Timeout: &timeout, - Interval: &interval, - Retries: &retries, + Test: []string{"EXEC", "touch", "/foo"}, + Timeout: &timeout, + Interval: &interval, + Retries: &retries, + StartPeriod: &startPeriod, + StartInterval: &startInterval, } expected := &container.HealthConfig{ - Test: source.Test, - Timeout: time.Duration(timeout), - Interval: time.Duration(interval), - Retries: 10, + Test: source.Test, + Timeout: time.Duration(timeout), + Interval: time.Duration(interval), + StartPeriod: time.Duration(startPeriod), + StartInterval: time.Duration(startInterval), + Retries: 10, } healthcheck, err := convertHealthcheck(source) diff --git a/cli/compose/loader/full-example.yml b/cli/compose/loader/full-example.yml index cac64a5ee0..76447d203a 100644 --- a/cli/compose/loader/full-example.yml +++ b/cli/compose/loader/full-example.yml @@ -158,6 +158,7 @@ services: timeout: 1s retries: 5 start_period: 15s + start_interval: 1s # Any valid image reference - repo, tag, id, sha image: redis diff --git a/cli/compose/loader/full-struct_test.go b/cli/compose/loader/full-struct_test.go index 5764ef616b..57f5e12567 100644 --- a/cli/compose/loader/full-struct_test.go +++ b/cli/compose/loader/full-struct_test.go @@ -154,11 +154,12 @@ func services(workingDir, homeDir string) []types.ServiceConfig { "x-foo": "bar", }, HealthCheck: &types.HealthCheckConfig{ - 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), + 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), + StartInterval: durationPtr(1 * time.Second), }, Hostname: "foo", Image: "redis", diff --git a/cli/compose/loader/testdata/full-example.json.golden b/cli/compose/loader/testdata/full-example.json.golden index 7e59c5bbc2..13c82de2fa 100644 --- a/cli/compose/loader/testdata/full-example.json.golden +++ b/cli/compose/loader/testdata/full-example.json.golden @@ -252,7 +252,8 @@ "timeout": "1s", "interval": "10s", "retries": 5, - "start_period": "15s" + "start_period": "15s", + "start_interval": "1s" }, "image": "redis", "ipc": "host", diff --git a/cli/compose/loader/testdata/full-example.yaml.golden b/cli/compose/loader/testdata/full-example.yaml.golden index 5266f98e47..83e2b8342f 100644 --- a/cli/compose/loader/testdata/full-example.yaml.golden +++ b/cli/compose/loader/testdata/full-example.yaml.golden @@ -126,6 +126,7 @@ services: interval: 10s retries: 5 start_period: 15s + start_interval: 1s image: redis ipc: host labels: diff --git a/cli/compose/schema/data/config_schema_v3.12.json b/cli/compose/schema/data/config_schema_v3.12.json index 939af4941b..2a548a3816 100644 --- a/cli/compose/schema/data/config_schema_v3.12.json +++ b/cli/compose/schema/data/config_schema_v3.12.json @@ -346,7 +346,8 @@ ] }, "timeout": {"type": "string", "format": "duration"}, - "start_period": {"type": "string", "format": "duration"} + "start_period": {"type": "string", "format": "duration"}, + "start_interval": {"type": "string", "format": "duration"} } }, "deployment": { diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index ed2e10e85b..964e5f5e33 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -276,12 +276,13 @@ type DeployConfig struct { // HealthCheckConfig the healthcheck configuration for a service type HealthCheckConfig struct { - Test HealthCheckTest `yaml:",omitempty" json:"test,omitempty"` - Timeout *Duration `yaml:",omitempty" json:"timeout,omitempty"` - Interval *Duration `yaml:",omitempty" json:"interval,omitempty"` - Retries *uint64 `yaml:",omitempty" json:"retries,omitempty"` - StartPeriod *Duration `mapstructure:"start_period" yaml:"start_period,omitempty" json:"start_period,omitempty"` - Disable bool `yaml:",omitempty" json:"disable,omitempty"` + Test HealthCheckTest `yaml:",omitempty" json:"test,omitempty"` + Timeout *Duration `yaml:",omitempty" json:"timeout,omitempty"` + Interval *Duration `yaml:",omitempty" json:"interval,omitempty"` + Retries *uint64 `yaml:",omitempty" json:"retries,omitempty"` + StartPeriod *Duration `mapstructure:"start_period" yaml:"start_period,omitempty" json:"start_period,omitempty"` + StartInterval *Duration `mapstructure:"start_interval" yaml:"start_interval,omitempty" json:"start_interval,omitempty"` + Disable bool `yaml:",omitempty" json:"disable,omitempty"` } // HealthCheckTest is the command run to test the health of a service