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
}
var (
timeout, interval, startPeriod time.Duration
timeout, interval, startPeriod, startInterval time.Duration
retries int
)
if healthcheck.Disable {
@ -457,6 +457,9 @@ 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)
}
@ -466,6 +469,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
Interval: interval,
Retries: retries,
StartPeriod: startPeriod,
StartInterval: startInterval,
}, nil
}

View File

@ -124,16 +124,23 @@ 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,
StartPeriod: &startPeriod,
StartInterval: &startInterval,
}
expected := &container.HealthConfig{
Test: source.Test,
Timeout: time.Duration(timeout),
Interval: time.Duration(interval),
StartPeriod: time.Duration(startPeriod),
StartInterval: time.Duration(startInterval),
Retries: 10,
}

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

@ -159,6 +159,7 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
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

@ -281,6 +281,7 @@ type HealthCheckConfig struct {
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"`
}