1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/utils/admission/exception.go
Mariam Fahmy 94d9bbe73f
chore: use v2 clients for policy exceptions (#10530)
Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
2024-06-24 16:36:55 +00:00

28 lines
842 B
Go

package admission
import (
kyvernov2 "github.com/kyverno/kyverno/api/kyverno/v2"
admissionv1 "k8s.io/api/admission/v1"
"k8s.io/apimachinery/pkg/util/json"
)
func UnmarshalPolicyException(raw []byte) (*kyvernov2.PolicyException, error) {
var exception *kyvernov2.PolicyException
if err := json.Unmarshal(raw, &exception); err != nil {
return nil, err
}
return exception, nil
}
func GetPolicyExceptions(request admissionv1.AdmissionRequest) (*kyvernov2.PolicyException, *kyvernov2.PolicyException, error) {
var empty *kyvernov2.PolicyException
exception, err := UnmarshalPolicyException(request.Object.Raw)
if err != nil {
return exception, empty, err
}
if request.Operation == admissionv1.Update {
old, err := UnmarshalPolicyException(request.OldObject.Raw)
return exception, old, err
}
return exception, empty, nil
}