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

Commit 819d938

Browse files
committed
add fdb for flannel which is needed 4 connectivity
1 parent c3b3868 commit 819d938

File tree

6 files changed

+95
-29
lines changed

6 files changed

+95
-29
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
}

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)