Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter nodeconfig event before reconcile #267

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions pkg/clusterlink/agent/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package agent

import (
"context"
"fmt"
"time"

apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -19,6 +18,7 @@ import (

kosmosv1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1"
networkmanager "github.com/kosmos.io/kosmos/pkg/clusterlink/agent/network-manager"
"github.com/kosmos.io/kosmos/pkg/clusterlink/controllers/node"
"github.com/kosmos.io/kosmos/pkg/clusterlink/network"
kosmosv1alpha1lister "github.com/kosmos.io/kosmos/pkg/generated/listers/kosmos/v1alpha1"
)
Expand All @@ -44,30 +44,42 @@ func NetworkManager() *networkmanager.NetworkManager {
return networkmanager.NewNetworkManager(net)
}

var predicatesFunc = predicate.Funcs{
CreateFunc: func(createEvent event.CreateEvent) bool {
return true
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
return true
},
DeleteFunc: func(deleteEvent event.DeleteEvent) bool {
return true
},
GenericFunc: func(genericEvent event.GenericEvent) bool {
return true
},
}

func (r *Reconciler) SetupWithManager(mgr manager.Manager) error {
if r.Client == nil {
r.Client = mgr.GetClient()
}

skipEvent := func(obj client.Object) bool {
eventObj, ok := obj.(*kosmosv1alpha1.NodeConfig)
if !ok {
return false
}

if eventObj.Name != node.ClusterNodeName(r.ClusterName, r.NodeName) {
klog.Infof("reconcile node name: %s, current node name: %s-%s", eventObj.Name, r.ClusterName, r.NodeName)
return false
}

return true
}

return ctrl.NewControllerManagedBy(mgr).
Named(controllerName).
WithOptions(controller.Options{}).
For(&kosmosv1alpha1.NodeConfig{}, builder.WithPredicates(predicatesFunc)).
For(&kosmosv1alpha1.NodeConfig{}, builder.WithPredicates(predicate.Funcs{
CreateFunc: func(createEvent event.CreateEvent) bool {
return skipEvent(createEvent.Object)
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
return skipEvent(updateEvent.ObjectNew)
},
DeleteFunc: func(deleteEvent event.DeleteEvent) bool {
return skipEvent(deleteEvent.Object)
},
GenericFunc: func(genericEvent event.GenericEvent) bool {
return skipEvent(genericEvent.Object)
},
})).
Complete(r)
}

Expand Down Expand Up @@ -97,12 +109,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
return reconcile.Result{RequeueAfter: RequeueTime}, nil
}

klog.Infof("reconcile node name: %s, current node name: %s-%s", reconcileNode.Name, r.ClusterName, r.NodeName)
if reconcileNode.Name != fmt.Sprintf("%s-%s", r.ClusterName, r.NodeName) {
klog.Infof("not match, drop this event.")
return reconcile.Result{}, nil
}

localCluster, err := r.ClusterLister.Get(r.ClusterName)
if err != nil {
klog.Errorf("could not get local cluster, clusterNode: %s, err: %v", r.NodeName, err)
Expand Down
Loading