mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #101532 from stevekuznetsov/skuznets/wrap-admission-error-reasons
apiserver: wrap errors in admission with context
This commit is contained in:
commit
50e319767c
@ -214,12 +214,12 @@ func (a *mutatingDispatcher) callAttrMutatingHook(ctx context.Context, h *admiss
|
|||||||
|
|
||||||
uid, request, response, err := webhookrequest.CreateAdmissionObjects(attr, invocation)
|
uid, request, response, err := webhookrequest.CreateAdmissionObjects(attr, invocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: err}
|
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: fmt.Errorf("could not create admission objects: %w", err)}
|
||||||
}
|
}
|
||||||
// Make the webhook request
|
// Make the webhook request
|
||||||
client, err := invocation.Webhook.GetRESTClient(a.cm)
|
client, err := invocation.Webhook.GetRESTClient(a.cm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: err}
|
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: fmt.Errorf("could not get REST client: %w", err)}
|
||||||
}
|
}
|
||||||
trace := utiltrace.New("Call mutating webhook",
|
trace := utiltrace.New("Call mutating webhook",
|
||||||
utiltrace.Field{"configuration", configurationName},
|
utiltrace.Field{"configuration", configurationName},
|
||||||
@ -253,13 +253,13 @@ func (a *mutatingDispatcher) callAttrMutatingHook(ctx context.Context, h *admiss
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := r.Do(ctx).Into(response); err != nil {
|
if err := r.Do(ctx).Into(response); err != nil {
|
||||||
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: err}
|
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: fmt.Errorf("failed to call webhook: %w", err)}
|
||||||
}
|
}
|
||||||
trace.Step("Request completed")
|
trace.Step("Request completed")
|
||||||
|
|
||||||
result, err := webhookrequest.VerifyAdmissionResponse(uid, true, response)
|
result, err := webhookrequest.VerifyAdmissionResponse(uid, true, response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: err}
|
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: fmt.Errorf("received invalid webhook response: %w", err)}
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range result.AuditAnnotations {
|
for k, v := range result.AuditAnnotations {
|
||||||
|
Loading…
Reference in New Issue
Block a user