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/metadata.go
Charles-Edouard Brétéché 767e576a9a
refactor: ttl label validation (#7960)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-08-03 12:48:10 +08:00

31 lines
839 B
Go

package admission
import (
"encoding/json"
admissionv1 "k8s.io/api/admission/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func UnmarshalPartialObjectMetadata(raw []byte) (*metav1.PartialObjectMetadata, error) {
var object *metav1.PartialObjectMetadata
if err := json.Unmarshal(raw, &object); err != nil {
return nil, err
}
return object, nil
}
func GetPartialObjectMetadatas(request admissionv1.AdmissionRequest) (*metav1.PartialObjectMetadata, *metav1.PartialObjectMetadata, error) {
object, err := UnmarshalPartialObjectMetadata(request.Object.Raw)
if err != nil {
return nil, nil, err
}
if request.Operation != admissionv1.Update {
return object, nil, nil
}
oldObject, err := UnmarshalPartialObjectMetadata(request.OldObject.Raw)
if err != nil {
return nil, nil, err
}
return object, oldObject, nil
}