Skip to content

Commit

Permalink
gatewayapi: Use single watch for CRDs
Browse files Browse the repository at this point in the history
Replace the multiple watches for Gateway API CRDs with a single CRD watch, with
a predicate to filter CRDs based on the gatewayapiv1.GroupName.  This ensures
that only relevant CRDs are watched, reducing unnecessary reconciliation
requests and log messages.

This commit fixes OCPBUGS-41892.

https://issues.redhat.com/browse/OCPBUGS-41892
  • Loading branch information
Ali Syed committed Nov 28, 2024
1 parent aa8860a commit f3551d0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/operator/controller/gatewayapi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import (

configv1 "github.com/openshift/api/config/v1"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/types"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

const (
Expand Down Expand Up @@ -60,15 +61,12 @@ func New(mgr manager.Manager, config Config) (controller.Controller, error) {
}

// watch for CRDs
for i := range managedCRDs {
if err = c.Watch(source.Kind[client.Object](operatorCache, managedCRDs[i], handler.EnqueueRequestsFromMapFunc(toFeatureGate), predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool { return false },
DeleteFunc: func(e event.DeleteEvent) bool { return true },
UpdateFunc: func(e event.UpdateEvent) bool { return false },
GenericFunc: func(e event.GenericEvent) bool { return false },
})); err != nil {
return nil, err
}
crdPredicate := predicate.NewPredicateFuncs(func(o client.Object) bool {
return o.(*apiextensionsv1.CustomResourceDefinition).Spec.Group == gatewayapiv1.GroupName
})

if err := c.Watch(source.Kind[client.Object](operatorCache, &apiextensionsv1.CustomResourceDefinition{}, handler.EnqueueRequestsFromMapFunc(toFeatureGate), crdPredicate)); err != nil {
return nil, err
}
return c, nil
}
Expand Down

0 comments on commit f3551d0

Please sign in to comment.