From 95cafb5decceda6963926e49beb6bf4aa164029f Mon Sep 17 00:00:00 2001 From: zongzw Date: Wed, 14 Dec 2022 20:39:49 +0800 Subject: [PATCH] enable BGP routing when legacy and TMOS mode. Cannot mix routing-protocol Legacy and TMOS mode for route-domain (/Common/0) --- main.go | 2 +- pkg/deployer.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d851aa7..75e4ba0 100644 --- a/main.go +++ b/main.go @@ -279,7 +279,7 @@ func setupBIGIPs() error { bc := &f5_bigip.BIGIPContext{BIGIP: *bigip, Context: context.TODO()} if c.Calico != nil { - if err := bc.ModifyDbValue("tmrouted.tmos.routing", "enable"); err != nil { + if err := pkg.EnableBGPRouting(bc); err != nil { errs = append(errs, fmt.Sprintf("config #%d: %s", i, err.Error())) continue } diff --git a/pkg/deployer.go b/pkg/deployer.go index 72e36e2..b39e039 100644 --- a/pkg/deployer.go +++ b/pkg/deployer.go @@ -1,6 +1,8 @@ package pkg import ( + "fmt" + f5_bigip "gitee.com/zongzw/f5-bigip-rest/bigip" "gitee.com/zongzw/f5-bigip-rest/utils" ) @@ -114,3 +116,34 @@ func Deployer(stopCh chan struct{}, bigips []*f5_bigip.BIGIP) { } } } + +func EnableBGPRouting(bc *f5_bigip.BIGIPContext) error { + kind := "net/route-domain" + partition, subfolder, name := "Common", "", "0" // route domain 0 + + exists, err := bc.Exist(kind, name, partition, subfolder) + if err != nil { + return err + } + if exists == nil { + return fmt.Errorf("route domain 0 must exist. check it") + } + // "Cannot mix routing-protocol Legacy and TMOS mode for route-domain (/Common/0)." + // We need to remove "BGP" from routingProtocol for TMOS mode + if (*exists)["routingProtocol"] != nil { + nrps := []interface{}{} + for _, rp := range (*exists)["routingProtocol"].([]interface{}) { + if rp.(string) != "BGP" { + nrps = append(nrps, rp) + } + } + body := map[string]interface{}{ + "routingProtocol": nrps, + } + if err := bc.Update(kind, name, partition, subfolder, body); err != nil { + return err + } + } + + return bc.ModifyDbValue("tmrouted.tmos.routing", "enable") +}