diff --git a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/conversion.go b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/conversion.go index f00e0bc0154..11f704f736a 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/conversion.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/conversion.go @@ -37,5 +37,7 @@ func ConvertToGVK(obj runtime.Object, gvk schema.GroupVersionKind, o admission.O if err != nil { return nil, err } + // Explicitly set the GVK + out.GetObjectKind().SetGroupVersionKind(gvk) return out, nil } diff --git a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/conversion_test.go b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/conversion_test.go index 5bb70d1b4b9..5482b7b5ab1 100644 --- a/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/conversion_test.go +++ b/staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/conversion_test.go @@ -62,6 +62,10 @@ func TestConvertToGVK(t *testing.T) { }, gvk: examplev1.SchemeGroupVersion.WithKind("Pod"), expectedObj: &examplev1.Pod{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "example.apiserver.k8s.io/v1", + Kind: "Pod", + }, ObjectMeta: metav1.ObjectMeta{ Name: "pod1", Labels: map[string]string{ @@ -87,6 +91,10 @@ func TestConvertToGVK(t *testing.T) { }, gvk: example2v1.SchemeGroupVersion.WithKind("ReplicaSet"), expectedObj: &example2v1.ReplicaSet{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "example2.apiserver.k8s.io/v1", + Kind: "ReplicaSet", + }, ObjectMeta: metav1.ObjectMeta{ Name: "rs1", Labels: map[string]string{