Skip to content

Commit

Permalink
Merge pull request #1665 from sbueringer/pr-fix-envtest-webhook-wait
Browse files Browse the repository at this point in the history
🐛  envtest: get gvk from hook struct instead of forcing set TypeMeta
  • Loading branch information
k8s-ci-robot authored Sep 16, 2021
2 parents f20692b + 3929c84 commit 394eaa7
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 394eaa7

Please sign in to comment.