Skip to content

Commit 2751cbb

Browse files
committed
add support for custom BGP environment overrides via environment variables
1 parent a82417c commit 2751cbb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cloud/linode/cilium_loadbalancers.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8+
"os"
89
"slices"
910
"strings"
1011

@@ -28,8 +29,8 @@ const (
2829
ciliumLBClass = "io.cilium/bgp-control-plane"
2930
ipHolderLabelPrefix = "linode-ccm-ip-holder"
3031
ciliumBGPPeeringPolicyName = "linode-ccm-bgp-peering"
31-
32-
commonControlPlaneLabel = "node-role.kubernetes.io/control-plane"
32+
defaultBGPPeerPrefix = "2600:3c0f"
33+
commonControlPlaneLabel = "node-role.kubernetes.io/control-plane"
3334
)
3435

3536
// This mapping is unfortunately necessary since there is no way to get the
@@ -481,6 +482,11 @@ func (l *loadbalancers) getCiliumLBIPPool(ctx context.Context, service *v1.Servi
481482

482483
// NOTE: Cilium CRDs must be installed for this to work
483484
func (l *loadbalancers) ensureCiliumBGPPeeringPolicy(ctx context.Context) error {
485+
if raw, ok := os.LookupEnv("BGPCustomIDMap"); ok {
486+
if err := json.Unmarshal([]byte(raw), &regionIDMap); err != nil {
487+
return err
488+
}
489+
}
484490
regionID, ok := regionIDMap[l.zone]
485491
if !ok {
486492
return fmt.Errorf("unsupported region for BGP: %s", l.zone)
@@ -543,10 +549,14 @@ func (l *loadbalancers) ensureCiliumBGPPeeringPolicy(ctx context.Context) error
543549
}},
544550
},
545551
}
552+
bgpPeerPrefix := defaultBGPPeerPrefix
553+
if raw, ok := os.LookupEnv("BGPPeerPrefix"); ok {
554+
bgpPeerPrefix = raw
555+
}
546556
// As in https://github.com/linode/lelastic, there are 4 peers per DC
547557
for i := 1; i <= 4; i++ {
548558
neighbor := v2alpha1.CiliumBGPNeighbor{
549-
PeerAddress: fmt.Sprintf("2600:3c0f:%d:34::%d/64", regionID, i),
559+
PeerAddress: fmt.Sprintf("%s:%d:34::%d/64", bgpPeerPrefix, regionID, i),
550560
PeerASN: 65000,
551561
EBGPMultihopTTL: ptr.To(int32(10)),
552562
ConnectRetryTimeSeconds: ptr.To(int32(5)),

0 commit comments

Comments
 (0)