Skip to content

[refactor] make BGP peer and secret management system event-driven#790

Open
aritrbas wants to merge 1 commit into
nsk-split-svcfrom
abasu-peers-watcher-rem-pubsub
Open

[refactor] make BGP peer and secret management system event-driven#790
aritrbas wants to merge 1 commit into
nsk-split-svcfrom
abasu-peers-watcher-rem-pubsub

Conversation

@aritrbas

@aritrbas aritrbas commented Sep 11, 2025

Copy link
Copy Markdown
Collaborator

Summary

This PR refactors the BGP peer and secret management system from a tightly-coupled handler-based architecture to a loosely-coupled event-driven system.

Changes by Component

1. PeerWatcher (watchers/peers_watcher.go)

  • Added local peer cache: cachedPeers map[string]calicov3.BGPPeer
  • Added granular events:
    • PeerAdded - single new peer added
    • PeerUpdated - single existing peer updated
    • PeerDeleted - single existing peer deleted
    • PeersChanged - for initial state reconciliation only
  • Updates SecretWatcher proactively on peer list changes
  • Achieves O(1) cache lookups instead of O(N) API list calls

2. SecretWatcher (watchers/secret_watcher.go)

  • Removed GetSecret() method (blocking) with events
  • Removed SweepStale() method (replaced with OnPeerListUpdated)
  • Emits granular events:
    • SecretAdded - new secret available
    • SecretChanged - existing secret modified
    • SecretDeleted - existing secret removed
  • Proactive secret watching via OnPeerListUpdated() - starts watches when peers are added
  • Automatic cleanup of stale secret watches when peers are deleted

3. PeerHandler (routing/peer_handler.go)

  • Added local secret cache: secretCache map[string]map[string]string
  • Added granular peer event handlers:
    • OnPeerAdded(peer) - O(1) processing for single peer
    • OnPeerUpdated(old, new) - O(1) diff and update
    • OnPeerDeleted(peer) - O(1) removal
  • Added granular secret event handlers:
    • OnSecretAdded(secretData) - cache secret locally
    • OnSecretChanged(secretName) - mark affected peers for update
    • OnSecretDeleted(secretName) - remove from cache
  • Added ProcessPeers() for initial reconciliation only

4. FelixServer (felix/felix_server.go)

  • Registered for new event types: PeersChanged, PeerAdded, PeerUpdated, PeerDeleted, SecretAdded, SecretChanged, SecretDeleted
  • Acts as an event coordinator (no business logic); routes events to appropriate PeerHandler methods

Made 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.

@aritrbas aritrbas self-assigned this Sep 11, 2025
@aritrbas aritrbas force-pushed the abasu-peers-watcher-rem-pubsub branch from 6fee584 to 2c22c24 Compare October 1, 2025 04:18
@aritrbas aritrbas force-pushed the abasu-peers-watcher-rem-pubsub branch 2 times, most recently from ffb8c29 to eb5adeb Compare October 10, 2025 00:20

@sknat sknat left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for taking a stab at this !
A couple comments inline, I think there is still room for more untangling of the logic.
Tell me if anything sounds unclear

Comment thread calico-vpp-agent/watchers/peers_watcher.go Outdated
Comment thread calico-vpp-agent/watchers/peers_watcher.go Outdated
Comment thread calico-vpp-agent/watchers/peers_watcher.go Outdated
Comment thread calico-vpp-agent/watchers/peers_watcher.go Outdated
Comment thread calico-vpp-agent/watchers/secret_watcher.go Outdated
Comment thread calico-vpp-agent/routing/peer_handler.go Outdated
Comment thread calico-vpp-agent/watchers/peers_watcher.go Outdated
Comment thread calico-vpp-agent/watchers/peers_watcher.go Outdated
Comment thread calico-vpp-agent/watchers/secret_watcher.go Outdated
Comment thread calico-vpp-agent/watchers/peers_watcher.go Outdated
@aritrbas aritrbas force-pushed the abasu-peers-watcher-rem-pubsub branch from eb5adeb to d64a12d Compare October 23, 2025 22:34
@aritrbas aritrbas changed the title Remove peers_watcher dependency on pubsub refactor: make BGP peer and secret management system event-driven Oct 23, 2025
@sknat sknat added this to the agent refactoring single thread milestone Nov 17, 2025
@sknat sknat changed the title refactor: make BGP peer and secret management system event-driven [refactor] make BGP peer and secret management system event-driven Jan 7, 2026
@aritrbas aritrbas force-pushed the abasu-peers-watcher-rem-pubsub branch from d64a12d to 4cc6f82 Compare May 19, 2026 23:30
Signed-off-by: Aritra Basu <aritrbas+gh@cisco.com>
@aritrbas aritrbas force-pushed the abasu-peers-watcher-rem-pubsub branch from 4cc6f82 to 7041ac6 Compare May 20, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants