@@ -18,6 +18,7 @@ package validating
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"fmt"
22
23
"sync"
23
24
"time"
@@ -173,13 +174,12 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr admission.Attr
173
174
if err != nil {
174
175
switch err := err .(type ) {
175
176
case * webhookutil.ErrCallingWebhook :
176
- if ctx .Err () == context .Canceled {
177
- klog .Warningf ("Context Canceled when calling webhook %v" , hook .Name )
178
- return
179
- }
180
177
if ! ignoreClientCallFailures {
181
178
rejected = true
182
- admissionmetrics .Metrics .ObserveWebhookRejection (ctx , hook .Name , "validating" , string (versionedAttr .Attributes .GetOperation ()), admissionmetrics .WebhookRejectionCallingWebhookError , int (err .Status .ErrStatus .Code ))
179
+ // Ignore context cancelled from webhook metrics
180
+ if ! errors .Is (err .Reason , context .Canceled ) {
181
+ admissionmetrics .Metrics .ObserveWebhookRejection (ctx , hook .Name , "validating" , string (versionedAttr .Attributes .GetOperation ()), admissionmetrics .WebhookRejectionCallingWebhookError , int (err .Status .ErrStatus .Code ))
182
+ }
183
183
}
184
184
admissionmetrics .Metrics .ObserveWebhook (ctx , hook .Name , time .Since (t ), rejected , versionedAttr .Attributes , "validating" , int (err .Status .ErrStatus .Code ))
185
185
case * webhookutil.ErrWebhookRejection :
@@ -198,12 +198,17 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr admission.Attr
198
198
199
199
if callErr , ok := err .(* webhookutil.ErrCallingWebhook ); ok {
200
200
if ignoreClientCallFailures {
201
- klog .Warningf ("Failed calling webhook, failing open %v: %v" , hook .Name , callErr )
202
- admissionmetrics .Metrics .ObserveWebhookFailOpen (ctx , hook .Name , "validating" )
203
- key := fmt .Sprintf ("%sround_0_index_%d" , ValidatingAuditAnnotationFailedOpenKeyPrefix , idx )
204
- value := hook .Name
205
- if err := versionedAttr .Attributes .AddAnnotation (key , value ); err != nil {
206
- klog .Warningf ("Failed to set admission audit annotation %s to %s for validating webhook %s: %v" , key , value , hook .Name , err )
201
+ // Ignore context cancelled from webhook metrics
202
+ if errors .Is (callErr .Reason , context .Canceled ) {
203
+ klog .Warningf ("Context canceled when calling webhook %v" , hook .Name )
204
+ } else {
205
+ klog .Warningf ("Failed calling webhook, failing open %v: %v" , hook .Name , callErr )
206
+ admissionmetrics .Metrics .ObserveWebhookFailOpen (ctx , hook .Name , "validating" )
207
+ key := fmt .Sprintf ("%sround_0_index_%d" , ValidatingAuditAnnotationFailedOpenKeyPrefix , idx )
208
+ value := hook .Name
209
+ if err := versionedAttr .Attributes .AddAnnotation (key , value ); err != nil {
210
+ klog .Warningf ("Failed to set admission audit annotation %s to %s for validating webhook %s: %v" , key , value , hook .Name , err )
211
+ }
207
212
}
208
213
utilruntime .HandleError (callErr )
209
214
return
0 commit comments