Skip to content

Commit 1d9b4cf

Browse files
committed
[pod SNAT] reuse code around pod SNAT creation.
Remove unused "match" parameter from addOrUpdatePodSNATOps. Rename logicalRouter/router to gwRouter. Signed-off-by: Nadia Pinaeva <[email protected]>
1 parent 4834e3d commit 1d9b4cf

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

go-controller/pkg/ovn/egressgw.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -649,30 +649,27 @@ func deletePodSNATOps(nbClient libovsdbclient.Client, ops []ovsdb.Operation, gwR
649649
// addOrUpdatePodSNAT adds or updates per pod SNAT rules towards the nodeIP that are applied to the GR where the pod resides
650650
// used when disableSNATMultipleGWs=true
651651
func addOrUpdatePodSNAT(nbClient libovsdbclient.Client, gwRouterName string, extIPs, podIfAddrs []*net.IPNet) error {
652-
nats, err := buildPodSNAT(extIPs, podIfAddrs, "")
652+
ops, err := addOrUpdatePodSNATOps(nbClient, gwRouterName, extIPs, podIfAddrs, nil)
653653
if err != nil {
654654
return err
655655
}
656-
logicalRouter := nbdb.LogicalRouter{
657-
Name: gwRouterName,
658-
}
659-
if err := libovsdbops.CreateOrUpdateNATs(nbClient, &logicalRouter, nats...); err != nil {
660-
return fmt.Errorf("failed to update SNAT for pods of router %s: %v", logicalRouter.Name, err)
656+
if _, err = libovsdbops.TransactAndCheck(nbClient, ops); err != nil {
657+
return fmt.Errorf("failed to update SNAT for pods of router %s: %v", gwRouterName, err)
661658
}
662659
return nil
663660
}
664661

665662
// addOrUpdatePodSNATOps returns the operation that adds or updates per pod SNAT rules towards the nodeIP that are
666663
// applied to the GR where the pod resides
667664
// used when disableSNATMultipleGWs=true
668-
func addOrUpdatePodSNATOps(nbClient libovsdbclient.Client, gwRouterName string, extIPs, podIfAddrs []*net.IPNet, match string, ops []ovsdb.Operation) ([]ovsdb.Operation, error) {
669-
router := &nbdb.LogicalRouter{Name: gwRouterName}
670-
nats, err := buildPodSNAT(extIPs, podIfAddrs, match)
665+
func addOrUpdatePodSNATOps(nbClient libovsdbclient.Client, gwRouterName string, extIPs, podIfAddrs []*net.IPNet, ops []ovsdb.Operation) ([]ovsdb.Operation, error) {
666+
gwRouter := &nbdb.LogicalRouter{Name: gwRouterName}
667+
nats, err := buildPodSNAT(extIPs, podIfAddrs, "")
671668
if err != nil {
672669
return nil, err
673670
}
674-
if ops, err = libovsdbops.CreateOrUpdateNATsOps(nbClient, ops, router, nats...); err != nil {
675-
return nil, fmt.Errorf("failed to update SNAT for pods of router: %s, error: %v", gwRouterName, err)
671+
if ops, err = libovsdbops.CreateOrUpdateNATsOps(nbClient, ops, gwRouter, nats...); err != nil {
672+
return nil, fmt.Errorf("failed to create ops to update SNAT for pods of router: %s, error: %v", gwRouterName, err)
676673
}
677674
return ops, nil
678675
}

go-controller/pkg/ovn/egressip.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,7 +2594,7 @@ func (e *EgressIPController) addExternalGWPodSNATOps(ni util.NetInfo, ops []ovsd
25942594
if err != nil {
25952595
return nil, err
25962596
}
2597-
ops, err = addOrUpdatePodSNATOps(e.nbClient, ni.GetNetworkScopedGWRouterName(pod.Spec.NodeName), extIPs, podIPs, "", ops)
2597+
ops, err = addOrUpdatePodSNATOps(e.nbClient, ni.GetNetworkScopedGWRouterName(pod.Spec.NodeName), extIPs, podIPs, ops)
25982598
if err != nil {
25992599
return nil, err
26002600
}
@@ -3639,12 +3639,12 @@ func (e *EgressIPController) createNATRuleOps(ni util.NetInfo, ops []ovsdb.Opera
36393639
nats = append(nats, nat)
36403640
}
36413641
}
3642-
router := &nbdb.LogicalRouter{
3642+
gwRouter := &nbdb.LogicalRouter{
36433643
Name: ni.GetNetworkScopedGWRouterName(status.Node),
36443644
}
3645-
ops, err = libovsdbops.CreateOrUpdateNATsOps(e.nbClient, ops, router, nats...)
3645+
ops, err = libovsdbops.CreateOrUpdateNATsOps(e.nbClient, ops, gwRouter, nats...)
36463646
if err != nil {
3647-
return nil, fmt.Errorf("unable to create snat rules, for router: %s, error: %v", router.Name, err)
3647+
return nil, fmt.Errorf("unable to create snat rules, for router: %s, error: %v", gwRouter.Name, err)
36483648
}
36493649
return ops, nil
36503650
}

go-controller/pkg/ovn/pods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (oc *DefaultNetworkController) addLogicalPort(pod *corev1.Pod) (err error)
315315
// namespace annotations to go through external egress router
316316
if extIPs, err := getExternalIPsGR(oc.watchFactory, pod.Spec.NodeName); err != nil {
317317
return err
318-
} else if ops, err = addOrUpdatePodSNATOps(oc.nbClient, oc.GetNetworkScopedGWRouterName(pod.Spec.NodeName), extIPs, podAnnotation.IPs, "", ops); err != nil {
318+
} else if ops, err = addOrUpdatePodSNATOps(oc.nbClient, oc.GetNetworkScopedGWRouterName(pod.Spec.NodeName), extIPs, podAnnotation.IPs, ops); err != nil {
319319
return err
320320
}
321321
}

go-controller/pkg/ovn/secondary_layer2_network_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,21 +757,21 @@ func (oc *SecondaryLayer2NetworkController) deleteNodeEvent(node *corev1.Node) e
757757
// externalIP = "169.254.0.12"; which is the masqueradeIP for this L2 UDN
758758
// so all in all we want to condionally SNAT all packets that are coming from pods hosted on this node,
759759
// which are leaving via UDN's mpX interface to the UDN's masqueradeIP.
760-
func (oc *SecondaryLayer2NetworkController) addUDNClusterSubnetEgressSNAT(localPodSubnets []*net.IPNet, routerName string) error {
761-
outputPort := types.GWRouterToJoinSwitchPrefix + routerName
760+
func (oc *SecondaryLayer2NetworkController) addUDNClusterSubnetEgressSNAT(localPodSubnets []*net.IPNet, gwRouterName string) error {
761+
outputPort := types.GWRouterToJoinSwitchPrefix + gwRouterName
762762
nats, err := oc.buildUDNEgressSNAT(localPodSubnets, outputPort)
763763
if err != nil {
764764
return err
765765
}
766766
if len(nats) == 0 {
767767
return nil // nothing to do
768768
}
769-
router := &nbdb.LogicalRouter{
770-
Name: routerName,
769+
gwRouter := &nbdb.LogicalRouter{
770+
Name: gwRouterName,
771771
}
772-
if err := libovsdbops.CreateOrUpdateNATs(oc.nbClient, router, nats...); err != nil {
772+
if err := libovsdbops.CreateOrUpdateNATs(oc.nbClient, gwRouter, nats...); err != nil {
773773
return fmt.Errorf("failed to update SNAT for cluster on router: %q for network %q, error: %w",
774-
routerName, oc.GetNetworkName(), err)
774+
gwRouterName, oc.GetNetworkName(), err)
775775
}
776776
return nil
777777
}

0 commit comments

Comments
 (0)