Skip to content

Commit 6644665

Browse files
p0lyn0mialopenshift-cherrypick-robot
authored andcommitted
webhooksupportabilitycontroller: do not use one second timeout when asserting a webhook connection
previously the dial timeout to a webook was set to one second which seems to be very aggressive and can cause failures which can put the operator into degraded state. This PR reads the timeout value for a webhook from the spec or uses a default value of 10 seconds if it wasn't specified
1 parent 9a997c3 commit 6644665

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pkg/operator/webhooksupportabilitycontroller/degraded_webhook.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ type webhookInfo struct {
2222
Service *serviceReference
2323
CABundle []byte
2424
FailurePolicyIsIgnore bool
25+
// TimeoutSeconds specifies the timeout for a webhook.
26+
// After the timeout passes, the webhook call will be ignored or the API call will fail
27+
TimeoutSeconds *int32
2528
}
2629

2730
// serviceReference generically represents a service reference
@@ -49,7 +52,7 @@ func (c *webhookSupportabilityController) updateWebhookConfigurationDegraded(ctx
4952
serviceMsgs = append(serviceMsgs, msg)
5053
continue
5154
}
52-
err = c.assertConnect(ctx, webhook.Name, webhook.Service, webhook.CABundle)
55+
err = c.assertConnect(ctx, webhook.Name, webhook.Service, webhook.CABundle, webhook.TimeoutSeconds)
5356
if err != nil {
5457
msg := fmt.Sprintf("%s: %s", webhook.Name, err)
5558
if webhook.FailurePolicyIsIgnore {
@@ -94,7 +97,7 @@ func (c *webhookSupportabilityController) assertService(reference *serviceRefere
9497
}
9598

9699
// assertConnect performs a dns lookup of service, opens a tcp connection, and performs a tls handshake.
97-
func (c *webhookSupportabilityController) assertConnect(ctx context.Context, webhookName string, reference *serviceReference, caBundle []byte) error {
100+
func (c *webhookSupportabilityController) assertConnect(ctx context.Context, webhookName string, reference *serviceReference, caBundle []byte, webhookTimeoutSeconds *int32) error {
98101
host := reference.Name + "." + reference.Namespace + ".svc"
99102
port := "443"
100103
if reference.Port != nil {
@@ -104,6 +107,10 @@ func (c *webhookSupportabilityController) assertConnect(ctx context.Context, web
104107
if len(caBundle) > 0 {
105108
rootCAs.AppendCertsFromPEM(caBundle)
106109
}
110+
timeout := 10 * time.Second
111+
if webhookTimeoutSeconds != nil {
112+
timeout = time.Duration(*webhookTimeoutSeconds) * time.Second
113+
}
107114
// the last error that occurred in the loop below
108115
var err error
109116
// retry up to 3 times on error
@@ -114,7 +121,7 @@ func (c *webhookSupportabilityController) assertConnect(ctx context.Context, web
114121
case <-time.After(time.Duration(i) * time.Second):
115122
}
116123
dialer := &tls.Dialer{
117-
NetDialer: &net.Dialer{Timeout: 1 * time.Second},
124+
NetDialer: &net.Dialer{Timeout: timeout},
118125
Config: &tls.Config{
119126
ServerName: host,
120127
RootCAs: rootCAs,

pkg/operator/webhooksupportabilitycontroller/degraded_webhook_admission.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func (c *webhookSupportabilityController) updateMutatingAdmissionWebhookConfigur
2727
Name: webhook.Name,
2828
CABundle: webhook.ClientConfig.CABundle,
2929
FailurePolicyIsIgnore: webhook.FailurePolicy != nil && *webhook.FailurePolicy == admissionregistrationv1.Ignore,
30+
TimeoutSeconds: webhook.TimeoutSeconds,
3031
}
3132
if webhook.ClientConfig.Service != nil {
3233
info.Service = &serviceReference{
@@ -58,6 +59,7 @@ func (c *webhookSupportabilityController) updateValidatingAdmissionWebhookConfig
5859
Name: webhook.Name,
5960
CABundle: webhook.ClientConfig.CABundle,
6061
FailurePolicyIsIgnore: webhook.FailurePolicy != nil && (*webhook.FailurePolicy == v1.Ignore),
62+
TimeoutSeconds: webhook.TimeoutSeconds,
6163
}
6264

6365
if webhook.ClientConfig.Service != nil {

0 commit comments

Comments
 (0)