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,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
}

View File

@ -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)

View File

@ -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

View File

@ -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",

View File

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

View File

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

View File

@ -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": {

View File

@ -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