Skip to content

Commit 0083b43

Browse files
divyasri537k8s-publishing-bot
authored andcommitted
Incorporating feedback on 119341
Kubernetes-commit: 955843efcf325a578aa1caad91081b7a21699158
1 parent 427f2f6 commit 0083b43

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

pkg/admission/plugin/webhook/mutating/dispatcher.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package mutating
2020

2121
import (
2222
"context"
23+
"errors"
2324
"fmt"
2425
"time"
2526

@@ -168,13 +169,12 @@ func (a *mutatingDispatcher) Dispatch(ctx context.Context, attr admission.Attrib
168169
if err != nil {
169170
switch err := err.(type) {
170171
case *webhookutil.ErrCallingWebhook:
171-
if ctx.Err() == context.Canceled {
172-
klog.Warningf("Context Canceled when calling webhook %v", hook.Name)
173-
return err
174-
}
175172
if !ignoreClientCallFailures {
176173
rejected = true
177-
admissionmetrics.Metrics.ObserveWebhookRejection(ctx, hook.Name, "admit", string(versionedAttr.Attributes.GetOperation()), admissionmetrics.WebhookRejectionCallingWebhookError, int(err.Status.ErrStatus.Code))
174+
// Ignore context cancelled from webhook metrics
175+
if !errors.Is(err.Reason, context.Canceled) {
176+
admissionmetrics.Metrics.ObserveWebhookRejection(ctx, hook.Name, "admit", string(versionedAttr.Attributes.GetOperation()), admissionmetrics.WebhookRejectionCallingWebhookError, int(err.Status.ErrStatus.Code))
177+
}
178178
}
179179
admissionmetrics.Metrics.ObserveWebhook(ctx, hook.Name, time.Since(t), rejected, versionedAttr.Attributes, "admit", int(err.Status.ErrStatus.Code))
180180
case *webhookutil.ErrWebhookRejection:
@@ -203,10 +203,14 @@ func (a *mutatingDispatcher) Dispatch(ctx context.Context, attr admission.Attrib
203203

204204
if callErr, ok := err.(*webhookutil.ErrCallingWebhook); ok {
205205
if ignoreClientCallFailures {
206-
klog.Warningf("Failed calling webhook, failing open %v: %v", hook.Name, callErr)
207-
admissionmetrics.Metrics.ObserveWebhookFailOpen(ctx, hook.Name, "admit")
208-
annotator.addFailedOpenAnnotation()
209-
206+
// Ignore context cancelled from webhook metrics
207+
if errors.Is(callErr.Reason, context.Canceled) {
208+
klog.Warningf("Context canceled when calling webhook %v", hook.Name)
209+
} else {
210+
klog.Warningf("Failed calling webhook, failing open %v: %v", hook.Name, callErr)
211+
admissionmetrics.Metrics.ObserveWebhookFailOpen(ctx, hook.Name, "admit")
212+
annotator.addFailedOpenAnnotation()
213+
}
210214
utilruntime.HandleError(callErr)
211215

212216
select {

pkg/admission/plugin/webhook/validating/dispatcher.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package validating
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"sync"
2324
"time"
@@ -173,13 +174,12 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr admission.Attr
173174
if err != nil {
174175
switch err := err.(type) {
175176
case *webhookutil.ErrCallingWebhook:
176-
if ctx.Err() == context.Canceled {
177-
klog.Warningf("Context Canceled when calling webhook %v", hook.Name)
178-
return
179-
}
180177
if !ignoreClientCallFailures {
181178
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+
}
183183
}
184184
admissionmetrics.Metrics.ObserveWebhook(ctx, hook.Name, time.Since(t), rejected, versionedAttr.Attributes, "validating", int(err.Status.ErrStatus.Code))
185185
case *webhookutil.ErrWebhookRejection:
@@ -198,12 +198,17 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr admission.Attr
198198

199199
if callErr, ok := err.(*webhookutil.ErrCallingWebhook); ok {
200200
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+
}
207212
}
208213
utilruntime.HandleError(callErr)
209214
return

0 commit comments

Comments
 (0)