Skip to content

Commit 9cec7dc

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

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cloud/linode/cilium_loadbalancers.go

Lines changed: 15 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,12 @@ 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+
klog.Info("BGPCustomIDMap env variable specified, using it instead of the default region map")
487+
if err := json.Unmarshal([]byte(raw), &regionIDMap); err != nil {
488+
return err
489+
}
490+
}
484491
regionID, ok := regionIDMap[l.zone]
485492
if !ok {
486493
return fmt.Errorf("unsupported region for BGP: %s", l.zone)
@@ -543,10 +550,15 @@ func (l *loadbalancers) ensureCiliumBGPPeeringPolicy(ctx context.Context) error
543550
}},
544551
},
545552
}
553+
bgpPeerPrefix := defaultBGPPeerPrefix
554+
if raw, ok := os.LookupEnv("BGPPeerPrefix"); ok {
555+
klog.Info("BGPPeerPrefix env variable specified, using it instead of the default bgpPeer prefix")
556+
bgpPeerPrefix = raw
557+
}
546558
// As in https://github.com/linode/lelastic, there are 4 peers per DC
547559
for i := 1; i <= 4; i++ {
548560
neighbor := v2alpha1.CiliumBGPNeighbor{
549-
PeerAddress: fmt.Sprintf("2600:3c0f:%d:34::%d/64", regionID, i),
561+
PeerAddress: fmt.Sprintf("%s:%d:34::%d/64", bgpPeerPrefix, regionID, i),
550562
PeerASN: 65000,
551563
EBGPMultihopTTL: ptr.To(int32(10)),
552564
ConnectRetryTimeSeconds: ptr.To(int32(5)),

0 commit comments

Comments
 (0)