Skip to content

Commit

Permalink
Merge pull request #1510 from p0lyn0mial/fix-ocpbugs-13946-part-2
Browse files Browse the repository at this point in the history
OCPBUGS-13946: do not use one second timeout when asserting a webhook connection
  • Loading branch information
openshift-merge-robot committed Jun 27, 2023
2 parents 6270111 + 1156b3a commit 8b64249
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/operator/webhooksupportabilitycontroller/degraded_webhook.go
Expand Up @@ -22,6 +22,9 @@ type webhookInfo struct {
Service *serviceReference
CABundle []byte
FailurePolicyIsIgnore bool
// TimeoutSeconds specifies the timeout for a webhook.
// After the timeout passes, the webhook call will be ignored or the API call will fail
TimeoutSeconds *int32
}

// serviceReference generically represents a service reference
Expand Down Expand Up @@ -49,7 +52,7 @@ func (c *webhookSupportabilityController) updateWebhookConfigurationDegraded(ctx
serviceMsgs = append(serviceMsgs, msg)
continue
}
err = c.assertConnect(ctx, webhook.Name, webhook.Service, webhook.CABundle)
err = c.assertConnect(ctx, webhook.Name, webhook.Service, webhook.CABundle, webhook.TimeoutSeconds)
if err != nil {
msg := fmt.Sprintf("%s: %s", webhook.Name, err)
if webhook.FailurePolicyIsIgnore {
Expand Down Expand Up @@ -94,7 +97,7 @@ func (c *webhookSupportabilityController) assertService(reference *serviceRefere
}

// assertConnect performs a dns lookup of service, opens a tcp connection, and performs a tls handshake.
func (c *webhookSupportabilityController) assertConnect(ctx context.Context, webhookName string, reference *serviceReference, caBundle []byte) error {
func (c *webhookSupportabilityController) assertConnect(ctx context.Context, webhookName string, reference *serviceReference, caBundle []byte, webhookTimeoutSeconds *int32) error {
host := reference.Name + "." + reference.Namespace + ".svc"
port := "443"
if reference.Port != nil {
Expand All @@ -104,6 +107,10 @@ func (c *webhookSupportabilityController) assertConnect(ctx context.Context, web
if len(caBundle) > 0 {
rootCAs.AppendCertsFromPEM(caBundle)
}
timeout := 10 * time.Second
if webhookTimeoutSeconds != nil {
timeout = time.Duration(*webhookTimeoutSeconds) * time.Second
}
// the last error that occurred in the loop below
var err error
// retry up to 3 times on error
Expand All @@ -114,7 +121,7 @@ func (c *webhookSupportabilityController) assertConnect(ctx context.Context, web
case <-time.After(time.Duration(i) * time.Second):
}
dialer := &tls.Dialer{
NetDialer: &net.Dialer{Timeout: 1 * time.Second},
NetDialer: &net.Dialer{Timeout: timeout},
Config: &tls.Config{
ServerName: host,
RootCAs: rootCAs,
Expand Down
Expand Up @@ -27,6 +27,7 @@ func (c *webhookSupportabilityController) updateMutatingAdmissionWebhookConfigur
Name: webhook.Name,
CABundle: webhook.ClientConfig.CABundle,
FailurePolicyIsIgnore: webhook.FailurePolicy != nil && *webhook.FailurePolicy == admissionregistrationv1.Ignore,
TimeoutSeconds: webhook.TimeoutSeconds,
}
if webhook.ClientConfig.Service != nil {
info.Service = &serviceReference{
Expand Down Expand Up @@ -58,6 +59,7 @@ func (c *webhookSupportabilityController) updateValidatingAdmissionWebhookConfig
Name: webhook.Name,
CABundle: webhook.ClientConfig.CABundle,
FailurePolicyIsIgnore: webhook.FailurePolicy != nil && (*webhook.FailurePolicy == v1.Ignore),
TimeoutSeconds: webhook.TimeoutSeconds,
}

if webhook.ClientConfig.Service != nil {
Expand Down

0 comments on commit 8b64249

Please sign in to comment.