Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Set Forbidden as the response status reason
Browse files Browse the repository at this point in the history
regadas committed Nov 30, 2021
1 parent 5f12afd commit 16f9867
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions pkg/webhook/policy.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 16f9867

Please sign in to comment.