Skip to content

Commit def348b

Browse files
Merge pull request #1533 from openshift-cherrypick-robot/cherry-pick-1532-to-release-4.12
[release-4.12] OCPBUGS-17139: make webhook connection failure a warning in log
2 parents 353171f + 3ecbb38 commit def348b

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

pkg/operator/webhooksupportabilitycontroller/degraded_webhook.go

Lines changed: 12 additions & 5 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.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, 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, ref
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, ref
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,
@@ -124,8 +131,8 @@ func (c *webhookSupportabilityController) assertConnect(ctx context.Context, ref
124131
conn, err = dialer.DialContext(ctx, "tcp", net.JoinHostPort(host, port))
125132
if err != nil {
126133
if i != 2 {
127-
// log err since only last one is reported
128-
runtime.HandleError(err)
134+
// log warning since only last one is reported
135+
klog.Warningf("failed to connect to webhook %q via service %q: %v", webhookName, net.JoinHostPort(host, port), err)
129136
}
130137
continue
131138
}

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 {

pkg/operator/webhooksupportabilitycontroller/degraded_webhook_conversion.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package webhooksupportabilitycontroller
22

33
import (
44
"context"
5-
65
operatorv1 "github.com/openshift/api/operator/v1"
76
"github.com/openshift/library-go/pkg/operator/v1helpers"
7+
8+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
89
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
910
"k8s.io/apimachinery/pkg/labels"
1011
)
@@ -21,24 +22,31 @@ func (c *webhookSupportabilityController) updateCRDConversionWebhookConfiguratio
2122
}
2223
var webhookInfos []webhookInfo
2324
for _, crd := range crds {
24-
conversion := crd.Spec.Conversion
25-
if conversion == nil || conversion.Strategy != v1.WebhookConverter {
26-
continue
27-
}
28-
clientConfig := conversion.Webhook.ClientConfig
29-
if clientConfig == nil || clientConfig.Service == nil {
25+
if !hasCRDConversionWebhookConfiguration(crd) {
3026
continue
3127
}
3228
info := webhookInfo{
3329
Name: crd.Name,
34-
CABundle: clientConfig.CABundle,
30+
CABundle: crd.Spec.Conversion.Webhook.ClientConfig.CABundle,
3531
Service: &serviceReference{
36-
Namespace: clientConfig.Service.Namespace,
37-
Name: clientConfig.Service.Name,
38-
Port: clientConfig.Service.Port,
32+
Namespace: crd.Spec.Conversion.Webhook.ClientConfig.Service.Namespace,
33+
Name: crd.Spec.Conversion.Webhook.ClientConfig.Service.Name,
34+
Port: crd.Spec.Conversion.Webhook.ClientConfig.Service.Port,
3935
},
4036
}
4137
webhookInfos = append(webhookInfos, info)
4238
}
4339
return c.updateWebhookConfigurationDegraded(ctx, condition, webhookInfos)
4440
}
41+
42+
func hasCRDConversionWebhookConfiguration(crd *apiextensionsv1.CustomResourceDefinition) bool {
43+
conversion := crd.Spec.Conversion
44+
if conversion == nil || conversion.Strategy != v1.WebhookConverter {
45+
return false
46+
}
47+
clientConfig := conversion.Webhook.ClientConfig
48+
if clientConfig == nil || clientConfig.Service == nil {
49+
return false
50+
}
51+
return true
52+
}

pkg/operator/webhooksupportabilitycontroller/webhook_supportability_controller.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/openshift/library-go/pkg/operator/events"
88
"github.com/openshift/library-go/pkg/operator/management"
99
"github.com/openshift/library-go/pkg/operator/v1helpers"
10+
11+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1012
apiextensionsinformers "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
1113
apiextensionslistersv1 "k8s.io/apiextensions-apiserver/pkg/client/listers/apiextensions/v1"
1214
admissionregistrationlistersv1 "k8s.io/client-go/listers/admissionregistration/v1"
@@ -43,14 +45,19 @@ func NewWebhookSupportabilityController(
4345
kubeInformersForAllNamespaces.Admissionregistration().V1().MutatingWebhookConfigurations().Informer(),
4446
kubeInformersForAllNamespaces.Admissionregistration().V1().ValidatingWebhookConfigurations().Informer(),
4547
kubeInformersForAllNamespaces.Core().V1().Services().Informer(),
46-
apiExtensionsInformers.Apiextensions().V1().CustomResourceDefinitions().Informer(),
4748
).
49+
WithFilteredEventsInformers(func(obj interface{}) bool {
50+
if crd, ok := obj.(*apiextensionsv1.CustomResourceDefinition); ok {
51+
return hasCRDConversionWebhookConfiguration(crd)
52+
}
53+
return true // re-queue just in case, the checks are fairly cheap
54+
}, apiExtensionsInformers.Apiextensions().V1().CustomResourceDefinitions().Informer()).
4855
WithSync(c.sync).
4956
ToController("webhookSupportabilityController", recorder)
5057
return c
5158
}
5259

53-
func (c *webhookSupportabilityController) sync(ctx context.Context, controllerContext factory.SyncContext) error {
60+
func (c *webhookSupportabilityController) sync(ctx context.Context, _ factory.SyncContext) error {
5461
operatorSpec, _, _, err := c.operatorClient.GetOperatorState()
5562
if err != nil {
5663
return err

0 commit comments

Comments
 (0)