Skip to content

Commit 3929c84

Browse files
committed
envtest: get gvk from hook struct instead of forcing set TypeMeta
Signed-off-by: Stefan Büringer [email protected]
1 parent 1730628 commit 3929c84

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

pkg/envtest/webhook.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import (
2929
"k8s.io/apimachinery/pkg/runtime/schema"
3030
"k8s.io/apimachinery/pkg/util/sets"
3131
"k8s.io/apimachinery/pkg/util/wait"
32+
"k8s.io/client-go/kubernetes/scheme"
3233
"k8s.io/client-go/rest"
34+
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
3335
"sigs.k8s.io/yaml"
3436

3537
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -175,17 +177,29 @@ func WaitForWebhooks(config *rest.Config,
175177
waitingFor := map[schema.GroupVersionKind]*sets.String{}
176178

177179
for _, hook := range mutatingWebhooks {
178-
if _, ok := waitingFor[hook.GroupVersionKind()]; !ok {
179-
waitingFor[hook.GroupVersionKind()] = &sets.String{}
180+
h := hook
181+
gvk, err := apiutil.GVKForObject(&h, scheme.Scheme)
182+
if err != nil {
183+
return fmt.Errorf("unable to get gvk for MutatingWebhookConfiguration %s: %v", hook.GetName(), err)
184+
}
185+
186+
if _, ok := waitingFor[gvk]; !ok {
187+
waitingFor[gvk] = &sets.String{}
180188
}
181-
waitingFor[hook.GroupVersionKind()].Insert(hook.GetName())
189+
waitingFor[gvk].Insert(h.GetName())
182190
}
183191

184192
for _, hook := range validatingWebhooks {
185-
if _, ok := waitingFor[hook.GroupVersionKind()]; !ok {
186-
waitingFor[hook.GroupVersionKind()] = &sets.String{}
193+
h := hook
194+
gvk, err := apiutil.GVKForObject(&h, scheme.Scheme)
195+
if err != nil {
196+
return fmt.Errorf("unable to get gvk for ValidatingWebhookConfiguration %s: %v", hook.GetName(), err)
197+
}
198+
199+
if _, ok := waitingFor[gvk]; !ok {
200+
waitingFor[gvk] = &sets.String{}
187201
}
188-
waitingFor[hook.GroupVersionKind()].Insert(hook.GetName())
202+
waitingFor[gvk].Insert(hook.GetName())
189203
}
190204

191205
// Poll until all resources are found in discovery

0 commit comments

Comments
 (0)