Skip to content

Commit

Permalink
fixup! Set Forbidden as the response status reason
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Regadas <filiperegadas@gmail.com>
  • Loading branch information
regadas committed Nov 30, 2021
1 parent 5f12afd commit 3fcac68
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
Expand Up @@ -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
Expand Down

0 comments on commit 3fcac68

Please # to comment.