Commit 1bea47aa authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #53896 from deads2k/admission-03-decode

Automatic merge from submit-queue (batch tested with PRs 47717, 53896). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. decode admission responses into a fresh object Something about the way the admission request object is built causes decoding into back into it to fail with ``` W1013 14:10:42.457423 2960 admission.go:185] rejected by webhook namespacereservations.admission.online.openshift.io/apis/admission.online.openshift.io/v1alpha1/namespacereservations &{%!t(string=namespacereservations.admission.online.openshift.io/apis/admission.online.openshift.io/v1alpha1/namespacereservations) %!t(*errors.errorString=&{reflect.Value.Addr of unaddressable value})}: failed calling admission webhook "namespacereservations.admission.online.openshift.io/apis/admission.online.openshift.io/v1alpha1/namespacereservations": reflect.Value.Addr of unaddressable value ``` This simply creates a fresh object to decode into, which works fine for our usage and makes it possible to actually have the webhook call out to something.
parents 09a42ba9 9adcbd72
...@@ -242,20 +242,21 @@ func (a *GenericAdmissionWebhook) callHook(ctx context.Context, h *v1alpha1.Exte ...@@ -242,20 +242,21 @@ func (a *GenericAdmissionWebhook) callHook(ctx context.Context, h *v1alpha1.Exte
if err != nil { if err != nil {
return &ErrCallingWebhook{WebhookName: h.Name, Reason: err} return &ErrCallingWebhook{WebhookName: h.Name, Reason: err}
} }
if err := client.Post().Context(ctx).Body(&request).Do().Into(&request); err != nil { response := &admissionv1alpha1.AdmissionReview{}
if err := client.Post().Context(ctx).Body(&request).Do().Into(response); err != nil {
return &ErrCallingWebhook{WebhookName: h.Name, Reason: err} return &ErrCallingWebhook{WebhookName: h.Name, Reason: err}
} }
if request.Status.Allowed { if response.Status.Allowed {
return nil return nil
} }
if request.Status.Result == nil { if response.Status.Result == nil {
return fmt.Errorf("admission webhook %q denied the request without explanation", h.Name) return fmt.Errorf("admission webhook %q denied the request without explanation", h.Name)
} }
return &apierrors.StatusError{ return &apierrors.StatusError{
ErrStatus: *request.Status.Result, ErrStatus: *response.Status.Result,
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment