Skip to content

Commit 399bcfd

Browse files
Merge pull request #2667 from ricky-rav/OCPBUGS-59246
OCPBUGS-59381:[release-4.17] Fix default network -> localnet
2 parents 3b4486b + e9cafcd commit 399bcfd

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

go-controller/pkg/node/gateway.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ func (g *gateway) Reconcile() error {
406406
if err != nil {
407407
return fmt.Errorf("failed to get subnets for node: %s for OpenFlow cache update; err: %w", node.Name, err)
408408
}
409-
nodeIPs, _ := g.nodeIPManager.ListAddresses()
410-
if err := g.openflowManager.updateBridgeFlowCache(subnets, nodeIPs); err != nil {
409+
hostIPs, hostSubnets := g.nodeIPManager.ListAddresses()
410+
if err := g.openflowManager.updateBridgeFlowCache(subnets, hostSubnets, hostIPs); err != nil {
411411
return err
412412
}
413413
// Services create OpenFlow flows as well, need to update them all

go-controller/pkg/node/gateway_localnet.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ import (
2020
utilnet "k8s.io/utils/net"
2121
)
2222

23-
func newLocalGateway(nodeName string, hostSubnets []*net.IPNet, gwNextHops []net.IP, gwIntf, egressGWIntf string, gwIPs []*net.IPNet,
23+
func newLocalGateway(nodeName string, subnets []*net.IPNet, gwNextHops []net.IP, gwIntf, egressGWIntf string, gwIPs []*net.IPNet,
2424
nodeAnnotator kube.Annotator, cfg *managementPortConfig, kube kube.Interface, watchFactory factory.NodeWatchFactory,
2525
routeManager *routemanager.Controller) (*gateway, error) {
2626
klog.Info("Creating new local gateway")
2727
gw := &gateway{}
2828

29-
for _, hostSubnet := range hostSubnets {
29+
for _, subnet := range subnets {
3030
// local gateway mode uses mp0 as default path for all ingress traffic into OVN
3131
var nextHop *net.IPNet
32-
if utilnet.IsIPv6CIDR(hostSubnet) {
32+
if utilnet.IsIPv6CIDR(subnet) {
3333
nextHop = cfg.ipv6.ifAddr
3434
} else {
3535
nextHop = cfg.ipv4.ifAddr
@@ -129,16 +129,16 @@ func newLocalGateway(nodeName string, hostSubnets []*net.IPNet, gwNextHops []net
129129
return fmt.Errorf("failed to update masquerade subnet annotation on node: %s, error: %v", nodeName, err)
130130
}
131131

132-
nodeIPs, _ := gw.nodeIPManager.ListAddresses()
133-
gw.openflowManager, err = newGatewayOpenFlowManager(gwBridge, exGwBridge, hostSubnets, nodeIPs)
132+
hostIPs, hostSubnets := gw.nodeIPManager.ListAddresses()
133+
gw.openflowManager, err = newGatewayOpenFlowManager(gwBridge, exGwBridge, subnets, hostSubnets, hostIPs)
134134
if err != nil {
135135
return err
136136
}
137137
// resync flows on IP change
138138
gw.nodeIPManager.OnChanged = func() {
139139
klog.V(5).Info("Node addresses changed, re-syncing bridge flows")
140-
nodeIPs, _ := gw.nodeIPManager.ListAddresses()
141-
if err := gw.openflowManager.updateBridgeFlowCache(hostSubnets, nodeIPs); err != nil {
140+
hostIPs, hostSubnets := gw.nodeIPManager.ListAddresses()
141+
if err := gw.openflowManager.updateBridgeFlowCache(subnets, hostSubnets, hostIPs); err != nil {
142142
// very unlikely - somehow node has lost its IP address
143143
klog.Errorf("Failed to re-generate gateway flows after address change: %v", err)
144144
}
@@ -158,7 +158,7 @@ func newLocalGateway(nodeName string, hostSubnets []*net.IPNet, gwNextHops []net
158158
if config.Gateway.NodeportEnable {
159159
if config.OvnKubeNode.Mode == types.NodeModeFull {
160160
// (TODO): Internal Traffic Policy is not supported in DPU mode
161-
if err := initSvcViaMgmPortRoutingRules(hostSubnets); err != nil {
161+
if err := initSvcViaMgmPortRoutingRules(subnets); err != nil {
162162
return err
163163
}
164164
}

go-controller/pkg/node/gateway_shared_intf.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ func flowsForDefaultBridge(bridge *bridgeConfiguration, extraIPs []net.IP) ([]st
13711371
return dftFlows, nil
13721372
}
13731373

1374-
func commonFlows(subnets []*net.IPNet, bridge *bridgeConfiguration) ([]string, error) {
1374+
func commonFlows(subnets, hostSubnets []*net.IPNet, bridge *bridgeConfiguration) ([]string, error) {
13751375
// CAUTION: when adding new flows where the in_port is ofPortPatch and the out_port is ofPortPhys, ensure
13761376
// that dl_src is included in match criteria!
13771377
ofPortPhys := bridge.ofPortPhys
@@ -1432,7 +1432,7 @@ func commonFlows(subnets []*net.IPNet, bridge *bridgeConfiguration) ([]string, e
14321432

14331433
// Allow OVN->Host traffic on the same node
14341434
if config.Gateway.Mode == config.GatewayModeShared || config.Gateway.Mode == config.GatewayModeLocal {
1435-
dftFlows = append(dftFlows, ovnToHostNetworkNormalActionFlows(netConfig, bridgeMacAddress, subnets, false)...)
1435+
dftFlows = append(dftFlows, ovnToHostNetworkNormalActionFlows(netConfig, bridgeMacAddress, hostSubnets, false)...)
14361436
}
14371437
} else {
14381438
// for UDN we additionally SNAT the packet from masquerade IP -> node IP
@@ -1512,7 +1512,7 @@ func commonFlows(subnets []*net.IPNet, bridge *bridgeConfiguration) ([]string, e
15121512

15131513
// Allow OVN->Host traffic on the same node
15141514
if config.Gateway.Mode == config.GatewayModeShared || config.Gateway.Mode == config.GatewayModeLocal {
1515-
dftFlows = append(dftFlows, ovnToHostNetworkNormalActionFlows(netConfig, bridgeMacAddress, subnets, true)...)
1515+
dftFlows = append(dftFlows, ovnToHostNetworkNormalActionFlows(netConfig, bridgeMacAddress, hostSubnets, true)...)
15161516
}
15171517
} else {
15181518
// for UDN we additionally SNAT the packet from masquerade IP -> node IP
@@ -1771,11 +1771,11 @@ func setBridgeOfPorts(bridge *bridgeConfiguration) error {
17711771

17721772
// initSvcViaMgmPortRoutingRules creates the svc2managementport routing table, routes and rules
17731773
// that let's us forward service traffic to ovn-k8s-mp0 as opposed to the default route towards breth0
1774-
func initSvcViaMgmPortRoutingRules(hostSubnets []*net.IPNet) error {
1774+
func initSvcViaMgmPortRoutingRules(subnets []*net.IPNet) error {
17751775
// create ovnkubeSvcViaMgmPortRT and service route towards ovn-k8s-mp0
1776-
for _, hostSubnet := range hostSubnets {
1777-
isIPv6 := utilnet.IsIPv6CIDR(hostSubnet)
1778-
gatewayIP := util.GetNodeGatewayIfAddr(hostSubnet).IP.String()
1776+
for _, subnet := range subnets {
1777+
isIPv6 := utilnet.IsIPv6CIDR(subnet)
1778+
gatewayIP := util.GetNodeGatewayIfAddr(subnet).IP.String()
17791779
for _, svcCIDR := range config.Kubernetes.ServiceCIDRs {
17801780
if isIPv6 == utilnet.IsIPv6CIDR(svcCIDR) {
17811781
if stdout, stderr, err := util.RunIP("route", "replace", "table", ovnkubeSvcViaMgmPortRT, svcCIDR.String(), "via", gatewayIP, "dev", types.K8sMgmtIntfName); err != nil {
@@ -1895,7 +1895,7 @@ func newSharedGateway(nodeName string, subnets []*net.IPNet, gwNextHops []net.IP
18951895
}
18961896
}
18971897
gw.nodeIPManager = newAddressManager(nodeName, kube, cfg, watchFactory, gwBridge)
1898-
nodeIPs, _ := gw.nodeIPManager.ListAddresses()
1898+
hostIPs, hostSubnets := gw.nodeIPManager.ListAddresses()
18991899

19001900
if config.OvnKubeNode.Mode == types.NodeModeFull {
19011901
// Delete stale masquerade resources if there are any. This is to make sure that there
@@ -1919,7 +1919,7 @@ func newSharedGateway(nodeName string, subnets []*net.IPNet, gwNextHops []net.IP
19191919
}
19201920
}
19211921

1922-
gw.openflowManager, err = newGatewayOpenFlowManager(gwBridge, exGwBridge, subnets, nodeIPs)
1922+
gw.openflowManager, err = newGatewayOpenFlowManager(gwBridge, exGwBridge, subnets, hostSubnets, hostIPs)
19231923
if err != nil {
19241924
return err
19251925
}
@@ -1928,7 +1928,7 @@ func newSharedGateway(nodeName string, subnets []*net.IPNet, gwNextHops []net.IP
19281928
gw.nodeIPManager.OnChanged = func() {
19291929
klog.V(5).Info("Node addresses changed, re-syncing bridge flows")
19301930
nodeIPs, _ := gw.nodeIPManager.ListAddresses()
1931-
if err := gw.openflowManager.updateBridgeFlowCache(subnets, nodeIPs); err != nil {
1931+
if err := gw.openflowManager.updateBridgeFlowCache(subnets, hostSubnets, nodeIPs); err != nil {
19321932
// very unlikely - somehow node has lost its IP address
19331933
klog.Errorf("Failed to re-generate gateway flows after address change: %v", err)
19341934
}

go-controller/pkg/node/openflow_manager.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (c *openflowManager) syncFlows() {
145145
//
146146
// -- to handle host -> service access, via masquerading from the host to OVN GR
147147
// -- to handle external -> service(ExternalTrafficPolicy: Local) -> host access without SNAT
148-
func newGatewayOpenFlowManager(gwBridge, exGWBridge *bridgeConfiguration, subnets []*net.IPNet, extraIPs []net.IP) (*openflowManager, error) {
148+
func newGatewayOpenFlowManager(gwBridge, exGWBridge *bridgeConfiguration, subnets, hostSubnets []*net.IPNet, extraIPs []net.IP) (*openflowManager, error) {
149149
// add health check function to check default OpenFlow flows are on the shared gateway bridge
150150
ofm := &openflowManager{
151151
defaultBridge: gwBridge,
@@ -157,7 +157,7 @@ func newGatewayOpenFlowManager(gwBridge, exGWBridge *bridgeConfiguration, subnet
157157
flowChan: make(chan struct{}, 1),
158158
}
159159

160-
if err := ofm.updateBridgeFlowCache(subnets, extraIPs); err != nil {
160+
if err := ofm.updateBridgeFlowCache(subnets, hostSubnets, extraIPs); err != nil {
161161
return nil, err
162162
}
163163

@@ -201,19 +201,19 @@ func (c *openflowManager) Run(stopChan <-chan struct{}, doneWg *sync.WaitGroup)
201201

202202
// updateBridgeFlowCache generates the "static" per-bridge flows
203203
// note: this is shared between shared and local gateway modes
204-
func (c *openflowManager) updateBridgeFlowCache(subnets []*net.IPNet, extraIPs []net.IP) error {
204+
func (c *openflowManager) updateBridgeFlowCache(subnets, hostSubnets []*net.IPNet, hostIPs []net.IP) error {
205205
// protect defaultBridge config from being updated by gw.nodeIPManager
206206
c.defaultBridge.Lock()
207207
defer c.defaultBridge.Unlock()
208208

209209
// CAUTION: when adding new flows where the in_port is ofPortPatch and the out_port is ofPortPhys, ensure
210210
// that dl_src is included in match criteria!
211211

212-
dftFlows, err := flowsForDefaultBridge(c.defaultBridge, extraIPs)
212+
dftFlows, err := flowsForDefaultBridge(c.defaultBridge, hostIPs)
213213
if err != nil {
214214
return err
215215
}
216-
dftCommonFlows, err := commonFlows(subnets, c.defaultBridge)
216+
dftCommonFlows, err := commonFlows(subnets, hostSubnets, c.defaultBridge)
217217
if err != nil {
218218
return err
219219
}
@@ -227,7 +227,7 @@ func (c *openflowManager) updateBridgeFlowCache(subnets []*net.IPNet, extraIPs [
227227
c.externalGatewayBridge.Lock()
228228
defer c.externalGatewayBridge.Unlock()
229229
c.updateExBridgeFlowCacheEntry("NORMAL", []string{fmt.Sprintf("table=0,priority=0,actions=%s\n", util.NormalAction)})
230-
exGWBridgeDftFlows, err := commonFlows(subnets, c.externalGatewayBridge)
230+
exGWBridgeDftFlows, err := commonFlows(subnets, hostSubnets, c.externalGatewayBridge)
231231
if err != nil {
232232
return err
233233
}

0 commit comments

Comments
 (0)