Commit e752a48a authored by Jordan Liggitt's avatar Jordan Liggitt

Explicitly set GVK when sending objects to webhooks

parent 8d6f20ea
...@@ -37,5 +37,7 @@ func ConvertToGVK(obj runtime.Object, gvk schema.GroupVersionKind, o admission.O ...@@ -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) { ...@@ -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) { ...@@ -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{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment