diff --git a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/mutating/dispatcher.go b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/mutating/dispatcher.go index ca42558916a..af237ae0c00 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/mutating/dispatcher.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/mutating/dispatcher.go @@ -168,6 +168,10 @@ func (a *mutatingDispatcher) Dispatch(ctx context.Context, attr admission.Attrib if err != nil { switch err := err.(type) { case *webhookutil.ErrCallingWebhook: + if ctx.Err() == context.Canceled { + klog.Warningf("Context Canceled when calling webhook %v", hook.Name) + return err + } if !ignoreClientCallFailures { rejected = true admissionmetrics.Metrics.ObserveWebhookRejection(ctx, hook.Name, "admit", string(versionedAttr.Attributes.GetOperation()), admissionmetrics.WebhookRejectionCallingWebhookError, int(err.Status.ErrStatus.Code)) @@ -198,10 +202,6 @@ func (a *mutatingDispatcher) Dispatch(ctx context.Context, attr admission.Attrib } if callErr, ok := err.(*webhookutil.ErrCallingWebhook); ok { - if ctx.Err() == context.Canceled { - klog.Warningf("Context Canceled when calling webhook %v", hook.Name) - return err - } if ignoreClientCallFailures { klog.Warningf("Failed calling webhook, failing open %v: %v", hook.Name, callErr) admissionmetrics.Metrics.ObserveWebhookFailOpen(ctx, hook.Name, "admit") diff --git a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/validating/dispatcher.go b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/validating/dispatcher.go index 2d9216d4f21..af435649bd0 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/validating/dispatcher.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/validating/dispatcher.go @@ -173,6 +173,10 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr admission.Attr if err != nil { switch err := err.(type) { case *webhookutil.ErrCallingWebhook: + if ctx.Err() == context.Canceled { + klog.Warningf("Context Canceled when calling webhook %v", hook.Name) + return + } if !ignoreClientCallFailures { rejected = true admissionmetrics.Metrics.ObserveWebhookRejection(ctx, hook.Name, "validating", string(versionedAttr.Attributes.GetOperation()), admissionmetrics.WebhookRejectionCallingWebhookError, int(err.Status.ErrStatus.Code)) @@ -193,10 +197,6 @@ func (d *validatingDispatcher) Dispatch(ctx context.Context, attr admission.Attr } if callErr, ok := err.(*webhookutil.ErrCallingWebhook); ok { - if ctx.Err() == context.Canceled { - klog.Warningf("Context Canceled when calling webhook %v", hook.Name) - return - } if ignoreClientCallFailures { klog.Warningf("Failed calling webhook, failing open %v: %v", hook.Name, callErr) admissionmetrics.Metrics.ObserveWebhookFailOpen(ctx, hook.Name, "validating")