Skip to content

Commit

Permalink
chore: reduce refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-lloyd committed Dec 31, 2024
1 parent 8474fb6 commit 985f51e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cns/kubecontroller/nodenetworkconfig/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,30 @@ func (r *Reconciler) Started(ctx context.Context) (bool, error) {
// SetupWithManager Sets up the reconciler with a new manager, filtering using NodeNetworkConfigFilter on nodeName.
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, node *v1.Node, cnsconfig *configuration.CNSConfig) error {
r.nnccli = nodenetworkconfig.NewClient(mgr.GetClient())
ipamV2Enabled := cnsconfig != nil && cnsconfig.EnableIPAMv2
err := ctrl.NewControllerManagedBy(mgr).
For(&v1alpha.NodeNetworkConfig{}).
WithEventFilter(predicate.Funcs{
// ignore delete events.
DeleteFunc: func(event.DeleteEvent) bool {
return false
},
}).
WithEventFilter(predicate.NewPredicateFuncs(func(object client.Object) bool {
// match on node controller ref for all other events.
return metav1.IsControlledBy(object, node)
})).
WithEventFilter(predicate.Funcs{
// check that the generation is the same iff IPAMv1 - status changes don't update generation.
// check that the generation is the same if IPAMv1 - status changes don't update generation.
UpdateFunc: func(ue event.UpdateEvent) bool {
if ue.ObjectOld == nil || ue.ObjectNew == nil {
return false
}
// IPAMv2 is idempotent and can process every update event.
if cnsconfig != nil && cnsconfig.EnableIPAMv2 {
if ipamV2Enabled {
return true
}
return ue.ObjectOld.GetGeneration() == ue.ObjectNew.GetGeneration()
},
}).
WithEventFilter(predicate.NewPredicateFuncs(func(object client.Object) bool {
// match on node controller ref for all other events.
return metav1.IsControlledBy(object, node)
})).
WithEventFilter(predicate.NewPredicateFuncs(func(object client.Object) bool {
// only process events on objects that are not being deleted.
return object.GetDeletionTimestamp().IsZero()
Expand Down

0 comments on commit 985f51e

Please sign in to comment.