Skip to content

Commit 704c65e

Browse files
rastislavsYutaroHayakawa
authored andcommitted
bgpv2: Update component tests to work with LB cell
After migration of svc reconciler to svc LB tables, update component tests infra to contain necessary LB cells, and update the tests to work properly: provide both v4 and v6 endpointslices when local endpoints are expected, use distinct ports among services in the service VIP sharing test. Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
1 parent aed8f11 commit 704c65e

3 files changed

Lines changed: 76 additions & 26 deletions

File tree

pkg/bgpv1/test/script_test.go

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ import (
3030
"github.com/cilium/cilium/pkg/datapath/linux/safenetlink"
3131
"github.com/cilium/cilium/pkg/datapath/tables"
3232
envoyCfg "github.com/cilium/cilium/pkg/envoy/config"
33+
"github.com/cilium/cilium/pkg/kpr"
34+
"github.com/cilium/cilium/pkg/loadbalancer"
35+
lbcell "github.com/cilium/cilium/pkg/loadbalancer/cell"
36+
"github.com/cilium/cilium/pkg/maglev"
37+
"github.com/cilium/cilium/pkg/node"
38+
"github.com/cilium/cilium/pkg/source"
3339

3440
ciliumhive "github.com/cilium/cilium/pkg/hive"
3541
ipamOption "github.com/cilium/cilium/pkg/ipam/option"
@@ -58,6 +64,8 @@ func TestPrivilegedScript(t *testing.T) {
5864
testutils.PrivilegedTest(t)
5965
slog.SetLogLoggerLevel(slog.LevelDebug) // used by test GoBGP instances
6066

67+
types.SetName(testNodeName)
68+
6169
// setup test link
6270
dummy := &netlink.Dummy{
6371
LinkAttrs: netlink.LinkAttrs{Name: testLinkName},
@@ -89,35 +97,55 @@ func TestPrivilegedScript(t *testing.T) {
8997
}
9098

9199
h := ciliumhive.New(
92-
k8sClient.FakeClientCell(),
93-
daemonk8s.ResourcesCell,
94-
cell.Config(envoyCfg.SecretSyncConfig{}),
95-
96100
metrics.Cell,
101+
102+
// BGP cell
97103
bgpv1.Cell,
98104

99-
// Provide route and device tables
105+
// Provide statedb tables
100106
cell.Provide(
101107
tables.NewRouteTable,
102108
tables.NewDeviceTable,
103-
statedb.RWTable[*tables.Route].ToTable, // Table[*Route]
104-
statedb.RWTable[*tables.Device].ToTable, // Table[*Device]
109+
tables.NewNodeAddressTable,
110+
statedb.RWTable[*tables.Route].ToTable, // Table[*Route]
111+
statedb.RWTable[*tables.Device].ToTable, // Table[*Device]
112+
statedb.RWTable[tables.NodeAddress].ToTable, // Table[NodeAddress]
105113
),
106114

107-
cell.Provide(func() *option.DaemonConfig {
108-
// BGP Manager uses the global variable option.Config so we need to set it there as well
109-
option.Config = &option.DaemonConfig{
110-
EnableBGPControlPlane: true,
111-
BGPSecretsNamespace: testSecretsNamespace,
112-
BGPRouterIDAllocationMode: option.BGPRouterIDAllocationModeDefault,
113-
IPAM: *ipam,
114-
}
115-
return option.Config
116-
}),
115+
// Dependencies
116+
k8sClient.FakeClientCell(),
117+
daemonk8s.ResourcesCell,
118+
daemonk8s.TablesCell,
119+
node.LocalNodeStoreTestCell,
120+
cell.Config(envoyCfg.SecretSyncConfig{}),
117121

118-
cell.Invoke(func() {
119-
types.SetName(testNodeName)
120-
}),
122+
// LB cell to populate LB tables from k8s services / endpoints
123+
lbcell.Cell,
124+
maglev.Cell,
125+
cell.Provide(source.NewSources),
126+
cell.Config(loadbalancer.TestConfig{}),
127+
cell.Provide(
128+
func(cfg loadbalancer.TestConfig) *loadbalancer.TestConfig { return &cfg }, // newLBMaps expects *TestConfig
129+
),
130+
131+
cell.Provide(
132+
func() *option.DaemonConfig {
133+
option.Config = &option.DaemonConfig{
134+
EnableBGPControlPlane: true,
135+
BGPSecretsNamespace: testSecretsNamespace,
136+
BGPRouterIDAllocationMode: option.BGPRouterIDAllocationModeDefault,
137+
IPAM: *ipam,
138+
EnableIPv4: true,
139+
EnableIPv6: true,
140+
}
141+
return option.Config
142+
},
143+
func() kpr.KPRConfig {
144+
return kpr.KPRConfig{
145+
KubeProxyReplacement: true,
146+
}
147+
},
148+
),
121149
cell.Invoke(func(m agent.BGPRouterManager) {
122150
bgpMgr = m
123151
m.(*manager.BGPRouterManager).DestroyRouterOnStop(true) // fully destroy GoBGP server on Stop()

pkg/bgpv1/test/testdata/svc-aggregation.txtar

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ gobgp/add-server test 65010 10.99.4.211 1790
1212
# Configure peers on GoBGP
1313
gobgp/add-peer 10.99.4.212 65001
1414

15-
# Add k8s services
16-
k8s/add service-1.yaml service-2.yaml service-3.yaml endpoints.yaml
15+
# Add k8s services and endpoints
16+
k8s/add service-1.yaml service-2.yaml service-3.yaml endpoints-ipv4.yaml endpoints-ipv6.yaml
1717

1818
# Configure BGP on Cilium
1919
k8s/add cilium-node.yaml bgp-node-config.yaml bgp-peer-config.yaml bgp-advertisement-1.yaml
@@ -274,13 +274,13 @@ status:
274274
- ip: 172.16.1.3
275275
- ip: fd00:cc:dd::3
276276

277-
-- endpoints.yaml --
277+
-- endpoints-ipv4.yaml --
278278
apiVersion: discovery.k8s.io/v1
279279
kind: EndpointSlice
280280
metadata:
281281
labels:
282282
kubernetes.io/service-name: svc3
283-
name: svc3-eps1
283+
name: svc3-eps-ipv4
284284
uid: d1f517f6-ab88-4c76-9bd0-4906a17cdd75
285285
addressType: IPv4
286286
endpoints:
@@ -296,6 +296,28 @@ ports:
296296
port: 80
297297
protocol: TCP
298298

299+
-- endpoints-ipv6.yaml --
300+
apiVersion: discovery.k8s.io/v1
301+
kind: EndpointSlice
302+
metadata:
303+
labels:
304+
kubernetes.io/service-name: svc3
305+
name: svc3-eps-ipv6
306+
uid: d1f517f6-ab88-4c76-9bd0-4906a17cdd76
307+
addressType: IPv6
308+
endpoints:
309+
- addresses:
310+
- 2001::1:20
311+
conditions:
312+
ready: true
313+
serving: true
314+
terminating: false
315+
nodeName: test-node
316+
ports:
317+
- name: http
318+
port: 80
319+
protocol: TCP
320+
299321
-- gobgp-routes-aggregated-ipv4-1.expected --
300322
Prefix NextHop Attrs
301323
10.10.10.0/24 10.99.4.212 [{Origin: i} {AsPath: 65001} {Nexthop: 10.99.4.212}]

pkg/bgpv1/test/testdata/svc-sharing.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ spec:
161161
ipFamilyPolicy: SingleStack
162162
ports:
163163
- name: http
164-
port: 80
164+
port: 8080
165165
protocol: TCP
166-
targetPort: 80
166+
targetPort: 8080
167167
selector:
168168
name: echo
169169
sessionAffinity: None

0 commit comments

Comments
 (0)