Skip to content

Commit

Permalink
fix: Default BGP peering for worker nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Mendoza committed Aug 12, 2024
1 parent 7bc2eea commit b00cd63
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
22 changes: 18 additions & 4 deletions cloud/linode/cilium_loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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"
)

// This mapping is unfortunately necessary since there is no way to get the
Expand Down Expand Up @@ -158,6 +160,9 @@ func (l *loadbalancers) handleIPSharing(ctx context.Context, node *v1.Node) erro
// not a selected Node
return nil
}
} else if _, ok := node.Labels[commonControlPlaneLabel]; ok {
// If there is no node selector specified, default to sharing across worker nodes only
return nil
}
// check if node has been updated with IPs to share
if _, foundIpSharingUpdatedLabel := node.Labels[annotations.AnnLinodeNodeIPSharingUpdated]; foundIpSharingUpdatedLabel {
Expand Down Expand Up @@ -235,8 +240,10 @@ func (l *loadbalancers) createSharedIP(ctx context.Context, nodes []*v1.Node) (s
// share the IPs with nodes participating in Cilium BGP peering
if Options.BGPNodeSelector == "" {
for _, node := range nodes {
if err = l.shareIPs(ctx, addrs, node); err != nil {
return "", err
if _, ok := node.Labels[commonControlPlaneLabel]; !ok {
if err = l.shareIPs(ctx, addrs, node); err != nil {
return "", err
}
}
}
} else {
Expand Down Expand Up @@ -442,9 +449,16 @@ func (l *loadbalancers) ensureCiliumBGPPeeringPolicy(ctx context.Context) error

// otherwise create it
var nodeSelector slimv1.LabelSelector
// If no BGPNodeSelector is specified, select all nodes by default.
// If no BGPNodeSelector is specified, select all worker nodes.
if Options.BGPNodeSelector == "" {
nodeSelector = slimv1.LabelSelector{}
nodeSelector = slimv1.LabelSelector{
MatchExpressions: []slimv1.LabelSelectorRequirement{
{
Key: commonControlPlaneLabel,
Operator: slimv1.LabelSelectorOpDoesNotExist,
},
},
}
} else {
kv := strings.Split(Options.BGPNodeSelector, "=")
if len(kv) != 2 {
Expand Down
11 changes: 11 additions & 0 deletions cloud/linode/cilium_loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ var (
ProviderID: fmt.Sprintf("%s%d", providerIDPrefix, 33333),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "node-control",
Labels: map[string]string{
commonControlPlaneLabel: "",
},
},
Spec: v1.NodeSpec{
ProviderID: fmt.Sprintf("%s%d", providerIDPrefix, 44444),
},
},
}
publicIPv4 = net.ParseIP("45.76.101.25")
ipHolderInstance = linodego.Instance{
Expand Down

0 comments on commit b00cd63

Please sign in to comment.