Skip to content

Commit

Permalink
Add comment on why we just continue for nil TimeoutSeconds value
Browse files Browse the repository at this point in the history
  • Loading branch information
MorrisLaw committed Jul 7, 2020
1 parent b3915f2 commit 161c7a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
22 changes: 6 additions & 16 deletions checks/doks/admission_controller_webhook_timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ func (w *webhookTimeoutCheck) Run(objects *kube.Objects) ([]checks.Diagnostic, e
for _, wh := range config.Webhooks {
if wh.TimeoutSeconds == nil {
// TimeoutSeconds value should be set to a non-nil value (greater than or equal to 1 and less than 30).
d := checks.Diagnostic{
Severity: checks.Error,
Message: "Validating webhook with the default TimeoutSeconds value of 30 will block upgrades.",
Kind: checks.ValidatingWebhookConfiguration,
Object: &config.ObjectMeta,
Owners: config.ObjectMeta.GetOwnerReferences(),
}
diagnostics = append(diagnostics, d)
// If the TimeoutSeconds value is set to nil and the cluster version is 1.13.*, users are
// unable to configure the TimeoutSeconds value and this value will stay at nil, breaking
// upgrades. It's only for versions >= 1.14 that the value will default to 30 seconds.
continue
} else if *wh.TimeoutSeconds < int32(1) || *wh.TimeoutSeconds >= int32(30) {
// Webhooks with TimeoutSeconds set: less than 1 or greater than or equal to 30 is bad.
Expand All @@ -78,14 +73,9 @@ func (w *webhookTimeoutCheck) Run(objects *kube.Objects) ([]checks.Diagnostic, e
for _, wh := range config.Webhooks {
if wh.TimeoutSeconds == nil {
// TimeoutSeconds value should be set to a non-nil value (greater than or equal to 1 and less than 30).
d := checks.Diagnostic{
Severity: checks.Error,
Message: "Mutating webhook with the default TimeoutSeconds value of 30 will block upgrades.",
Kind: checks.MutatingWebhookConfiguration,
Object: &config.ObjectMeta,
Owners: config.ObjectMeta.GetOwnerReferences(),
}
diagnostics = append(diagnostics, d)
// If the TimeoutSeconds value is set to nil and the cluster version is 1.13.*, users are
// unable to configure the TimeoutSeconds value and this value will stay at nil, breaking
// upgrades. It's only for versions >= 1.14 that the value will default to 30 seconds.
continue
} else if *wh.TimeoutSeconds < int32(1) || *wh.TimeoutSeconds >= int32(30) {
// Webhooks with TimeoutSeconds set: less than 1 or greater than or equal to 30 is bad.
Expand Down
26 changes: 1 addition & 25 deletions checks/doks/admission_controller_webhook_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestWebhookTimeoutError(t *testing.T) {
nil,
2,
),
expected: webhookNilTimeoutErrors(),
expected: nil,
},
}

Expand Down Expand Up @@ -236,30 +236,6 @@ func webhookTimeoutErrors() []checks.Diagnostic {
return diagnostics
}

func webhookNilTimeoutErrors() []checks.Diagnostic {
objs := webhookTimeoutTestObjects(ar.WebhookClientConfig{}, nil, 0)
validatingConfig := objs.ValidatingWebhookConfigurations.Items[0]
mutatingConfig := objs.MutatingWebhookConfigurations.Items[0]

diagnostics := []checks.Diagnostic{
{
Severity: checks.Error,
Message: "Validating webhook with the default TimeoutSeconds value of 30 will block upgrades.",
Kind: checks.ValidatingWebhookConfiguration,
Object: &validatingConfig.ObjectMeta,
Owners: validatingConfig.ObjectMeta.GetOwnerReferences(),
},
{
Severity: checks.Error,
Message: "Mutating webhook with the default TimeoutSeconds value of 30 will block upgrades.",
Kind: checks.MutatingWebhookConfiguration,
Object: &mutatingConfig.ObjectMeta,
Owners: mutatingConfig.ObjectMeta.GetOwnerReferences(),
},
}
return diagnostics
}

// converts an int to an int32 and returns a pointer
func toIntP(i int) *int32 {
num := int32(i)
Expand Down

0 comments on commit 161c7a1

Please sign in to comment.