Skip to content

Commit

Permalink
Merge pull request #134 from projectsyn/change/lb-ip-pools
Browse files Browse the repository at this point in the history
Allow creating CiliumLoadBalancerIPPool with L2 Announcements
  • Loading branch information
DebakelOrakel authored Aug 15, 2024
2 parents a80216a + ccc1b62 commit 9005d9f
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 38 deletions.
1 change: 1 addition & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ parameters:
l2_announcements:
enabled: false
policies: {}
loadbalancer_ip_pools: {}

bgp:
enabled: false
Expand Down
35 changes: 1 addition & 34 deletions component/bgp-control-plane.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@ local util = import 'util.libsonnet';
local inv = kap.inventory();
local params = inv.parameters.cilium;

local version = util.parse_version(
if params.install_method == 'helm' then
local chart = if params.release == 'opensource'
then
'cilium'
else
'cilium-enterprise';
params.charts[chart].version
else
params.olm.full_version
);

local CiliumLoadBalancerIPPool(name) =
kube._Object('cilium.io/v2alpha1', 'CiliumLoadBalancerIPPool', name) {
metadata+: {
annotations+: {
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
},
},
};

local CiliumBGPPeeringPolicy(name) =
kube._Object('cilium.io/v2alpha1', 'CiliumBGPPeeringPolicy', name) {
metadata+: {
Expand Down Expand Up @@ -61,19 +40,7 @@ local peerings = com.generateResources(
CiliumBGPPeeringPolicy
);

local render_ip_pool(name, pool) =
{
spec: {
[if version.minor <= 14 then 'cidrs' else 'blocks']:
std.objectValues(pool.blocks),
serviceSelector: std.get(pool, 'serviceSelector', {}),
} + com.makeMergeable(std.get(pool, 'spec', {})),
};

local lb_ip_pools = com.generateResources(
std.mapWithKey(render_ip_pool, params.bgp.loadbalancer_ip_pools),
CiliumLoadBalancerIPPool,
);
local lb_ip_pools = util.ipPool(params.bgp.loadbalancer_ip_pools);

{
[if params.bgp.enabled && std.length(peerings) > 0 then
Expand Down
6 changes: 6 additions & 0 deletions component/l2-announcement-policies.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local com = import 'lib/commodore.libjsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';

local util = import 'util.libsonnet';

local inv = kap.inventory();
local params = inv.parameters.cilium;

Expand All @@ -19,7 +21,11 @@ local policies = com.generateResources(
CiliumL2AnnouncementPolicy
);

local lb_ip_pools = util.ipPool(params.l2_announcements.loadbalancer_ip_pools);

{
[if params.l2_announcements.enabled && std.length(params.l2_announcements.policies) > 0 then
'50_l2_announcement_policies']: policies,
[if params.l2_announcements.enabled && std.length(lb_ip_pools) > 0 then
'50_loadbalancer_ip_pools']: lb_ip_pools,
}
4 changes: 1 addition & 3 deletions component/olm.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,14 @@ local kubeSystemSecretRO = [
},
];

local olm_version = util.parse_version(params.olm.full_version);

std.foldl(
function(files, file) files { [std.strReplace(file.filename, '.yaml', '')]: file.contents },
std.filter(
function(obj) obj != null,
std.map(function(obj) patchManifests(obj, olmFiles.has_csv), olmFiles.files),
),
{
[if olm_version.minor <= 14 then '98_fixup_bgp_controlpane_rbac']: kubeSystemSecretRO,
[if util.version.minor <= 14 then '98_fixup_bgp_controlpane_rbac']: kubeSystemSecretRO,
'99_cleanup': (import 'cleanup.libsonnet'),
}
)
45 changes: 44 additions & 1 deletion component/util.libsonnet
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
local com = import 'lib/commodore.libjsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';

local inv = kap.inventory();
local params = inv.parameters.cilium;
local isOpenshift = std.member([ 'openshift4', 'oke' ], inv.parameters.facts.distribution);

// Parse cilium version

local parse_version(ver) =
local verparts = std.split(ver, '.');
local parseOrError(val, typ) =
Expand All @@ -20,7 +25,45 @@ local parse_version(ver) =
minor: parseOrError(verparts[1], 'minor'),
};

local version = parse_version(
if params.install_method == 'helm' then
local chart = if params.release == 'opensource'
then
'cilium'
else
'cilium-enterprise';
params.charts[chart].version
else
params.olm.full_version
);

// CiliumLoadBalancerIPPool

local CiliumLoadBalancerIPPool(name) =
kube._Object('cilium.io/v2alpha1', 'CiliumLoadBalancerIPPool', name) {
metadata+: {
annotations+: {
'argocd.argoproj.io/sync-options': 'SkipDryRunOnMissingResource=true',
},
},
};

local render_ip_pool(name, pool) =
{
spec: {
[if version.minor <= 14 then 'cidrs' else 'blocks']:
std.objectValues(pool.blocks),
serviceSelector: std.get(pool, 'serviceSelector', {}),
} + com.makeMergeable(std.get(pool, 'spec', {})),
};

local render_ip_pools(pools) = com.generateResources(
std.mapWithKey(render_ip_pool, pools),
CiliumLoadBalancerIPPool,
);

{
isOpenshift: isOpenshift,
parse_version: parse_version,
version: version,
ipPool: render_ip_pools,
}
9 changes: 9 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,15 @@ l2_announcements:
loadBalancerIPs: true
----

=== `l2_announcements.loadbalancer_ip_pools`

[horizontal]
type:: object
default:: `{}`

See xref:references/parameters.adoc#_bgp_loadbalancer_ip_pools[BGP LB IP Pool configuration].


== `bgp`

This section allows users to configure the https://docs.cilium.io/en/stable/network/bgp-control-plane/[Cilium BGP control plane].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: cilium.io/v2alpha1
kind: CiliumLoadBalancerIPPool
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
labels:
name: lb-services
name: lb-services
spec:
blocks:
- cidr: 198.51.100.32/27
- start: 203.0.113.10
stop: 203.0.113.20
serviceSelector:
matchLabels:
syn.tools/load-balancer-class: cilium
11 changes: 11 additions & 0 deletions tests/l2-announcement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ parameters:
- ^eth[0-9]+
externalIPs: true
loadBalancerIPs: true
loadbalancer_ip_pools:
lb-services:
blocks:
tn2:
cidr: 198.51.100.32/27
tn3:
start: 203.0.113.10
stop: 203.0.113.20
serviceSelector:
matchLabels:
syn.tools/load-balancer-class: cilium

0 comments on commit 9005d9f

Please sign in to comment.