Skip to content

Commit a981c27

Browse files
authored
Merge pull request #5263 from jcaamano/fix-ofmanager-concurrent
Fix panic/race around openflowmanager
2 parents bed7073 + 682b603 commit a981c27

File tree

4 files changed

+265
-179
lines changed

4 files changed

+265
-179
lines changed

go-controller/pkg/node/gateway_shared_intf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func (npw *nodePortWatcher) updateServiceFlowCache(service *corev1.Service, netI
422422
ipPrefix = "ipv6"
423423
}
424424
// table 2, user-defined network host -> OVN towards default cluster network services
425-
defaultNetConfig := npw.ofm.defaultBridge.getActiveNetworkBridgeConfig(types.DefaultNetworkName)
425+
defaultNetConfig := npw.ofm.defaultBridge.getActiveNetworkBridgeConfigCopy(types.DefaultNetworkName)
426426
// sample flow: cookie=0xdeff105, duration=2319.685s, table=2, n_packets=496, n_bytes=67111, priority=300,
427427
// ip,nw_dst=10.96.0.1 actions=mod_dl_dst:02:42:ac:12:00:03,output:"patch-breth0_ov"
428428
// This flow is used for UDNs and advertised UDNs to be able to reach kapi and dns services alone on default network

go-controller/pkg/node/gateway_udn.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,18 @@ func (b *bridgeConfiguration) delNetworkBridgeConfig(nInfo util.NetInfo) {
146146
delete(b.netConfig, nInfo.GetNetworkName())
147147
}
148148

149-
// getActiveNetworkBridgeConfig returns a shallow copy of the network configuration corresponding to the
149+
func (b *bridgeConfiguration) getNetworkBridgeConfig(networkName string) *bridgeUDNConfiguration {
150+
b.Lock()
151+
defer b.Unlock()
152+
return b.netConfig[networkName]
153+
}
154+
155+
// getActiveNetworkBridgeConfigCopy returns a shallow copy of the network configuration corresponding to the
150156
// provided netInfo.
151157
//
152158
// NOTE: if the network configuration can't be found or if the network is not patched by OVN
153159
// yet this returns nil.
154-
func (b *bridgeConfiguration) getActiveNetworkBridgeConfig(networkName string) *bridgeUDNConfiguration {
160+
func (b *bridgeConfiguration) getActiveNetworkBridgeConfigCopy(networkName string) *bridgeUDNConfiguration {
155161
b.Lock()
156162
defer b.Unlock()
157163

@@ -917,9 +923,18 @@ func (udng *UserDefinedNetworkGateway) Reconcile() {
917923
func (udng *UserDefinedNetworkGateway) doReconcile() error {
918924
klog.Infof("Reconciling gateway with updates for UDN %s", udng.GetNetworkName())
919925

926+
// shouldn't happen
927+
if udng.openflowManager == nil || udng.openflowManager.defaultBridge == nil {
928+
return fmt.Errorf("openflow manager with default bridge configuration has not been provided for network %s", udng.GetNetworkName())
929+
}
930+
920931
// update bridge configuration
921932
isNetworkAdvertised := util.IsPodNetworkAdvertisedAtNode(udng.NetInfo, udng.node.Name)
922-
udng.openflowManager.defaultBridge.netConfig[udng.GetNetworkName()].advertised.Store(isNetworkAdvertised)
933+
netConfig := udng.openflowManager.defaultBridge.getNetworkBridgeConfig(udng.GetNetworkName())
934+
if netConfig == nil {
935+
return fmt.Errorf("missing bridge configuration for network %s", udng.GetNetworkName())
936+
}
937+
netConfig.advertised.Store(isNetworkAdvertised)
923938

924939
if err := udng.updateUDNVRFIPRules(isNetworkAdvertised); err != nil {
925940
return fmt.Errorf("error while updating ip rule for UDN %s: %s", udng.GetNetworkName(), err)

go-controller/pkg/node/openflow_manager.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (c *openflowManager) delNetwork(nInfo util.NetInfo) {
5959
}
6060

6161
func (c *openflowManager) getActiveNetwork(nInfo util.NetInfo) *bridgeUDNConfiguration {
62-
return c.defaultBridge.getActiveNetworkBridgeConfig(nInfo.GetNetworkName())
62+
return c.defaultBridge.getActiveNetworkBridgeConfigCopy(nInfo.GetNetworkName())
6363
}
6464

6565
// END UDN UTILs
@@ -211,9 +211,15 @@ func (c *openflowManager) Run(stopChan <-chan struct{}, doneWg *sync.WaitGroup)
211211
}
212212

213213
func (c *openflowManager) updateBridgePMTUDFlowCache(key string, ipAddrs []string) {
214+
// protect defaultBridge config from being updated by gw.nodeIPManager
215+
c.defaultBridge.Lock()
216+
defer c.defaultBridge.Unlock()
217+
214218
dftFlows := pmtudDropFlows(c.defaultBridge, ipAddrs)
215219
c.updateFlowCacheEntry(key, dftFlows)
216220
if c.externalGatewayBridge != nil {
221+
c.externalGatewayBridge.Lock()
222+
defer c.externalGatewayBridge.Unlock()
217223
exGWBridgeDftFlows := pmtudDropFlows(c.externalGatewayBridge, ipAddrs)
218224
c.updateExBridgeFlowCacheEntry(key, exGWBridgeDftFlows)
219225
}

0 commit comments

Comments
 (0)