refactor: split routeWatcher into watcher and handler components #797
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This refactors the
RouteWatchercomponent by separating the route watching functionality from the route handling logic.Previously, the
RouteWatcherused to (i) monitor netlink route updates and address changes and (ii) respond to network and IPAM configuration events via pubsub. Because of this, theRouteWatcherneeded to be passed to theNetWatcherjust so it could subscribe to events, and the event handling logic was mixed with route watching logic.Now, we have a new handler component
RouteHandlerthat implements three event handling methods:OnNetDeleted(netDef *common.NetworkDefinition) errorOnNetAddedOrUpdated(netDef *common.NetworkDefinition) errorOnIpamConfChanged(oldPool, newPool *proto.IPAMPool) errorand holds a reference to
RouteWatcherto perform route operations.The
RouteWatcheris now purely focused on route watching. It no longer subscribes to pubsub or performs any event handling. It is only responsible for netlink route/address monitoring.NetWatcherand IPAM configuration changes now directly call theRouteHandlerinstead of sending pubsub events resulting in network and IPAM events being synchronously processed when they occur.NetWatcherno longer needs to know aboutRouteWatcher, it only knows about theRouteHandlerinterface.Events are now processed directly:
NetWatcher→RouteHandler→RouteWatcherPreviously:
NetWatcher→SendEvent→PubSub→RouteWatcher.eventChan→RouteWatcherMade the changes on top of the nsk-split-svc branch for now, will rebase on top of master once those commits for single thread agent are merged.