HealthCheck: add validation for minimum accepted start-interval

This is a follow-up to 2216d3ca8d, which
implemented the StartInterval for health-checks, but did not add validation
for the minimum accepted interval;

> The time to wait between checks in nanoseconds during the start period.
> It should be 0 or at least 1000000 (1 ms). 0 means inherit.

This patch adds validation for the minimum accepted interval (1ms).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-10-14 18:43:34 +02:00
parent 670bc0a46c
commit 2df698025c
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 23 additions and 9 deletions

View file

@ -333,6 +333,9 @@ func validateHealthCheck(healthConfig *containertypes.HealthConfig) error {
if healthConfig.StartPeriod != 0 && healthConfig.StartPeriod < containertypes.MinimumDuration {
return errors.Errorf("StartPeriod in Healthcheck cannot be less than %s", containertypes.MinimumDuration)
}
if healthConfig.StartInterval != 0 && healthConfig.StartInterval < containertypes.MinimumDuration {
return errors.Errorf("StartInterval in Healthcheck cannot be less than %s", containertypes.MinimumDuration)
}
return nil
}

View file

@ -343,12 +343,13 @@ func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
apiClient := testEnv.APIClient()
testCases := []struct {
doc string
interval time.Duration
timeout time.Duration
retries int
startPeriod time.Duration
expectedErr string
doc string
interval time.Duration
timeout time.Duration
retries int
startPeriod time.Duration
startInterval time.Duration
expectedErr string
}{
{
doc: "test invalid Interval in Healthcheck: less than 0s",
@ -386,6 +387,15 @@ func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
startPeriod: 100 * time.Microsecond,
expectedErr: fmt.Sprintf("StartPeriod in Healthcheck cannot be less than %s", container.MinimumDuration),
},
{
doc: "test invalid StartInterval in Healthcheck: not 0 and less than 1ms",
interval: time.Second,
timeout: time.Second,
retries: 1000,
startPeriod: time.Second,
startInterval: 100 * time.Microsecond,
expectedErr: fmt.Sprintf("StartInterval in Healthcheck cannot be less than %s", container.MinimumDuration),
},
}
for _, tc := range testCases {
@ -396,9 +406,10 @@ func TestCreateWithInvalidHealthcheckParams(t *testing.T) {
cfg := container.Config{
Image: "busybox",
Healthcheck: &container.HealthConfig{
Interval: tc.interval,
Timeout: tc.timeout,
Retries: tc.retries,
Interval: tc.interval,
Timeout: tc.timeout,
Retries: tc.retries,
StartInterval: tc.startInterval,
},
}
if tc.startPeriod != 0 {