Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit 27d4c31

Browse files
Niklaus-xiegitee-org
authored andcommitted
!27 add fdb for flannel which is needed 4 connectivity
Merge pull request !27 from niklaus-x/add-fdb-4-node-reconcile-add-gomod
2 parents c3b3868 + e6d4ed8 commit 27d4c31

File tree

8 files changed

+98
-32
lines changed

8 files changed

+98
-32
lines changed

controllers/v1_controller.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
9595
ocfgs := map[string]interface{}{}
9696
ncfgs := map[string]interface{}{}
9797

98+
oIpToMacV4 := map[string]string{}
99+
// oIpToMacV6 := map[string]string{}
100+
nIpToMacV4 := map[string]string{}
101+
// nIpToMacV6 := map[string]string{}
102+
98103
var obj v1.Node
99104
zlog := log.FromContext(ctx)
100105
zlog.V(1).Info("resource event: " + req.NamespacedName.String())
@@ -137,6 +142,13 @@ func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
137142
}
138143
}
139144

145+
if pkg.ActiveSIGs.Mode == "flannel" {
146+
oIpToMacV4, _ = k8s.NodeCache.AllIpToMac()
147+
if ocfgs, err = pkg.ParseFdbsFrom(pkg.ActiveSIGs.VxlanTunnelName, oIpToMacV4); err != nil {
148+
return ctrl.Result{}, err
149+
}
150+
}
151+
140152
k8s.NodeCache.Set(obj.DeepCopy())
141153

142154
if pkg.ActiveSIGs.Mode == "calico" {
@@ -145,14 +157,21 @@ func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
145157
return ctrl.Result{}, err
146158
}
147159

148-
pkg.PendingDeploys <- pkg.DeployRequest{
149-
Meta: fmt.Sprintf("refreshing neighs for node '%s'", req.Name),
150-
From: &ocfgs,
151-
To: &ncfgs,
152-
StatusFunc: func() {},
153-
Partition: "Common",
160+
}
161+
162+
if pkg.ActiveSIGs.Mode == "flannel" {
163+
nIpToMacV4, _ = k8s.NodeCache.AllIpToMac()
164+
if ncfgs, err = pkg.ParseFdbsFrom(pkg.ActiveSIGs.VxlanTunnelName, nIpToMacV4); err != nil {
165+
return ctrl.Result{}, err
154166
}
155167
}
168+
pkg.PendingDeploys <- pkg.DeployRequest{
169+
Meta: fmt.Sprintf("refreshing for request '%s'", req.Name),
170+
From: &ocfgs,
171+
To: &ncfgs,
172+
StatusFunc: func() {},
173+
Partition: "Common",
174+
}
156175
}
157176
return ctrl.Result{}, nil
158177
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module gitee.com/zongzw/bigip-kubernetes-gateway
33
go 1.19
44

55
require (
6-
gitee.com/zongzw/f5-bigip-rest v0.0.0-20221130015610-8a29e5ce86f8
6+
gitee.com/zongzw/f5-bigip-rest v0.0.0-20221205102327-fa38879c1630
77
github.com/onsi/ginkgo/v2 v2.3.1
88
github.com/onsi/gomega v1.22.1
99
github.com/prometheus/client_golang v1.13.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
4444
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
4545
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
4646
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
47-
gitee.com/zongzw/f5-bigip-rest v0.0.0-20221130015610-8a29e5ce86f8 h1:fSZ3htadktrBRev5bqA6LuQVAdGh3sjQUERVDHmxRa4=
48-
gitee.com/zongzw/f5-bigip-rest v0.0.0-20221130015610-8a29e5ce86f8/go.mod h1:jx0Y6qhir/J/75V5tCYrLlmKPaZUEfbCg8fS6Xo6Syw=
47+
gitee.com/zongzw/f5-bigip-rest v0.0.0-20221205102327-fa38879c1630 h1:ohgztWDK54plXV9PZ+1ABa4vwQCEi1+ANcEfd23Jt8M=
48+
gitee.com/zongzw/f5-bigip-rest v0.0.0-20221205102327-fa38879c1630/go.mod h1:jx0Y6qhir/J/75V5tCYrLlmKPaZUEfbCg8fS6Xo6Syw=
4949
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
5050
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
5151
github.com/Azure/go-autorest/autorest v0.11.27 h1:F3R3q42aWytozkV8ihzcgMO4OA4cuqr3bNlsEuF6//A=

k8s/k8s.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,24 @@ func (ns *Nodes) AllIpAddresses() []string {
127127
}
128128
return rlt
129129
}
130+
131+
func (ns *Nodes) AllIpToMac() (map[string]string, map[string]string) {
132+
NodeCache.mutex <- true
133+
defer func() { <-NodeCache.mutex }()
134+
135+
rlt4 := map[string]string{}
136+
rlt6 := map[string]string{}
137+
138+
for _, n := range ns.Items {
139+
if len(n.IpAddr) > 0 && len(n.MacAddr) > 0 {
140+
slog.Infof("n.IpAddress is %s:", n.IpAddr)
141+
rlt4[n.IpAddr] = n.MacAddr
142+
}
143+
if len(n.IpAddrV6) > 0 && len(n.MacAddrV6) > 0 {
144+
slog.Infof("n.IpAddrV6 is %s:", n.IpAddrV6)
145+
rlt6[n.IpAddrV6] = n.MacAddrV6
146+
}
147+
148+
}
149+
return rlt4, rlt6
150+
}

main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ func main() {
9292
flag.StringVar(&credsDir, "credentials-directory", "", "Optional, directory that contains the BIG-IP username,"+
9393
"password, and/or url files. To be used instead of username, password, and/or url arguments.")
9494
flag.StringVar(&controllerName, "controller-name", "f5.io/gateway-controller-name", "This controller name.")
95-
flag.StringVar(&mode, "mode", "flannel", "if set to calico or flannel, will make some related configs onto bigip automatically.")
95+
flag.StringVar(&mode, "mode", "", "if set to calico or flannel, will make some related configs onto bigip automatically.")
9696
flag.StringVar(&vxlanProfileName, "vxlan-profile-name", "fl-vxlan", "vxlan profile name on bigip.")
9797
flag.StringVar(&vxlanPort, "vxlan-port", "8472", "port number in the vxlan profile.")
9898
flag.StringVar(&vxlanTunnelName, "vxlan-tunnel-name", "fl-vxlan", "vxlan tunnel name on bigip.")
99-
flag.StringVar(&vxlanLocalAddress, "vxlan-local-address", "9.4.4.4", "local address in the vxlan tunnel. e.g. 192.168.2.100")
99+
flag.StringVar(&vxlanLocalAddress, "vxlan-local-address", "", "local address in the vxlan tunnel. e.g. 192.168.2.100")
100100
flag.StringVar(&selfIpName, "selfip-name", "flannel-self", "flannel selfip name.")
101-
flag.StringVar(&selfIpAddress, "selfip-address", "5.5.5.5/28", "flannel selfip ip address. e.g. 192.168.1.100/24")
101+
flag.StringVar(&selfIpAddress, "selfip-address", "", "flannel selfip ip address. e.g. 192.168.1.100/24")
102102

103103
opts := zap.Options{
104104
Development: true,
@@ -108,6 +108,7 @@ func main() {
108108

109109
pkg.ActiveSIGs.ControllerName = controllerName
110110
pkg.ActiveSIGs.Mode = mode
111+
pkg.ActiveSIGs.VxlanTunnelName = vxlanTunnelName
111112

112113
if (len(bigipUrl) == 0 || len(bigipUsername) == 0 ||
113114
len(bigipPassword) == 0) && len(credsDir) == 0 {

pkg/parser.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,3 +625,26 @@ func ParseNeighsFrom(routerName, localAs, remoteAs string, addresses []string) (
625625
"": rlt,
626626
}, nil
627627
}
628+
629+
func ParseFdbsFrom(tunnelName string, iPToMac map[string]string) (map[string]interface{}, error) {
630+
rlt := map[string]interface{}{}
631+
632+
rlt["net/fdb/tunnel/"+tunnelName] = map[string]interface{}{
633+
"records": []interface{}{},
634+
}
635+
636+
fmtrecords := []interface{}{}
637+
for ip, mac := range iPToMac {
638+
slog.Infof("parse ip address: %s and mac: %s", ip, mac)
639+
fmtrecords = append(fmtrecords, map[string]string{
640+
"name": mac,
641+
"endpoint": ip,
642+
})
643+
}
644+
645+
rlt["net/fdb/tunnel/"+tunnelName].(map[string]interface{})["records"] = fmtrecords
646+
647+
return map[string]interface{}{
648+
"": rlt,
649+
}, nil
650+
}

pkg/types.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ type ParseRequest struct {
2222
}
2323

2424
type SIGCache struct {
25-
mutex sync.RWMutex
26-
SyncedAtStart bool
27-
ControllerName string
28-
Mode string
29-
Gateway map[string]*gatewayv1beta1.Gateway
30-
HTTPRoute map[string]*gatewayv1beta1.HTTPRoute
31-
Endpoints map[string]*v1.Endpoints
32-
Service map[string]*v1.Service
33-
GatewayClasses map[string]*gatewayv1beta1.GatewayClass
34-
Bigip *f5_bigip.BIGIP
25+
mutex sync.RWMutex
26+
SyncedAtStart bool
27+
ControllerName string
28+
Mode string
29+
VxlanTunnelName string
30+
Gateway map[string]*gatewayv1beta1.Gateway
31+
HTTPRoute map[string]*gatewayv1beta1.HTTPRoute
32+
Endpoints map[string]*v1.Endpoints
33+
Service map[string]*v1.Service
34+
GatewayClasses map[string]*gatewayv1beta1.GatewayClass
35+
Bigip *f5_bigip.BIGIP
3536
// Node map[string]*v1.Node
3637
}
3738

pkg/utils.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ func init() {
2424
PendingParses = make(chan ParseRequest, 16)
2525
slog = utils.SetupLog("", "debug")
2626
ActiveSIGs = &SIGCache{
27-
mutex: sync.RWMutex{},
28-
SyncedAtStart: false,
29-
ControllerName: "",
30-
Mode: "",
31-
Gateway: map[string]*gatewayv1beta1.Gateway{},
32-
HTTPRoute: map[string]*gatewayv1beta1.HTTPRoute{},
33-
Endpoints: map[string]*v1.Endpoints{},
34-
Service: map[string]*v1.Service{},
35-
GatewayClasses: map[string]*gatewayv1beta1.GatewayClass{},
36-
Bigip: nil,
27+
mutex: sync.RWMutex{},
28+
SyncedAtStart: false,
29+
ControllerName: "",
30+
Mode: "",
31+
VxlanTunnelName: "",
32+
Gateway: map[string]*gatewayv1beta1.Gateway{},
33+
HTTPRoute: map[string]*gatewayv1beta1.HTTPRoute{},
34+
Endpoints: map[string]*v1.Endpoints{},
35+
Service: map[string]*v1.Service{},
36+
GatewayClasses: map[string]*gatewayv1beta1.GatewayClass{},
37+
Bigip: nil,
3738
// Node: map[string]*v1.Node{},
3839
}
3940
}

0 commit comments

Comments
 (0)