Merge pull request #74448 from liggitt/webhook-gvk

Explicitly set GVK when sending objects to webhooks
This commit is contained in:
Kubernetes Prow Robot 2019-02-26 12:44:35 -08:00 committed by GitHub
commit 7d67315d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -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
}

View File

@ -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{