Skip to content

Commit

Permalink
Merge pull request #992 from spidernet-io/reduce
Browse files Browse the repository at this point in the history
Reduce the data impact caused by EgressTunnel updates
  • Loading branch information
weizhoublue authored Nov 21, 2023
2 parents 8149aad + ea3e86c commit 0fc60b5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pkg/agent/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"net"
"reflect"
"strconv"
"strings"
"sync"
Expand All @@ -20,6 +21,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"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/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -917,7 +919,9 @@ func newEgressTunnelController(mgr manager.Manager, cfg *config.Config, log logr
}

if err := c.Watch(source.Kind(mgr.GetCache(), &egressv1.EgressTunnel{}),
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressTunnel"))); err != nil {
handler.EnqueueRequestsFromMapFunc(utils.KindToMapFlat("EgressTunnel")),
egressTunnelPredicate{},
); err != nil {
return fmt.Errorf("failed to watch EgressTunnel: %w", err)
}

Expand Down Expand Up @@ -947,3 +951,29 @@ func newEgressTunnelController(mgr manager.Manager, cfg *config.Config, log logr

return nil
}

type egressTunnelPredicate struct{}

func (p egressTunnelPredicate) Create(_ event.CreateEvent) bool { return true }
func (p egressTunnelPredicate) Delete(_ event.DeleteEvent) bool { return true }
func (p egressTunnelPredicate) Update(updateEvent event.UpdateEvent) bool {
oldEgressTunnel, ok := updateEvent.ObjectOld.(*egressv1.EgressTunnel)
if !ok {
return false
}
newEgressTunnel, ok := updateEvent.ObjectNew.(*egressv1.EgressTunnel)
if !ok {
return false
}
if !reflect.DeepEqual(oldEgressTunnel.Status.Tunnel, newEgressTunnel.Status.Tunnel) {
return true
}
if oldEgressTunnel.Status.Phase != newEgressTunnel.Status.Phase {
return true
}
if oldEgressTunnel.Status.Mark != newEgressTunnel.Status.Mark {
return true
}
return false
}
func (p egressTunnelPredicate) Generic(_ event.GenericEvent) bool { return false }

0 comments on commit 0fc60b5

Please sign in to comment.