From 16f9867fad8cf1a15bd38e5ec7c9bfd19dd4b8b1 Mon Sep 17 00:00:00 2001 From: Filipe Regadas Date: Tue, 30 Nov 2021 15:56:52 +0000 Subject: [PATCH] fixup! Set Forbidden as the response status reason --- pkg/webhook/policy.go | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/pkg/webhook/policy.go b/pkg/webhook/policy.go index 68b095ff74e..1e3c89cfb68 100644 --- a/pkg/webhook/policy.go +++ b/pkg/webhook/policy.go @@ -189,25 +189,31 @@ func (h *validationHandler) Handle(ctx context.Context, req admission.Request) a denyMsgs, warnMsgs := h.getValidationMessages(res, &req) if len(denyMsgs) > 0 { - vResp := admission.Denied(string(metav1.StatusReasonForbidden)) - if vResp.Result == nil { - vResp.Result = &metav1.Status{} - } - if len(warnMsgs) > 0 { - vResp.Warnings = warnMsgs - } - vResp.Result.Message = strings.Join(denyMsgs, "\n") requestResponse = denyResponse - return vResp + return admission.Response{ + AdmissionResponse: admissionv1.AdmissionResponse{ + Allowed: false, + Result: &metav1.Status{ + Reason: metav1.StatusReasonForbidden, + Code: http.StatusForbidden, + Message: strings.Join(denyMsgs, "\n"), + }, + Warnings: warnMsgs, + }, + } } requestResponse = allowResponse - vResp := admission.Allowed("") - if vResp.Result == nil { - vResp.Result = &metav1.Status{} + vResp := admission.Response{ + AdmissionResponse: admissionv1.AdmissionResponse{ + Allowed: true, + Result: &metav1.Status{ + Code: http.StatusOK, + }, + Warnings: warnMsgs, + }, } if len(warnMsgs) > 0 { - vResp.Warnings = warnMsgs vResp.Result.Code = httpStatusWarning } return vResp