Skip to content

Commit 1b2351c

Browse files
eljohnson92Rahul Sharma
andauthored
[feat] add support for custom BGP environment overrides via environment variables (#277)
* add support for custom BGP environment overrides via environment variables * address review comments * add test for bgp custom id map --------- Co-authored-by: Rahul Sharma <rahsharm@akamai.com>
1 parent ab98d88 commit 1b2351c

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,14 @@ sessionAffinityConfig:
294294
## Additional environment variables
295295
To tweak CCM based on needs, one can overwrite the default values set for caches and requests by setting appropriate environment variables when applying the manifest or helm chart.
296296

297-
| Environment Variable | Default | Description |
298-
|-----------------------------------|---------|-------------------------------------------------------------|
299-
| `LINODE_INSTANCE_CACHE_TTL` | `15` | Default timeout of instance cache in seconds |
300-
| `LINODE_ROUTES_CACHE_TTL_SECONDS` | `60` | Default timeout of route cache in seconds |
301-
| `LINODE_REQUEST_TIMEOUT_SECONDS` | `120` | Default timeout in seconds for http requests to linode API |
302-
| `LINODE_EXTERNAL_SUBNET` | | Mark private network as external. Example - `172.24.0.0/16` |
297+
| Environment Variable | Default | Description |
298+
|-----------------------------------|-------------|-------------------------------------------------------------|
299+
| `LINODE_INSTANCE_CACHE_TTL` | `15` | Default timeout of instance cache in seconds |
300+
| `LINODE_ROUTES_CACHE_TTL_SECONDS` | `60` | Default timeout of route cache in seconds |
301+
| `LINODE_REQUEST_TIMEOUT_SECONDS` | `120` | Default timeout in seconds for http requests to linode API |
302+
| `LINODE_EXTERNAL_SUBNET` | | Mark private network as external. Example - `172.24.0.0/16` |
303+
| `BGP_CUSTOM_ID_MAP` | | Use your own map instead of default region map for BGP |
304+
| `BGP_PEER_PREFIX` | `2600:3c0f` | Use your own BGP peer prefix instead of default one |
303305

304306
## Generating a Manifest for Deployment
305307
Use the script located at `./deploy/generate-manifest.sh` to generate a self-contained deployment manifest for the Linode CCM. Two arguments are required.

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("BGP_CUSTOM_ID_MAP"); ok {
486+
klog.Info("BGP_CUSTOM_ID_MAP 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("BGP_PEER_PREFIX"); ok {
555+
klog.Info("BGP_PEER_PREFIX 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)),

cloud/linode/cilium_loadbalancers_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func createNewIpHolderInstance() linodego.Instance {
201201
func testNoBGPNodeLabel(t *testing.T, mc *mocks.MockClient) {
202202
Options.BGPNodeSelector = ""
203203
Options.IpHolderSuffix = "linodelb"
204+
t.Setenv("BGP_PEER_PREFIX", "2600:3cef")
204205
svc := createTestService()
205206
newIpHolderInstance = createNewIpHolderInstance()
206207

@@ -257,7 +258,18 @@ func testUnsupportedRegion(t *testing.T, mc *mocks.MockClient) {
257258

258259
lbStatus, err := lb.EnsureLoadBalancer(context.TODO(), "linodelb", svc, nodes)
259260
if err == nil {
260-
t.Fatal("expected nil error")
261+
t.Fatal("expected not nil error")
262+
}
263+
if lbStatus != nil {
264+
t.Fatalf("expected a nil lbStatus, got %v", lbStatus)
265+
}
266+
267+
// Use BGP custom id map
268+
t.Setenv("BGP_CUSTOM_ID_MAP", "{'us-foobar': 2}")
269+
lb = &loadbalancers{mc, zone, kubeClient, ciliumClient, ciliumLBType}
270+
lbStatus, err = lb.EnsureLoadBalancer(context.TODO(), "linodelb", svc, nodes)
271+
if err == nil {
272+
t.Fatal("expected not nil error")
261273
}
262274
if lbStatus != nil {
263275
t.Fatalf("expected a nil lbStatus, got %v", lbStatus)

0 commit comments

Comments
 (0)