Skip to content

Commit 3ec1a42

Browse files
committed
watch multiple group versions
Signed-off-by: zirain <zirain2009@gmail.com>
1 parent 3c310a2 commit 3ec1a42

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/provider/kubernetes/controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
19001900
}
19011901
}
19021902

1903-
r.tlsRouteCRDExists = r.crdExists(mgr, resource.KindTLSRoute, gwapiv1a3.GroupVersion.String())
1903+
r.tlsRouteCRDExists = r.crdExists(mgr, resource.KindTLSRoute, gwapiv1a2.GroupVersion.String(), gwapiv1a3.GroupVersion.String())
19041904
if !r.tlsRouteCRDExists {
19051905
r.log.Info("TLSRoute CRD not found, skipping TLSRoute watch")
19061906
} else {
@@ -2294,7 +2294,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M
22942294
}
22952295
}
22962296

2297-
r.bTLSPolicyCRDExists = r.crdExists(mgr, resource.KindBackendTLSPolicy, gwapiv1.GroupVersion.String())
2297+
r.bTLSPolicyCRDExists = r.crdExists(mgr, resource.KindBackendTLSPolicy, gwapiv1.GroupVersion.String(), gwapiv1a3.GroupVersion.String())
22982298
if !r.bTLSPolicyCRDExists {
22992299
r.log.Info("BackendTLSPolicy CRD not found, skipping BackendTLSPolicy watch")
23002300
} else {
@@ -2564,7 +2564,8 @@ func (r *gatewayAPIReconciler) processEnvoyProxy(ep *egv1a1.EnvoyProxy, resource
25642564
}
25652565

25662566
// crdExists checks for the existence of the CRD in k8s APIServer before watching it
2567-
func (r *gatewayAPIReconciler) crdExists(mgr manager.Manager, kind, groupVersion string) bool {
2567+
func (r *gatewayAPIReconciler) crdExists(mgr manager.Manager, kind string, groupVersion ...string) bool {
2568+
groupVersionList := sets.New[string](groupVersion...)
25682569
discoveryClient, err := discovery.NewDiscoveryClientForConfig(mgr.GetConfig())
25692570
if err != nil {
25702571
r.log.Error(err, "failed to create discovery client")
@@ -2577,7 +2578,7 @@ func (r *gatewayAPIReconciler) crdExists(mgr manager.Manager, kind, groupVersion
25772578
for _, list := range apiResourceList {
25782579
for i := range list.APIResources {
25792580
res := &list.APIResources[i]
2580-
if list.GroupVersion == groupVersion && res.Kind == kind {
2581+
if groupVersionList.Has(list.GroupVersion) && res.Kind == kind {
25812582
found = true
25822583
break
25832584
}

0 commit comments

Comments
 (0)