Skip to content

Commit 2b7101a

Browse files
authored
Merge pull request #167 from projectsyn/fix/bgp-resourcegen
Correctly handle nulled BGP resource configuration entries
2 parents 1aa8d50 + ebcaded commit 2b7101a

File tree

2 files changed

+66
-58
lines changed

2 files changed

+66
-58
lines changed

component/bgp-control-plane.jsonnet

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -48,73 +48,76 @@ local CiliumBGPNodeConfigOverride(name) =
4848
};
4949

5050
local validate_auth_secret(name, config) =
51-
local data = std.get(config, 'data', {});
52-
local sdata = std.get(config, 'stringData', {});
53-
assert
54-
std.objectHas(data, 'password') || std.objectHas(sdata, 'password')
55-
: "Cilium BGP auth secret `%s` doesn't have key `password`" % name;
56-
config {
57-
metadata+: {
58-
namespace: params.cilium_helm_values.bgpControlPlane.secretsNamespace.name,
59-
},
60-
};
51+
if config != null then
52+
local data = std.get(config, 'data', {});
53+
local sdata = std.get(config, 'stringData', {});
54+
assert
55+
std.objectHas(data, 'password') || std.objectHas(sdata, 'password')
56+
: "Cilium BGP auth secret `%s` doesn't have key `password`" % name;
57+
config {
58+
metadata+: {
59+
namespace: params.cilium_helm_values.bgpControlPlane.secretsNamespace.name,
60+
},
61+
};
6162

6263
local authsecrets = com.generateResources(
6364
std.mapWithKey(validate_auth_secret, params.bgp.auth_secrets),
6465
kube.Secret
6566
);
6667

6768
local render_peer_config(name, config) =
68-
local auth_secret_names = [ o.metadata.name for o in authsecrets ];
69-
local validate_peer_config(pconfig) =
70-
local secretname = std.get(pconfig.spec, 'authSecretRef');
71-
assert
72-
secretname == null || std.member(auth_secret_names, secretname)
73-
: "CiliumBGPPeerConfig `%s` references auth secret `%s` which doesn't exist"
74-
% [ name, secretname ];
75-
pconfig;
76-
validate_peer_config({
77-
metadata+: std.get(config, 'metadata', {}),
78-
spec: {
79-
families: std.objectValues(std.get(config, 'families', {})),
80-
} + com.makeMergeable(std.get(config, 'spec', {})),
81-
});
69+
if config != null then
70+
local auth_secret_names = [ o.metadata.name for o in authsecrets ];
71+
local validate_peer_config(pconfig) =
72+
local secretname = std.get(pconfig.spec, 'authSecretRef');
73+
assert
74+
secretname == null || std.member(auth_secret_names, secretname)
75+
: "CiliumBGPPeerConfig `%s` references auth secret `%s` which doesn't exist"
76+
% [ name, secretname ];
77+
pconfig;
78+
validate_peer_config({
79+
metadata+: std.get(config, 'metadata', {}),
80+
spec: {
81+
families: std.objectValues(std.get(config, 'families', {})),
82+
} + com.makeMergeable(std.get(config, 'spec', {})),
83+
});
8284

8385
local bgppeerconfigs = com.generateResources(
8486
std.mapWithKey(render_peer_config, params.bgp.peer_configs),
8587
CiliumBGPPeerConfig
8688
);
8789

8890
local render_cluster_config(name, config) =
89-
local peerConfigNames = [ o.metadata.name for o in bgppeerconfigs ];
90-
local validate_peer_config(iname, pconfig) =
91-
local pcfgname = std.get(pconfig, 'peerConfigRef', { name: '' }).name;
92-
assert
93-
std.member(peerConfigNames, pcfgname)
94-
: 'Peer `%s` in BGP instance `%s` in CiliumBGPClusterConfig `%s` ' %
95-
[ pconfig.name, iname, name ]
96-
+ "references CiliumBGPPeerConfig `%s` which doesn't exist" %
97-
[ pcfgname ];
98-
pconfig;
99-
local render_instance(name, iconfig) =
100-
local cfg = iconfig {
101-
name: name,
102-
peers: [
103-
validate_peer_config(name, iconfig.peers[pname] { name: pname })
104-
for pname in std.objectFields(iconfig.peers)
105-
],
91+
if config != null then
92+
local peerConfigNames = [ o.metadata.name for o in bgppeerconfigs ];
93+
local validate_peer_config(iname, pconfig) =
94+
local pcfgname = std.get(pconfig, 'peerConfigRef', { name: '' }).name;
95+
assert
96+
std.member(peerConfigNames, pcfgname)
97+
: 'Peer `%s` in BGP instance `%s` in CiliumBGPClusterConfig `%s` ' %
98+
[ pconfig.name, iname, name ]
99+
+ "references CiliumBGPPeerConfig `%s` which doesn't exist" %
100+
[ pcfgname ];
101+
pconfig;
102+
local render_instance(name, iconfig) =
103+
local cfg = iconfig {
104+
name: name,
105+
peers: [
106+
validate_peer_config(name, iconfig.peers[pname] { name: pname })
107+
for pname in std.objectFields(iconfig.peers)
108+
],
109+
};
110+
cfg;
111+
{
112+
metadata+: std.get(config, 'metadata', {}),
113+
spec: {
114+
nodeSelector: std.get(config, 'nodeSelector', {}),
115+
bgpInstances: std.objectValues(std.mapWithKey(
116+
render_instance,
117+
config.bgpInstances
118+
)),
119+
} + com.makeMergeable(std.get(config, 'spec', {})),
106120
};
107-
cfg;
108-
{
109-
metadata+: std.get(config, 'metadata', {}),
110-
spec: {
111-
nodeSelector: std.get(config, 'nodeSelector', {}),
112-
bgpInstances: std.objectValues(std.mapWithKey(
113-
render_instance,
114-
config.bgpInstances
115-
)),
116-
} + com.makeMergeable(std.get(config, 'spec', {})),
117-
};
118121

119122
local bgpclusterconfigs = com.generateResources(
120123
std.mapWithKey(render_cluster_config, params.bgp.cluster_configs),
@@ -123,12 +126,13 @@ local bgpclusterconfigs = com.generateResources(
123126

124127

125128
local render_advertisement(name, config) =
126-
{
127-
metadata+: std.get(config, 'metadata', {}),
128-
spec: {
129-
advertisements: std.objectValues(std.get(config, 'advertisements', {})),
130-
},
131-
};
129+
if config != null then
130+
{
131+
metadata+: std.get(config, 'metadata', {}),
132+
spec: {
133+
advertisements: std.objectValues(std.get(config, 'advertisements', {})),
134+
},
135+
};
132136

133137
local bgpadvertisements = com.generateResources(
134138
std.mapWithKey(render_advertisement, params.bgp.advertisements),

tests/bgp-control-plane.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ parameters:
3030
peerASN: 64512
3131
peerConfigRef:
3232
name: lb-services
33+
test: null
3334
peer_configs:
3435
lb-services:
3536
spec:
@@ -43,6 +44,7 @@ parameters:
4344
advertisements:
4445
matchLabels:
4546
cilium.syn.tools/advertise: bgp
47+
test: null
4648
advertisements:
4749
lb-services:
4850
metadata:
@@ -57,13 +59,15 @@ parameters:
5759
selector:
5860
matchLabels:
5961
syn.tools/load-balancer-class: cilium
62+
test: null
6063
auth_secrets:
6164
test:
6265
data:
6366
password: foobar
6467
test2:
6568
stringData:
6669
password: foobar
70+
foo: null
6771
loadbalancer_ip_pools:
6872
lb-services:
6973
blocks:

0 commit comments

Comments
 (0)