Merge pull request #46646 from thaJeztah/start_interval_validation

HealthCheck: add validation for minimum accepted start-interval (1ms)
This commit is contained in:
Bjorn Neergaard 2023-10-16 11:07:14 -07:00 committed by GitHub
commit fd3066c168
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 {