Skip to content

Commit 3112a76

Browse files
authored
Merge pull request #155 from inhogog2/main
Added BGP Policy CRD
2 parents c3cff4f + f841a44 commit 3112a76

File tree

97 files changed

+6897
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+6897
-3
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ wget https://github.com/loxilb-io/kube-loxilb/raw/main/manifest/ext-cluster/kube
4848
#- --monitor
4949
#- --setBGP=65100
5050
#- --extBGPPeers=50.50.50.1:65101,51.51.51.1:65102
51+
#- --enableBGPCRDs
5152
#- --setRoles=0.0.0.0
5253
#- --setLBMode=1
5354
#- --setUniqueIP=false
@@ -67,6 +68,7 @@ The arguments have the following meaning :
6768
| setLBMode | 0, 1, 2 <br> 0 - default (only DNAT, preserves source-IP) <br> 1 - onearm (source IP is changed to load balancer’s interface IP) <br> 2 - fullNAT (sourceIP is changed to virtual IP) |
6869
| setUniqueIP | Allocate unique service-IP per LB service (default : false) |
6970
| externalSecondaryCIDRs | Secondary CIDR or IPAddress ranges to allocate addresses from in case of multi-homing support |
71+
| enableBGPCRDs | Enable BGP Policy and Peer CRDs |
7072

7173
Many of the above flags and arguments can be overriden on a per-service basis based on loxilb specific annotation as mentioned below.
7274

@@ -205,10 +207,30 @@ Thereafter, the process of service creation remains the same as explained in pre
205207
Kube-loxilb provides Custom Resource Definition (CRD). Current the following operations are supported (which would be continually updated):
206208
- Add a BGP Peer
207209
- Delete a BGP Peer
210+
- Add/Delete a BGP Policy
211+
212+
For information on BGP Policy CRD, please refer [here.](https://github.com/loxilb-io/loxilbdocs/blob/main/docs/k8s_bgp_policy_crd.md)
208213

209214
An example of CRD is stored in manifest/crds. Setting up a BGP Peer as an example is as follows:
210215

211-
1. Pre-Processing (Register kube-loxilb CRDs with K8s). Apply lbpeercrd.yaml as first step
216+
1. Pre-Processing (Register kube-loxilb CRDs with K8s).
217+
218+
First of all change the kube-loxilb.yaml arguments. It need to add `- --enableBGPCRDs` option.
219+
```
220+
args:
221+
- --loxiURL=http://12.12.12.1:11111
222+
- --externalCIDR=123.123.123.1/24
223+
#- --externalSecondaryCIDRs=124.124.124.1/24,125.125.125.1/24
224+
#- --externalCIDR6=3ffe::1/96
225+
#- --monitor
226+
#- --setBGP=65100
227+
#- --extBGPPeers=50.50.50.1:65101,51.51.51.1:65102
228+
- --enableBGPCRDs
229+
#- --setRoles=0.0.0.0
230+
#- --setLBMode=1
231+
#- --setUniqueIP=false
232+
```
233+
And Apply lbpeercrd.yaml
212234
```
213235
kubectl apply -f manifest/crds/lbpeercrd.yaml
214236
```

cmd/loxilb-agent/agent.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525

2626
"github.com/loxilb-io/kube-loxilb/pkg/agent/config"
2727
"github.com/loxilb-io/kube-loxilb/pkg/agent/manager/bgppeer"
28+
"github.com/loxilb-io/kube-loxilb/pkg/agent/manager/bgppolicyapply"
29+
"github.com/loxilb-io/kube-loxilb/pkg/agent/manager/bgppolicydefinedsets"
30+
"github.com/loxilb-io/kube-loxilb/pkg/agent/manager/bgppolicydefinition"
2831
"github.com/loxilb-io/kube-loxilb/pkg/agent/manager/gatewayapi"
2932
"github.com/loxilb-io/kube-loxilb/pkg/agent/manager/loadbalancer"
3033
"github.com/loxilb-io/kube-loxilb/pkg/api"
@@ -66,6 +69,9 @@ func run(o *Options) error {
6669
informerFactory := informers.NewSharedInformerFactory(k8sClient, informerDefaultResync)
6770
crdInformerFactory := crdinformers.NewSharedInformerFactory(crdClient, informerDefaultResync)
6871
BGPPeerInformer := crdInformerFactory.Bgppeer().V1().BGPPeerServices()
72+
BGPPolicyDefinedSetInformer := crdInformerFactory.Bgppolicydefinedsets().V1().BGPPolicyDefinedSetsServices()
73+
BGPPolicyDefinitionInformer := crdInformerFactory.Bgppolicydefinition().V1().BGPPolicyDefinitionServices()
74+
BGPPolicyApplyInformer := crdInformerFactory.Bgppolicyapply().V1().BGPPolicyApplyServices()
6975
sigsInformerFactory := sigsInformer.NewSharedInformerFactory(sigsClient, informerDefaultResync)
7076

7177
// networkReadyCh is used to notify that the Node's network is ready.
@@ -200,6 +206,30 @@ func run(o *Options) error {
200206
BGPPeerInformer,
201207
lbManager,
202208
)
209+
210+
BGPPolicyDefinedSetsManager := bgppolicydefinedsets.NewBGPPolicyDefinedSetsManager(
211+
k8sClient,
212+
crdClient,
213+
networkConfig,
214+
BGPPolicyDefinedSetInformer,
215+
lbManager,
216+
)
217+
218+
BGPPolicyDefinitionManager := bgppolicydefinition.NewBGPPolicyDefinitionManager(
219+
k8sClient,
220+
crdClient,
221+
networkConfig,
222+
BGPPolicyDefinitionInformer,
223+
lbManager,
224+
)
225+
BGPPolicyApplyManager := bgppolicyapply.NewBGPPolicyApplyManager(
226+
k8sClient,
227+
crdClient,
228+
networkConfig,
229+
BGPPolicyApplyInformer,
230+
lbManager,
231+
)
232+
203233
go func() {
204234
for {
205235
select {
@@ -226,7 +256,13 @@ func run(o *Options) error {
226256
informerFactory.Start(stopCh)
227257

228258
go lbManager.Run(stopCh, loxiLBLiveCh, loxiLBPurgeCh, loxiLBSelMasterEvent)
229-
go BgpPeerManager.Run(stopCh, loxiLBLiveCh, loxiLBPurgeCh, loxiLBSelMasterEvent)
259+
if o.config.EnableBGPCRDs {
260+
crdInformerFactory.Start(stopCh)
261+
go BgpPeerManager.Run(stopCh, loxiLBLiveCh, loxiLBPurgeCh, loxiLBSelMasterEvent)
262+
go BGPPolicyDefinedSetsManager.Run(stopCh, loxiLBLiveCh, loxiLBPurgeCh, loxiLBSelMasterEvent)
263+
go BGPPolicyDefinitionManager.Run(stopCh, loxiLBLiveCh, loxiLBPurgeCh, loxiLBSelMasterEvent)
264+
go BGPPolicyApplyManager.Run(stopCh, loxiLBLiveCh, loxiLBPurgeCh, loxiLBSelMasterEvent)
265+
}
230266

231267
// Run gateway API managers
232268
if o.config.EnableGatewayAPI {

cmd/loxilb-agent/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ type AgentConfig struct {
7575
// Specify aws secondary IP. Used when configuring HA in AWS.
7676
// The specified private IP is assigned to the loxilb instance and is associated with EIP.
7777
PrivateCIDR string `yaml:"privateCIDR,omitempty"`
78+
// enable Gateway API
79+
EnableBGPCRDs bool `yaml:"enableBGPCRDs,omitempty"`
7880
}

cmd/loxilb-agent/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func (o *Options) addFlags(fs *pflag.FlagSet) {
6262
fs.StringVar(&secondaryCIDRs6, "externalSecondaryCIDRs6", secondaryCIDRs6, "External Secondary CIDR6 Range(s)")
6363
fs.StringVar(&o.config.LoxilbLoadBalancerClass, "loxilbLoadBalancerClass", o.config.LoxilbLoadBalancerClass, "Load-Balancer Class Name")
6464
fs.BoolVar(&o.config.EnableGatewayAPI, "gatewayAPI", false, "Enable gateway API managers")
65+
fs.BoolVar(&o.config.EnableBGPCRDs, "enableBGPCRDs", false, "Enable BGP CRDs")
6566
fs.StringVar(&o.config.LoxilbGatewayClass, "loxilbGatewayClass", o.config.LoxilbGatewayClass, "GatewayClass manager Name")
6667
fs.Uint16Var(&o.config.SetBGP, "setBGP", o.config.SetBGP, "Use BGP routing")
6768
fs.Uint16Var(&o.config.ListenBGPPort, "listenBGPPort", o.config.ListenBGPPort, "Custom BGP listen port")
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.13.0
6+
name: bgppolicyapplyservices.bgppolicyapply.loxilb.io
7+
spec:
8+
group: bgppolicyapply.loxilb.io
9+
names:
10+
kind: BGPPolicyApplyService
11+
listKind: BGPPolicyApplyServiceList
12+
plural: bgppolicyapplyservices
13+
singular: bgppolicyapplyservice
14+
scope: Cluster
15+
versions:
16+
- name: v1
17+
served: true
18+
storage: true
19+
additionalPrinterColumns:
20+
- name: Name
21+
type: string
22+
priority: 0
23+
jsonPath: .spec.ipAddress
24+
description: Applied policy IP address
25+
schema:
26+
openAPIV3Schema:
27+
type: object
28+
properties:
29+
spec:
30+
type: object
31+
properties:
32+
ipAddress:
33+
type: string
34+
policyType:
35+
type: string
36+
policies:
37+
type: array
38+
items:
39+
type: string
40+
routeAction:
41+
type: string
42+
status:
43+
type: object
44+
x-kubernetes-preserve-unknown-fields: true

manifest/crds/bgp-policy-apply.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: bgppolicyapply.loxilb.io/v1
2+
kind: BGPPolicyApplyService
3+
metadata:
4+
name: policy-apply
5+
spec:
6+
ipAddress: "10.10.10.254"
7+
policyType: "import"
8+
policies:
9+
- "poltest6"
10+
routeAction: "accept"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.13.0
6+
name: bgppolicydefinedsetsservices.bgppolicydefinedsets.loxilb.io
7+
spec:
8+
group: bgppolicydefinedsets.loxilb.io
9+
names:
10+
kind: BGPPolicyDefinedSetsService
11+
listKind: BGPPolicyDefinedSetsServiceList
12+
plural: bgppolicydefinedsetsservices
13+
singular: bgppolicydefinedsetsservice
14+
scope: Cluster
15+
versions:
16+
- name: v1
17+
served: true
18+
storage: true
19+
additionalPrinterColumns:
20+
- name: Name
21+
type: string
22+
priority: 0
23+
jsonPath: .spec.name
24+
description: Defined Set Name
25+
schema:
26+
openAPIV3Schema:
27+
type: object
28+
properties:
29+
spec:
30+
type: object
31+
properties:
32+
name:
33+
type: string
34+
definedType:
35+
type: string
36+
List:
37+
type: array
38+
items:
39+
type: string
40+
prefixList:
41+
type: array
42+
items:
43+
type: object
44+
properties:
45+
ipPrefix:
46+
type: string
47+
masklengthRange:
48+
type: string
49+
required:
50+
- name
51+
status:
52+
type: object
53+
x-kubernetes-preserve-unknown-fields: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: bgppolicydefinedsets.loxilb.io/v1
2+
kind: BGPPolicyDefinedSetsService
3+
metadata:
4+
name: policy-prefix
5+
spec:
6+
name: "ps2"
7+
definedType: "prefix"
8+
prefixList:
9+
- ipPrefix: "192.168.0.0/16"
10+
masklengthRange: "16..24"

0 commit comments

Comments
 (0)