1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/pkg/utils/admission/response.go
Charles-Edouard Brétéché 18033a415b
refactor: remove admission request/response pointers (#6769)
* refactor: remove admission request/response pointers

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix tests

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-04-03 18:08:57 +00:00

37 lines
947 B
Go

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