Skip to content

Commit

Permalink
Fix periodic re-reconciles of NNCPs with name equal to node (#957) (#967
Browse files Browse the repository at this point in the history
)

Policies that are named the same as worker nodes are getting
periodically re-reconciled.
It seems that the For(&corev1.Node{}) creates a watch of it's own
that overrides the builder.WithPredicates(onLabelsUpdatedForThisNode)
defined in the subsequent Watches(...) statement.

This commit creates the controller manually without using
controller-runtime builder.

Signed-off-by: Radim Hrazdil <[email protected]>
  • Loading branch information
rhrazdil authored Jan 20, 2022
1 parent ee60e47 commit cbcd8da
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions controllers/nodenetworkconfigurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"k8s.io/client-go/util/retry"

ctrl "sigs.k8s.io/controller-runtime"
builder "sigs.k8s.io/controller-runtime/pkg/builder"
"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/predicate"
Expand Down Expand Up @@ -241,13 +241,19 @@ func (r *NodeNetworkConfigurationPolicyReconciler) SetupWithManager(mgr ctrl.Man

// Reconcile all NNCPs if Node is updated (for example labels are changed), node creation event
// is not needed since all NNCPs are going to be Reconcile at node startup.
err = ctrl.NewControllerManagedBy(mgr).
For(&corev1.Node{}).
Watches(&source.Kind{Type: &corev1.Node{}}, handler.EnqueueRequestsFromMapFunc(allPolicies), builder.WithPredicates(onLabelsUpdatedForThisNode)).
Complete(r)
c, err := controller.New("node_labels", mgr, controller.Options{Reconciler: r})
if err != nil {
return errors.Wrap(err, "failed to create node_labels controller to NNCP Reconciler watching node label changes")
}
err = c.Watch(
&source.Kind{Type: &corev1.Node{}},
handler.EnqueueRequestsFromMapFunc(allPolicies),
onLabelsUpdatedForThisNode,
)
if err != nil {
return errors.Wrap(err, "failed to add controller to NNCP Reconciler listening Node events")
return errors.Wrap(err, "failed to add watch to enqueue NNCPs reconcile on node label change")
}

return nil
}

Expand Down

0 comments on commit cbcd8da

Please sign in to comment.