Skip to content

Commit 1bea47a

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#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.
2 parents 09a42ba + 9adcbd7 commit 1bea47a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

plugin/pkg/admission/webhook/admission.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,21 @@ func (a *GenericAdmissionWebhook) callHook(ctx context.Context, h *v1alpha1.Exte
242242
if err != nil {
243243
return &ErrCallingWebhook{WebhookName: h.Name, Reason: err}
244244
}
245-
if err := client.Post().Context(ctx).Body(&request).Do().Into(&request); err != nil {
245+
response := &admissionv1alpha1.AdmissionReview{}
246+
if err := client.Post().Context(ctx).Body(&request).Do().Into(response); err != nil {
246247
return &ErrCallingWebhook{WebhookName: h.Name, Reason: err}
247248
}
248249

249-
if request.Status.Allowed {
250+
if response.Status.Allowed {
250251
return nil
251252
}
252253

253-
if request.Status.Result == nil {
254+
if response.Status.Result == nil {
254255
return fmt.Errorf("admission webhook %q denied the request without explanation", h.Name)
255256
}
256257

257258
return &apierrors.StatusError{
258-
ErrStatus: *request.Status.Result,
259+
ErrStatus: *response.Status.Result,
259260
}
260261
}
261262

0 commit comments

Comments
 (0)