diff --git a/pkg/envtest/webhook.go b/pkg/envtest/webhook.go index d19032534d..8578590206 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,27 @@ 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{} + gvk, err := apiutil.GVKForObject(&hook, 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(hook.GetName()) } for _, hook := range validatingWebhooks { - if _, ok := waitingFor[hook.GroupVersionKind()]; !ok { - waitingFor[hook.GroupVersionKind()] = &sets.String{} + gvk, err := apiutil.GVKForObject(&hook, 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