1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00
kyverno/pkg/utils/admission/response.go
Charles-Edouard Brétéché 060f7bb873
refactor: admission response utils (#5234)
- refactor: admission response utils
- unit tests

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2022-11-08 09:35:08 +00:00

30 lines
721 B
Go

package admission
import (
admissionv1 "k8s.io/api/admission/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func Response(err error, warnings ...string) *admissionv1.AdmissionResponse {
response := &admissionv1.AdmissionResponse{
Allowed: err == nil,
}
if err != nil {
response.Result = &metav1.Status{
Status: metav1.StatusFailure,
Message: err.Error(),
}
}
response.Warnings = warnings
return response
}
func ResponseSuccess(warnings ...string) *admissionv1.AdmissionResponse {
return Response(nil, warnings...)
}
func MutationResponse(patch []byte, warnings ...string) *admissionv1.AdmissionResponse {
response := ResponseSuccess(warnings...)
response.Patch = patch
return response
}