mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Explicitly set GVK when sending objects to webhooks
This commit is contained in:
parent
8d6f20ea43
commit
e752a48a30
@ -37,5 +37,7 @@ func ConvertToGVK(obj runtime.Object, gvk schema.GroupVersionKind, o admission.O
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Explicitly set the GVK
|
||||||
|
out.GetObjectKind().SetGroupVersionKind(gvk)
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,10 @@ func TestConvertToGVK(t *testing.T) {
|
|||||||
},
|
},
|
||||||
gvk: examplev1.SchemeGroupVersion.WithKind("Pod"),
|
gvk: examplev1.SchemeGroupVersion.WithKind("Pod"),
|
||||||
expectedObj: &examplev1.Pod{
|
expectedObj: &examplev1.Pod{
|
||||||
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
APIVersion: "example.apiserver.k8s.io/v1",
|
||||||
|
Kind: "Pod",
|
||||||
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "pod1",
|
Name: "pod1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
@ -87,6 +91,10 @@ func TestConvertToGVK(t *testing.T) {
|
|||||||
},
|
},
|
||||||
gvk: example2v1.SchemeGroupVersion.WithKind("ReplicaSet"),
|
gvk: example2v1.SchemeGroupVersion.WithKind("ReplicaSet"),
|
||||||
expectedObj: &example2v1.ReplicaSet{
|
expectedObj: &example2v1.ReplicaSet{
|
||||||
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
APIVersion: "example2.apiserver.k8s.io/v1",
|
||||||
|
Kind: "ReplicaSet",
|
||||||
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "rs1",
|
Name: "rs1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
|
Loading…
Reference in New Issue
Block a user