Skip to content

Commit 7823281

Browse files
committed
Merge remote-tracking branch 'ovnorg/master' into merge-7th-feb-2025
2 parents 633ebb6 + 7d79da2 commit 7823281

File tree

22 files changed

+494
-2087
lines changed

22 files changed

+494
-2087
lines changed

go-controller/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ require (
1111
github.com/containernetworking/cni v1.1.2
1212
github.com/containernetworking/plugins v1.2.0
1313
github.com/coreos/go-iptables v0.6.0
14-
github.com/coreos/go-systemd/v22 v22.5.0
1514
github.com/fsnotify/fsnotify v1.7.0
1615
github.com/gaissmai/cidrtree v0.1.4
1716
github.com/go-logr/logr v1.4.2
1817
github.com/go-logr/stdr v1.2.2
18+
github.com/godbus/dbus/v5 v5.1.0
1919
github.com/google/go-cmp v0.6.0
2020
github.com/google/gopacket v1.1.19
2121
github.com/google/uuid v1.6.0
@@ -30,6 +30,7 @@ require (
3030
github.com/metallb/frr-k8s v0.0.15
3131
github.com/miekg/dns v1.1.31
3232
github.com/mitchellh/copystructure v1.2.0
33+
github.com/moby/sys/userns v0.1.0
3334
github.com/onsi/ginkgo/v2 v2.19.0
3435
github.com/onsi/gomega v1.33.1
3536
github.com/openshift/api v0.0.0-20231120222239-b86761094ee3
@@ -84,7 +85,6 @@ require (
8485
github.com/go-openapi/jsonreference v0.21.0 // indirect
8586
github.com/go-openapi/swag v0.23.0 // indirect
8687
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
87-
github.com/godbus/dbus/v5 v5.1.0 // indirect
8888
github.com/gogo/protobuf v1.3.2 // indirect
8989
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
9090
github.com/golang/protobuf v1.5.4 // indirect

go-controller/go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7
224224
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
225225
github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
226226
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
227-
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
228-
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
229227
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
230228
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
231229
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
@@ -344,7 +342,6 @@ github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZ
344342
github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
345343
github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
346344
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
347-
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
348345
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
349346
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
350347
github.com/gogo/googleapis v1.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU=
@@ -584,6 +581,8 @@ github.com/moby/spdystream v0.4.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVO
584581
github.com/moby/sys/mountinfo v0.4.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
585582
github.com/moby/sys/mountinfo v0.4.1/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
586583
github.com/moby/sys/symlink v0.1.0/go.mod h1:GGDODQmbFOjFsXvfLVn3+ZRxkch54RkSiGqsZeMYowQ=
584+
github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g=
585+
github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28=
587586
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo=
588587
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
589588
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=

go-controller/pkg/factory/factory.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ const (
190190
defaultHandlerPriority int = 0
191191
// lowest priority among various handlers (See GetHandlerPriority for more information)
192192
minHandlerPriority int = 4
193+
194+
// used to determine if an internal informer has handlers attached to it or not
195+
hasNoHandler uint32 = 0
196+
hasHandler uint32 = 1
193197
)
194198

195199
var (
@@ -1295,6 +1299,12 @@ func (wf *WatchFactory) addHandler(objType reflect.Type, namespace string, sel l
12951299
intInf.Lock()
12961300
defer intInf.Unlock()
12971301

1302+
// we are going to add a handler, we need to update the atomic signal that handlers exist now
1303+
// so that we do not miss events after we list current items.
1304+
// We need to do this after we get internal informer lock, to preserve that we can be the only one updating
1305+
// the atomic and preserve known state of the atomic while the handler is going to be added in the future
1306+
hadZeroHandlers := atomic.CompareAndSwapUint32(&intInf.hasHandlers, hasNoHandler, hasHandler)
1307+
12981308
items := make([]interface{}, 0)
12991309
for _, obj := range inf.inf.GetStore().List() {
13001310
if filterFunc(obj) {
@@ -1313,6 +1323,10 @@ func (wf *WatchFactory) addHandler(objType reflect.Type, namespace string, sel l
13131323
return true, nil
13141324
})
13151325
if err != nil {
1326+
// handler is not going to be added, restore previous value if needed
1327+
if hadZeroHandlers {
1328+
atomic.StoreUint32(&intInf.hasHandlers, hasNoHandler)
1329+
}
13161330
return nil, err
13171331
}
13181332
}

go-controller/pkg/factory/handler.go

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"sync/atomic"
88
"time"
99

10-
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/cryptorand"
1110
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/metrics"
1211

1312
ipamclaimslister "github.com/k8snetworkplumbingwg/ipamclaims/pkg/crd/ipamclaims/v1alpha1/apis/listers/ipamclaims/v1alpha1"
@@ -26,6 +25,7 @@ import (
2625

2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2827
ktypes "k8s.io/apimachinery/pkg/types"
28+
"k8s.io/apimachinery/pkg/util/rand"
2929
listers "k8s.io/client-go/listers/core/v1"
3030
discoverylisters "k8s.io/client-go/listers/discovery/v1"
3131
netlisters "k8s.io/client-go/listers/networking/v1"
@@ -107,20 +107,22 @@ type queueMapEntry struct {
107107

108108
type internalInformer struct {
109109
sync.RWMutex
110-
oType reflect.Type
110+
oType reflect.Type
111+
// keyed by priority - used to track the handler's priority of being invoked.
112+
// example: a handler with priority 0 will process the received event first
113+
// before a handler with priority 1, 0 being the highest priority.
114+
// NOTE: we can have multiple handlers with the same priority hence the value
115+
// is a map of handlers keyed by its unique id.
111116
handlers map[int]map[uint64]*Handler
112117
// queueMap handles distributing events across a queued handler's queues
113118
queueMap *queueMap
119+
// hasHandlers is an atomic used to determine if this internal informer actually has handlers attached to it or not
120+
hasHandlers uint32
114121
}
115122

116123
type informer struct {
117-
oType reflect.Type
118-
inf cache.SharedIndexInformer
119-
// keyed by priority - used to track the handler's priority of being invoked.
120-
// example: a handler with priority 0 will process the received event first
121-
// before a handler with priority 1, 0 being the higest priority.
122-
// NOTE: we can have multiple handlers with the same priority hence the value
123-
// is a map of handlers keyed by its unique id.
124+
oType reflect.Type
125+
inf cache.SharedIndexInformer
124126
lister listerInterface
125127
// initialAddFunc will be called to deliver the initial list of objects
126128
// when a handler is added
@@ -133,7 +135,7 @@ type informer struct {
133135
func (inf *internalInformer) forEachQueuedHandler(f func(h *Handler)) {
134136
inf.RLock()
135137
defer inf.RUnlock()
136-
for priority := 0; priority <= minHandlerPriority; priority++ { // loop over priority higest to lowest
138+
for priority := 0; priority <= minHandlerPriority; priority++ { // loop over priority highest to lowest
137139
for _, handler := range inf.handlers[priority] {
138140
f(handler)
139141
}
@@ -192,19 +194,28 @@ func (i *informer) removeHandler(handler *Handler) {
192194

193195
intInf.Lock()
194196
defer intInf.Unlock()
195-
removed := 0
197+
removed := false
198+
// track overall how many handlers this internal informer has
199+
numHandlers := 0
196200
for priority := range intInf.handlers { // loop over priority
197201
if _, ok := intInf.handlers[priority]; !ok {
198202
continue // protection against nil map as value
199203
}
200204
if _, ok := intInf.handlers[priority][handler.id]; ok {
201205
// Remove the handler
202206
delete(intInf.handlers[priority], handler.id)
203-
removed = 1
207+
removed = true
204208
klog.V(5).Infof("Removed %v event handler %d", i.oType, handler.id)
205209
}
210+
numHandlers += len(intInf.handlers[priority])
206211
}
207-
if removed == 0 {
212+
213+
// if this internal informer has no handlers, update the atomic
214+
if numHandlers == 0 {
215+
atomic.StoreUint32(&intInf.hasHandlers, hasNoHandler)
216+
}
217+
218+
if !removed {
208219
klog.Warningf("Tried to remove unknown object type %v event handler %d", i.oType, handler.id)
209220
}
210221
}()
@@ -260,7 +271,7 @@ func (qm *queueMap) getNewQueueNum() uint32 {
260271
if numEventQueues == 1 {
261272
return 0
262273
}
263-
startIdx = uint32(cryptorand.Intn(int64(numEventQueues - 1)))
274+
startIdx = uint32(rand.Intn(int(numEventQueues - 1)))
264275
queueIdx = startIdx
265276
lowestNum := len(qm.queues[startIdx])
266277
for j = 0; j < numEventQueues; j++ {
@@ -381,6 +392,10 @@ func (i *informer) newFederatedQueuedHandler(internalInformerIndex int) cache.Re
381392
intInf := i.internalInformers[internalInformerIndex]
382393
return cache.ResourceEventHandlerFuncs{
383394
AddFunc: func(obj interface{}) {
395+
// do not enqueue events to internal informer that has no handlers for better performance
396+
if atomic.LoadUint32(&intInf.hasHandlers) == hasNoHandler {
397+
return
398+
}
384399
intInf.queueMap.enqueueEvent(nil, obj, i.oType, false, func(e *event) {
385400
metrics.MetricResourceUpdateCount.WithLabelValues(name, "add").Inc()
386401
start := time.Now()
@@ -391,6 +406,10 @@ func (i *informer) newFederatedQueuedHandler(internalInformerIndex int) cache.Re
391406
})
392407
},
393408
UpdateFunc: func(oldObj, newObj interface{}) {
409+
// do not enqueue events to internal informer that has no handlers for better performance
410+
if atomic.LoadUint32(&intInf.hasHandlers) == hasNoHandler {
411+
return
412+
}
394413
intInf.queueMap.enqueueEvent(oldObj, newObj, i.oType, false, func(e *event) {
395414
metrics.MetricResourceUpdateCount.WithLabelValues(name, "update").Inc()
396415
start := time.Now()
@@ -415,6 +434,10 @@ func (i *informer) newFederatedQueuedHandler(internalInformerIndex int) cache.Re
415434
klog.Errorf(err.Error())
416435
return
417436
}
437+
// do not enqueue events to internal informer that has no handlers for better performance
438+
if atomic.LoadUint32(&intInf.hasHandlers) == hasNoHandler {
439+
return
440+
}
418441
intInf.queueMap.enqueueEvent(nil, realObj, i.oType, true, func(e *event) {
419442
metrics.MetricResourceUpdateCount.WithLabelValues(name, "delete").Inc()
420443
start := time.Now()

go-controller/pkg/node/default_node_network_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func newDefaultNodeNetworkController(cnnci *CommonNodeNetworkControllerInfo, sto
146146
}
147147
if util.IsNetworkSegmentationSupportEnabled() && !config.OVNKubernetesFeature.DisableUDNHostIsolation {
148148
c.udnHostIsolationManager = NewUDNHostIsolationManager(config.IPv4Mode, config.IPv6Mode,
149-
cnnci.watchFactory.PodCoreInformer())
149+
cnnci.watchFactory.PodCoreInformer(), cnnci.name, cnnci.recorder)
150150
}
151151
c.linkManager = linkmanager.NewController(cnnci.name, config.IPv4Mode, config.IPv6Mode, c.updateGatewayMAC)
152152
return c

0 commit comments

Comments
 (0)