Skip to content

Commit 98360ca

Browse files
martonraYutaroHayakawa
authored andcommitted
bgp: register route-policy statedb when BGP enabled
Only register route-policy statedb table and reconciler when BGP control plane enabled. Signed-off-by: Marton Rasek <mrasek@isovalent.com>
1 parent b38239d commit 98360ca

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

pkg/bgp/cell.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,14 @@ var Cell = cell.Module(
8282
cell.Provide(
8383
tables.NewBGPReconcileErrorTable,
8484
tables.NewDesiredRoutePoliciesTable,
85-
statedb.RWTable[*tables.DesiredRoutePolicy].ToTable,
85+
func(t statedb.RWTable[*tables.DesiredRoutePolicy], dc *option.DaemonConfig) statedb.Table[*tables.DesiredRoutePolicy] {
86+
// Do not create this resource if BGP Control Plane is disabled.
87+
if !dc.BGPControlPlaneEnabled() {
88+
return nil
89+
}
90+
91+
return statedb.RWTable[*tables.DesiredRoutePolicy].ToTable(t)
92+
},
8693
),
8794

8895
// provide privates for reconciler v2

pkg/bgp/manager/reconciler/route_policy.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/cilium/cilium/pkg/bgp/manager/instance"
1818
"github.com/cilium/cilium/pkg/bgp/manager/tables"
1919
"github.com/cilium/cilium/pkg/bgp/types"
20+
"github.com/cilium/cilium/pkg/option"
2021
)
2122

2223
type RoutePolicyReconcilerOut struct {
@@ -31,6 +32,7 @@ type RoutePolicyReconcilerIn struct {
3132
Logger *slog.Logger
3233
DB *statedb.DB
3334
DesiredRoutePolicyTable statedb.Table[*tables.DesiredRoutePolicy]
35+
DaemonConfig *option.DaemonConfig
3436
}
3537

3638
type RoutePolicyReconciler struct {
@@ -48,6 +50,11 @@ type RoutePolicyReconcilerMetadata struct {
4850
}
4951

5052
func NewRoutePolicyReconciler(params RoutePolicyReconcilerIn) RoutePolicyReconcilerOut {
53+
// Do not create this resource if BGP Control Plane is disabled.
54+
if !params.DaemonConfig.BGPControlPlaneEnabled() {
55+
return RoutePolicyReconcilerOut{}
56+
}
57+
5158
return RoutePolicyReconcilerOut{
5259
Reconciler: &RoutePolicyReconciler{
5360
logger: params.Logger.With(types.ReconcilerLogField, RoutePolicyReconcilerName),

pkg/bgp/manager/tables/route_policies.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/cilium/cilium/pkg/bgp/types"
1313
"github.com/cilium/cilium/pkg/k8s/resource"
14+
"github.com/cilium/cilium/pkg/option"
1415
)
1516

1617
const (
@@ -229,7 +230,12 @@ func DesiredRoutePoliciesByInstanceOwnerResource(instance string, owner string,
229230
})
230231
}
231232

232-
func NewDesiredRoutePoliciesTable(db *statedb.DB) (statedb.RWTable[*DesiredRoutePolicy], error) {
233+
func NewDesiredRoutePoliciesTable(db *statedb.DB, dc *option.DaemonConfig) (statedb.RWTable[*DesiredRoutePolicy], error) {
234+
// Do not create this resource if BGP Control Plane is disabled.
235+
if !dc.BGPControlPlaneEnabled() {
236+
return nil, nil
237+
}
238+
233239
return statedb.NewTable(
234240
db,
235241
"bgp-desired-route-policies",

0 commit comments

Comments
 (0)