Skip to content

Commit 43c6eaa

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 43c6eaa

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

pkg/envtest/webhook.go

Lines changed: 18 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,27 @@ 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+
gvk, err := apiutil.GVKForObject(&hook, scheme.Scheme)
181+
if err != nil {
182+
return fmt.Errorf("unable to get gvk for MutatingWebhookConfiguration %s: %v", hook.GetName(), err)
183+
}
184+
185+
if _, ok := waitingFor[gvk]; !ok {
186+
waitingFor[gvk] = &sets.String{}
180187
}
181-
waitingFor[hook.GroupVersionKind()].Insert(hook.GetName())
188+
waitingFor[gvk].Insert(hook.GetName())
182189
}
183190

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

191203
// Poll until all resources are found in discovery

0 commit comments

Comments
 (0)