Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] add support for custom BGP environment overrides via environment variables #277

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions cloud/linode/cilium_loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"os"
"slices"
"strings"

Expand All @@ -28,8 +29,8 @@ const (
ciliumLBClass = "io.cilium/bgp-control-plane"
ipHolderLabelPrefix = "linode-ccm-ip-holder"
ciliumBGPPeeringPolicyName = "linode-ccm-bgp-peering"

commonControlPlaneLabel = "node-role.kubernetes.io/control-plane"
defaultBGPPeerPrefix = "2600:3c0f"
commonControlPlaneLabel = "node-role.kubernetes.io/control-plane"
)

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

// NOTE: Cilium CRDs must be installed for this to work
func (l *loadbalancers) ensureCiliumBGPPeeringPolicy(ctx context.Context) error {
if raw, ok := os.LookupEnv("BGPCustomIDMap"); ok {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add these two environment variables in readme here? https://github.com/linode/linode-cloud-controller-manager?tab=readme-ov-file#additional-environment-variables

Also, should we capitalize the environment variable to match with existing style?

klog.Info("BGPCustomIDMap env variable specified, using it instead of the default region map")
if err := json.Unmarshal([]byte(raw), &regionIDMap); err != nil {
eljohnson92 marked this conversation as resolved.
Show resolved Hide resolved
return err
}
}
regionID, ok := regionIDMap[l.zone]
if !ok {
return fmt.Errorf("unsupported region for BGP: %s", l.zone)
Expand Down Expand Up @@ -543,10 +550,15 @@ func (l *loadbalancers) ensureCiliumBGPPeeringPolicy(ctx context.Context) error
}},
},
}
bgpPeerPrefix := defaultBGPPeerPrefix
if raw, ok := os.LookupEnv("BGPPeerPrefix"); ok {
klog.Info("BGPPeerPrefix env variable specified, using it instead of the default bgpPeer prefix")
bgpPeerPrefix = raw
eljohnson92 marked this conversation as resolved.
Show resolved Hide resolved
}
// As in https://github.com/linode/lelastic, there are 4 peers per DC
for i := 1; i <= 4; i++ {
neighbor := v2alpha1.CiliumBGPNeighbor{
PeerAddress: fmt.Sprintf("2600:3c0f:%d:34::%d/64", regionID, i),
PeerAddress: fmt.Sprintf("%s:%d:34::%d/64", bgpPeerPrefix, regionID, i),
PeerASN: 65000,
EBGPMultihopTTL: ptr.To(int32(10)),
ConnectRetryTimeSeconds: ptr.To(int32(5)),
Expand Down
Loading