Skip to content

Commit

Permalink
Merge pull request #4718 from tssurya/wrong-udn-lrsr-and-lrps
Browse files Browse the repository at this point in the history
UDN: L3: Use nodesubnet annotations for L3; not clustersubnet from NAD
  • Loading branch information
trozet committed Sep 13, 2024
2 parents 0a84913 + 961b5df commit a83b6be
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 86 deletions.
22 changes: 11 additions & 11 deletions go-controller/pkg/ovn/multihoming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/kube"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/testing"
ovntest "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/testing"
libovsdbtest "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/testing/libovsdb"
ovntypes "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/util"
Expand Down Expand Up @@ -122,14 +123,13 @@ func (em *secondaryNetworkExpectationMachine) expectedLogicalSwitchesAndPorts(is
if !ok {
continue
}

subnets := ocInfo.bnc.Subnets()
subnets := podInfo.nodeSubnet
var (
subnet config.CIDRNetworkEntry
subnet *net.IPNet
hasSubnets bool
)
if len(subnets) > 0 {
subnet = subnets[0]
subnet = ovntest.MustParseIPNet(subnets)
hasSubnets = true
}

Expand All @@ -154,7 +154,7 @@ func (em *secondaryNetworkExpectationMachine) expectedLogicalSwitchesAndPorts(is
switch ocInfo.bnc.TopologyType() {
case ovntypes.Layer3Topology:
switchName = ocInfo.bnc.GetNetworkScopedName(pod.nodeName)
managementIP := managementPortIP(subnet.CIDR)
managementIP := managementPortIP(subnet)

switchToRouterPortName := "stor-" + switchName
switchToRouterPortUUID := switchToRouterPortName + "-UUID"
Expand All @@ -176,7 +176,7 @@ func (em *secondaryNetworkExpectationMachine) expectedLogicalSwitchesAndPorts(is
}
case ovntypes.Layer2Topology:
switchName = ocInfo.bnc.GetNetworkScopedName(ovntypes.OVNLayer2Switch)
managementIP := managementPortIP(subnet.CIDR)
managementIP := managementPortIP(subnet)

if em.gatewayConfig != nil {
// there are multiple mgmt ports in the cluster, thus the ports must be scoped with the node name
Expand Down Expand Up @@ -222,8 +222,8 @@ func (em *secondaryNetworkExpectationMachine) expectedLogicalSwitchesAndPorts(is
var otherConfig map[string]string
if hasSubnets {
otherConfig = map[string]string{
"exclude_ips": managementPortIP(subnet.CIDR).String(),
"subnet": subnet.CIDR.String(),
"exclude_ips": managementPortIP(subnet).String(),
"subnet": subnet.String(),
}
}

Expand All @@ -247,8 +247,8 @@ func (em *secondaryNetworkExpectationMachine) expectedLogicalSwitchesAndPorts(is
})
if em.gatewayConfig != nil {
if ocInfo.bnc.TopologyType() == ovntypes.Layer3Topology {
data = append(data, expectedGWEntities(pod.nodeName, ocInfo.bnc, *em.gatewayConfig)...)
data = append(data, expectedLayer3EgressEntities(ocInfo.bnc, *em.gatewayConfig)...)
data = append(data, expectedGWEntities(pod.nodeName, subnets, ocInfo.bnc, *em.gatewayConfig)...)
data = append(data, expectedLayer3EgressEntities(ocInfo.bnc, *em.gatewayConfig, subnet)...)
} else {
data = append(data, expectedLayer2EgressEntities(ocInfo.bnc, *em.gatewayConfig, pod.nodeName)...)
}
Expand Down Expand Up @@ -464,7 +464,7 @@ func dummyOVNPodNetworkAnnotationForNetwork(netConfig secondaryNetInfo, tunnelID
gateways []string
ips []string
)
for _, subnetStr := range strings.Split(netConfig.subnets, ",") {
for _, subnetStr := range strings.Split(netConfig.clustersubnets, ",") {
subnet := testing.MustParseIPNet(subnetStr)
ips = append(ips, GetWorkloadSecondaryNetworkDummyIP(subnet).String())
gateways = append(gateways, util.GetNodeGatewayIfAddr(subnet).IP.String())
Expand Down
20 changes: 10 additions & 10 deletions go-controller/pkg/ovn/secondary_layer2_network_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ var _ = Describe("OVN Multi-Homed pod operations for layer2 network", func() {

func dummySecondaryLayer2UserDefinedNetwork(subnets string) secondaryNetInfo {
return secondaryNetInfo{
netName: secondaryNetworkName,
nadName: namespacedName(ns, nadName),
topology: ovntypes.Layer2Topology,
subnets: subnets,
netName: secondaryNetworkName,
nadName: namespacedName(ns, nadName),
topology: ovntypes.Layer2Topology,
clustersubnets: subnets,
}
}

Expand Down Expand Up @@ -329,7 +329,7 @@ func dummyL2TestPod(nsName string, info secondaryNetInfo) testPod {
pod.addNetwork(
info.netName,
info.nadName,
info.subnets,
info.clustersubnets,
"",
"100.200.0.1",
"100.200.0.3/16",
Expand All @@ -353,7 +353,7 @@ func dummyL2TestPod(nsName string, info secondaryNetInfo) testPod {
pod.addNetwork(
info.netName,
info.nadName,
info.subnets,
info.clustersubnets,
"",
"",
"100.200.0.1/16",
Expand Down Expand Up @@ -459,10 +459,10 @@ func ipv4DefaultRoute() *net.IPNet {

func dummyLayer2SecondaryUserDefinedNetwork(subnets string) secondaryNetInfo {
return secondaryNetInfo{
netName: secondaryNetworkName,
nadName: namespacedName(ns, nadName),
topology: ovntypes.Layer2Topology,
subnets: subnets,
netName: secondaryNetworkName,
nadName: namespacedName(ns, nadName),
topology: ovntypes.Layer2Topology,
clustersubnets: subnets,
}
}

Expand Down
36 changes: 22 additions & 14 deletions go-controller/pkg/ovn/secondary_layer3_network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ func (oc *SecondaryLayer3NetworkController) addUpdateLocalNodeEvent(node *kapi.N
gwConfig.config,
gwConfig.hostSubnets,
gwConfig.hostAddrs,
gwConfig.hostSubnets,
gwConfig.clusterSubnets,
gwConfig.gwLRPIPs,
oc.SCTPSupport,
oc.ovnClusterLRPToJoinIfAddrs,
Expand Down Expand Up @@ -858,11 +858,12 @@ func (oc *SecondaryLayer3NetworkController) gatherJoinSwitchIPs() error {
}

type SecondaryL3GatewayConfig struct {
config *util.L3GatewayConfig
hostSubnets []*net.IPNet
gwLRPIPs []*net.IPNet
hostAddrs []string
externalIPs []net.IP
config *util.L3GatewayConfig
hostSubnets []*net.IPNet
clusterSubnets []*net.IPNet
gwLRPIPs []*net.IPNet
hostAddrs []string
externalIPs []net.IP
}

func (oc *SecondaryLayer3NetworkController) nodeGatewayConfig(node *kapi.Node) (*SecondaryL3GatewayConfig, error) {
Expand Down Expand Up @@ -898,10 +899,16 @@ func (oc *SecondaryLayer3NetworkController) nodeGatewayConfig(node *kapi.Node) (
hostAddrs = append(hostAddrs, externalIP.String())
}

// Use the host subnets present in the network attachment definition.
hostSubnets := make([]*net.IPNet, 0, len(oc.Subnets()))
// Use the cluster subnets present in the network attachment definition.
clusterSubnets := make([]*net.IPNet, 0, len(oc.Subnets()))
for _, subnet := range oc.Subnets() {
hostSubnets = append(hostSubnets, subnet.CIDR)
clusterSubnets = append(clusterSubnets, subnet.CIDR)
}

// Fetch the host subnets present in the node annotation for this network
hostSubnets, err := util.ParseNodeHostSubnetAnnotation(node, oc.GetNetworkName())
if err != nil {
return nil, fmt.Errorf("failed to get node %q subnet annotation for network %q: %v", node.Name, oc.GetNetworkName(), err)
}

gwLRPIPs, err := util.ParseNodeGatewayRouterJoinAddrs(node, oc.GetNetworkName())
Expand All @@ -913,11 +920,12 @@ func (oc *SecondaryLayer3NetworkController) nodeGatewayConfig(node *kapi.Node) (
l3GatewayConfig.InterfaceID = oc.GetNetworkScopedExtPortName(l3GatewayConfig.BridgeID, node.Name)

return &SecondaryL3GatewayConfig{
config: l3GatewayConfig,
hostSubnets: hostSubnets,
gwLRPIPs: gwLRPIPs,
hostAddrs: hostAddrs,
externalIPs: externalIPs,
config: l3GatewayConfig,
hostSubnets: hostSubnets,
clusterSubnets: clusterSubnets,
gwLRPIPs: gwLRPIPs,
hostAddrs: hostAddrs,
externalIPs: externalIPs,
}, nil
}

Expand Down
Loading

0 comments on commit a83b6be

Please sign in to comment.