Skip to content

Commit

Permalink
envtest: get gvk from hook struct instead of forcing set TypeMeta
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer buringerst@vmware.com
  • Loading branch information
sbueringer committed Sep 16, 2021
1 parent 1730628 commit 3929c84
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions pkg/envtest/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3929c84

Please sign in to comment.