f-41: config, frr: base BGP pilotée par l'agent au démarrage #41

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-11 19:52:46 +02:00
commit bf0e83862f
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
12 changed files with 331 additions and 18 deletions

View file

@ -13,7 +13,9 @@ import (
agentapi "git.g3e.fr/syonad/two/internal/api/agent"
configuration "git.g3e.fr/syonad/two/internal/config/agent"
dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent"
"git.g3e.fr/syonad/two/internal/frr"
"git.g3e.fr/syonad/two/internal/migration"
"git.g3e.fr/syonad/two/internal/netif"
agentmetrics "git.g3e.fr/syonad/two/internal/prometheus/agent"
"git.g3e.fr/syonad/two/internal/watchdog"
"git.g3e.fr/syonad/two/internal/watchdog/notify"
@ -58,6 +60,14 @@ func main() {
return
}
if cfg.BGP.Enabled() {
if err := applyBGPBase(cfg, frr.NewClient()); err != nil {
log.Error("failed to apply the bgp base configuration", "error", err)
return
}
log.Info("bgp base configuration applied", "asn", cfg.BGP.ASN, "route_reflectors", cfg.BGP.RouteReflectors)
}
q := worker.New(cfg.Worker.BufferSize)
q.Start(cfg.Worker.Count)
@ -110,6 +120,22 @@ func main() {
closeDB = shutdown(log, q, servers, shutdownTimeout)
}
type baseApplier interface {
ApplyBase(frr.Base) error
}
func applyBGPBase(cfg *configuration.Config, frrClient baseApplier) error {
reflectors, err := cfg.BGP.Reflectors()
if err != nil {
return err
}
vtep, err := netif.VTEPAddress(cfg.DefaultInterface)
if err != nil {
return err
}
return frrClient.ApplyBase(frr.Base{ASN: cfg.BGP.ASN, RouterID: vtep, RouteReflectors: reflectors})
}
type httpShutdowner interface {
Shutdown(context.Context) error
}