Skip to content

Commit

Permalink
chore: just pass bool
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-lloyd committed Jan 7, 2025
1 parent a001931 commit 82ac882
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 6 additions & 8 deletions cns/kubecontroller/nodenetworkconfig/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"sync"

"github.com/Azure/azure-container-networking/cns"
"github.com/Azure/azure-container-networking/cns/configuration"
"github.com/Azure/azure-container-networking/cns/logger"
"github.com/Azure/azure-container-networking/cns/restserver"
cnstypes "github.com/Azure/azure-container-networking/cns/types"
Expand Down Expand Up @@ -158,26 +157,25 @@ 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 {
// filterGenerationChange will check the old and new object's generation and only reconcile updates where the
// generation is the same. This is typically used in IPAMv1 but should be set to false in IPAMv2.
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager, node *v1.Node, filterGenerationChange bool) 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
},
// 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 ipamV2Enabled {
return true
if filterGenerationChange {
return ue.ObjectOld.GetGeneration() == ue.ObjectNew.GetGeneration()
}
return ue.ObjectOld.GetGeneration() == ue.ObjectNew.GetGeneration()
return true
},
}).
WithEventFilter(predicate.NewPredicateFuncs(func(object client.Object) bool {
Expand Down
5 changes: 4 additions & 1 deletion cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,10 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
nodeIP := configuration.NodeIP()
nncReconciler := nncctrl.NewReconciler(httpRestServiceImplementation, poolMonitor, nodeIP)
// pass Node to the Reconciler for Controller xref
if err := nncReconciler.SetupWithManager(manager, node, cnsconfig); err != nil { //nolint:govet // intentional shadow
// IPAMv1 - reconcile only status changes (where generation doesn't change).
// IPAMv2 - reconcile all updates.
filterGenerationChange := !cnsconfig.EnableIPAMv2
if err := nncReconciler.SetupWithManager(manager, node, filterGenerationChange); err != nil { //nolint:govet // intentional shadow
return errors.Wrapf(err, "failed to setup nnc reconciler with manager")
}

Expand Down

0 comments on commit 82ac882

Please sign in to comment.