mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 07:57:07 +00:00
* feat: use admission review v1 Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * nit Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * logs Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * patch type 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> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Co-authored-by: Prateek Pandey <prateek.pandey@nirmata.com>
37 lines
951 B
Go
37 lines
951 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
|
|
}
|