Skip to content

Commit 789cecb

Browse files
committed
cni-server: add static fdb entry for subnets with u2o enabled (#6269)
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
1 parent 9708780 commit 789cecb

32 files changed

+3164
-28
lines changed

hack/modelgen.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,30 @@ set -o errexit
44
set -o nounset
55
set -o pipefail
66

7+
OVS_VERSION="3.3"
78
OVN_VERSION="24.03"
89

9-
# download ovn nb/sb schema files
10+
# download vswitch/nb/sb schema files
11+
curl -sSf -L --retry 5 -o vswitch.ovsschema \
12+
https://raw.githubusercontent.com/openvswitch/ovs/refs/heads/branch-${OVS_VERSION}/vswitchd/vswitch.ovsschema
1013
curl -sSf -L --retry 5 -o ovn-nb.ovsschema \
1114
https://raw.githubusercontent.com/ovn-org/ovn/refs/heads/branch-${OVN_VERSION}/ovn-nb.ovsschema
1215
curl -sSf -L --retry 5 -o ovn-sb.ovsschema \
1316
https://raw.githubusercontent.com/ovn-org/ovn/refs/heads/branch-${OVN_VERSION}/ovn-sb.ovsschema
1417

1518
# remove old generated files
16-
rm -rf pkg/ovsdb/ovnnb pkg/ovsdb/ovnsb
19+
rm -rfv pkg/ovsdb/vswitch pkg/ovsdb/ovnnb pkg/ovsdb/ovnsb
1720

18-
# generate go code from ovn nb/sb schema files
21+
# generate go code from vswitch/nb/sb schema files
22+
go tool github.com/ovn-kubernetes/libovsdb/cmd/modelgen \
23+
-p vswitch -o pkg/ovsdb/vswitch vswitch.ovsschema
1924
go tool github.com/ovn-kubernetes/libovsdb/cmd/modelgen \
2025
-p ovnnb -o pkg/ovsdb/ovnnb ovn-nb.ovsschema
2126
go tool github.com/ovn-kubernetes/libovsdb/cmd/modelgen \
2227
-p ovnsb -o pkg/ovsdb/ovnsb ovn-sb.ovsschema
2328

2429
# remove downloaded schema files
25-
rm -f ovn-nb.ovsschema ovn-sb.ovsschema
30+
rm -fv vswitch.ovsschema ovn-nb.ovsschema ovn-sb.ovsschema
2631

2732
# add generated files to git
28-
git add pkg/ovsdb/ovnnb pkg/ovsdb/ovnsb
33+
git add pkg/ovsdb/vswitch pkg/ovsdb/ovnnb pkg/ovsdb/ovnsb

mocks/pkg/ovs/interface.go

Lines changed: 160 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,9 @@ func (c *Controller) Run(ctx context.Context) {
988988
c.initResourceOnce()
989989
<-ctx.Done()
990990
klog.Info("Shutting down workers")
991+
992+
c.OVNNbClient.Close()
993+
c.OVNSbClient.Close()
991994
}
992995

993996
func (c *Controller) dbStatus() {

pkg/daemon/controller.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"slices"
77
"strconv"
88
"strings"
9+
"sync"
910
"time"
1011

1112
nadutils "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/utils"
@@ -71,6 +72,11 @@ type Controller struct {
7172
localNamespace string
7273

7374
k8sExec k8sexec.Interface
75+
76+
// channel used for fdb sync
77+
fdbSyncChan chan struct{}
78+
fdbSyncMutex sync.Mutex
79+
vswitchClient ovs.Vswitch
7480
}
7581

7682
func newTypedRateLimitingQueue[T comparable](name string, rateLimiter workqueue.TypedRateLimiter[T]) workqueue.TypedRateLimitingInterface[T] {
@@ -125,6 +131,8 @@ func NewController(config *Configuration, stopCh <-chan struct{}, podInformerFac
125131

126132
recorder: recorder,
127133
k8sExec: k8sexec.New(),
134+
135+
fdbSyncChan: make(chan struct{}, 1),
128136
}
129137

130138
node, err := config.KubeClient.CoreV1().Nodes().Get(context.Background(), config.NodeName, metav1.GetOptions{})
@@ -180,6 +188,10 @@ func NewController(config *Configuration, stopCh <-chan struct{}, podInformerFac
180188
return nil, err
181189
}
182190

191+
if controller.vswitchClient, err = ovs.NewVswitchClient("unix:/var/run/openvswitch/db.sock", 1, 3); err != nil {
192+
return nil, fmt.Errorf("failed to create vswitch client: %w", err)
193+
}
194+
183195
return controller, nil
184196
}
185197

@@ -521,6 +533,7 @@ func (c *Controller) processNextSubnetWorkItem() bool {
521533

522534
err := func(obj *subnetEvent) error {
523535
defer c.subnetQueue.Done(obj)
536+
c.requestFdbSync()
524537
if err := c.reconcileRouters(obj); err != nil {
525538
c.subnetQueue.AddRateLimited(obj)
526539
return fmt.Errorf("error syncing %v: %w, requeuing", obj, err)
@@ -656,6 +669,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
656669
defer c.subnetQueue.ShutDown()
657670
defer c.serviceQueue.ShutDown()
658671
defer c.updatePodQueue.ShutDown()
672+
defer c.vswitchClient.Close()
659673

660674
go wait.Until(ovs.CleanLostInterface, time.Minute, stopCh)
661675
go wait.Until(recompute, 10*time.Minute, stopCh)
@@ -714,6 +728,9 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
714728
// Start OpenFlow sync loop
715729
go c.runFlowSync(stopCh)
716730

731+
// start fdb sync loop
732+
go c.runFdbSync(stopCh)
733+
717734
<-stopCh
718735
klog.Info("Shutting down workers")
719736
}

0 commit comments

Comments
 (0)