@@ -28,8 +28,11 @@ import (
2828 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929 "k8s.io/apimachinery/pkg/runtime"
3030 "k8s.io/apimachinery/pkg/types"
31+ "k8s.io/client-go/util/workqueue"
3132 ctrl "sigs.k8s.io/controller-runtime"
33+ "sigs.k8s.io/controller-runtime/pkg/builder"
3234 "sigs.k8s.io/controller-runtime/pkg/client"
35+ "sigs.k8s.io/controller-runtime/pkg/event"
3336 "sigs.k8s.io/controller-runtime/pkg/handler"
3437 "sigs.k8s.io/controller-runtime/pkg/reconcile"
3538 "sigs.k8s.io/controller-runtime/pkg/source"
@@ -249,20 +252,33 @@ func (r *NicClusterPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
249252 }
250253 r .stateManager = stateManager
251254
252- builder := ctrl .NewControllerManagedBy (mgr ).
255+ ctl := ctrl .NewControllerManagedBy (mgr ).
253256 For (& mellanoxv1alpha1.NicClusterPolicy {}).
254257 // Watch for changes to primary resource NicClusterPolicy
255258 Watches (& source.Kind {Type : & mellanoxv1alpha1.NicClusterPolicy {}}, & handler.EnqueueRequestForObject {})
256259
257- // Watch for changes to secondary resource DaemonSet and requeue the owner NicClusterPolicy
260+ // we always add object with a same(static) key to the queue to reduce
261+ // reconciliation count
262+ updateEnqueue := handler.Funcs {
263+ UpdateFunc : func (e event.UpdateEvent , q workqueue.RateLimitingInterface ) {
264+ q .Add (reconcile.Request {NamespacedName : types.NamespacedName {
265+ Name : consts .NicClusterPolicyResourceName ,
266+ }})
267+ },
268+ }
269+
270+ // Watch for "feature.node.kubernetes.io/pci-15b3.present" label applying
271+ nodePredicates := builder .WithPredicates (MlnxLabelChangedPredicate {})
272+ ctl = ctl .Watches (& source.Kind {Type : & corev1.Node {}}, updateEnqueue , nodePredicates )
273+
258274 ws := stateManager .GetWatchSources ()
259275 r .Log .V (consts .LogLevelInfo ).Info ("Watch Sources" , "Kind:" , ws )
260276 for i := range ws {
261- builder = builder .Watches (ws [i ], & handler.EnqueueRequestForOwner {
277+ ctl = ctl .Watches (ws [i ], & handler.EnqueueRequestForOwner {
262278 IsController : true ,
263279 OwnerType : & mellanoxv1alpha1.NicClusterPolicy {},
264280 })
265281 }
266282
267- return builder .Complete (r )
283+ return ctl .Complete (r )
268284}
0 commit comments