From 3929c84324c55c1a28daf3c531dae7c125341b36 Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Thu, 16 Sep 2021 11:50:45 +0200 Subject: [PATCH] envtest: get gvk from hook struct instead of forcing set TypeMeta MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Büringer buringerst@vmware.com --- pkg/envtest/webhook.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/envtest/webhook.go b/pkg/envtest/webhook.go index d19032534d..bdd160bb2d 100644 --- a/pkg/envtest/webhook.go +++ b/pkg/envtest/webhook.go @@ -29,7 +29,9 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client/apiutil" "sigs.k8s.io/yaml" "sigs.k8s.io/controller-runtime/pkg/client" @@ -175,17 +177,29 @@ func WaitForWebhooks(config *rest.Config, waitingFor := map[schema.GroupVersionKind]*sets.String{} for _, hook := range mutatingWebhooks { - if _, ok := waitingFor[hook.GroupVersionKind()]; !ok { - waitingFor[hook.GroupVersionKind()] = &sets.String{} + h := hook + gvk, err := apiutil.GVKForObject(&h, scheme.Scheme) + if err != nil { + return fmt.Errorf("unable to get gvk for MutatingWebhookConfiguration %s: %v", hook.GetName(), err) + } + + if _, ok := waitingFor[gvk]; !ok { + waitingFor[gvk] = &sets.String{} } - waitingFor[hook.GroupVersionKind()].Insert(hook.GetName()) + waitingFor[gvk].Insert(h.GetName()) } for _, hook := range validatingWebhooks { - if _, ok := waitingFor[hook.GroupVersionKind()]; !ok { - waitingFor[hook.GroupVersionKind()] = &sets.String{} + h := hook + gvk, err := apiutil.GVKForObject(&h, scheme.Scheme) + if err != nil { + return fmt.Errorf("unable to get gvk for ValidatingWebhookConfiguration %s: %v", hook.GetName(), err) + } + + if _, ok := waitingFor[gvk]; !ok { + waitingFor[gvk] = &sets.String{} } - waitingFor[hook.GroupVersionKind()].Insert(hook.GetName()) + waitingFor[gvk].Insert(hook.GetName()) } // Poll until all resources are found in discovery