stacks: Add support for start interval

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Brian Goff 2023-10-11 16:35:51 +00:00 committed by Sebastiaan van Stijn
parent 9df7be5d5e
commit defa52b8c6
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
8 changed files with 45 additions and 28 deletions

View File

@ -436,7 +436,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
return nil, nil return nil, nil
} }
var ( var (
timeout, interval, startPeriod time.Duration timeout, interval, startPeriod, startInterval time.Duration
retries int retries int
) )
if healthcheck.Disable { if healthcheck.Disable {
@ -457,6 +457,9 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
if healthcheck.StartPeriod != nil { if healthcheck.StartPeriod != nil {
startPeriod = time.Duration(*healthcheck.StartPeriod) startPeriod = time.Duration(*healthcheck.StartPeriod)
} }
if healthcheck.StartInterval != nil {
startInterval = time.Duration(*healthcheck.StartInterval)
}
if healthcheck.Retries != nil { if healthcheck.Retries != nil {
retries = int(*healthcheck.Retries) retries = int(*healthcheck.Retries)
} }
@ -466,6 +469,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
Interval: interval, Interval: interval,
Retries: retries, Retries: retries,
StartPeriod: startPeriod, StartPeriod: startPeriod,
StartInterval: startInterval,
}, nil }, nil
} }

View File

@ -124,16 +124,23 @@ func TestConvertHealthcheck(t *testing.T) {
retries := uint64(10) retries := uint64(10)
timeout := composetypes.Duration(30 * time.Second) timeout := composetypes.Duration(30 * time.Second)
interval := composetypes.Duration(2 * time.Millisecond) interval := composetypes.Duration(2 * time.Millisecond)
startPeriod := composetypes.Duration(time.Minute)
startInterval := composetypes.Duration(1 * time.Second)
source := &composetypes.HealthCheckConfig{ source := &composetypes.HealthCheckConfig{
Test: []string{"EXEC", "touch", "/foo"}, Test: []string{"EXEC", "touch", "/foo"},
Timeout: &timeout, Timeout: &timeout,
Interval: &interval, Interval: &interval,
Retries: &retries, Retries: &retries,
StartPeriod: &startPeriod,
StartInterval: &startInterval,
} }
expected := &container.HealthConfig{ expected := &container.HealthConfig{
Test: source.Test, Test: source.Test,
Timeout: time.Duration(timeout), Timeout: time.Duration(timeout),
Interval: time.Duration(interval), Interval: time.Duration(interval),
StartPeriod: time.Duration(startPeriod),
StartInterval: time.Duration(startInterval),
Retries: 10, Retries: 10,
} }

View File

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

View File

@ -159,6 +159,7 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
Timeout: durationPtr(1 * time.Second), Timeout: durationPtr(1 * time.Second),
Retries: uint64Ptr(5), Retries: uint64Ptr(5),
StartPeriod: durationPtr(15 * time.Second), StartPeriod: durationPtr(15 * time.Second),
StartInterval: durationPtr(1 * time.Second),
}, },
Hostname: "foo", Hostname: "foo",
Image: "redis", Image: "redis",

View File

@ -252,7 +252,8 @@
"timeout": "1s", "timeout": "1s",
"interval": "10s", "interval": "10s",
"retries": 5, "retries": 5,
"start_period": "15s" "start_period": "15s",
"start_interval": "1s"
}, },
"image": "redis", "image": "redis",
"ipc": "host", "ipc": "host",

View File

@ -126,6 +126,7 @@ services:
interval: 10s interval: 10s
retries: 5 retries: 5
start_period: 15s start_period: 15s
start_interval: 1s
image: redis image: redis
ipc: host ipc: host
labels: labels:

View File

@ -346,7 +346,8 @@
] ]
}, },
"timeout": {"type": "string", "format": "duration"}, "timeout": {"type": "string", "format": "duration"},
"start_period": {"type": "string", "format": "duration"} "start_period": {"type": "string", "format": "duration"},
"start_interval": {"type": "string", "format": "duration"}
} }
}, },
"deployment": { "deployment": {

View File

@ -281,6 +281,7 @@ type HealthCheckConfig struct {
Interval *Duration `yaml:",omitempty" json:"interval,omitempty"` Interval *Duration `yaml:",omitempty" json:"interval,omitempty"`
Retries *uint64 `yaml:",omitempty" json:"retries,omitempty"` Retries *uint64 `yaml:",omitempty" json:"retries,omitempty"`
StartPeriod *Duration `mapstructure:"start_period" yaml:"start_period,omitempty" json:"start_period,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"` Disable bool `yaml:",omitempty" json:"disable,omitempty"`
} }