From 166310edf48d3295ad0b445172b325fdd440f314 Mon Sep 17 00:00:00 2001 From: Max Neverov Date: Mon, 14 Aug 2023 19:09:24 +0200 Subject: [PATCH 1/2] Populate port mapping name to make endpoint port mapping work. --- backends/iptables/iptables.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/backends/iptables/iptables.go b/backends/iptables/iptables.go index a7ea10539..a829a224b 100644 --- a/backends/iptables/iptables.go +++ b/backends/iptables/iptables.go @@ -648,6 +648,7 @@ func (t *iptables) createEndpointsChain(svcInfo *serviceInfo, allEndpoints *endp } targetPort := epInfo.PortMapping(&localv1.PortMapping{ + Name: svcInfo.portName, TargetPortName: svcInfo.targetPortName, TargetPort: int32(svcInfo.targetPort), }) @@ -747,13 +748,6 @@ func (t *iptables) writeDNATRules(svcInfo *serviceInfo, svcName types.Namespaced } targetPort := t.getTargetPort(svcInfo, endpointPortMap, *epIP) - - // this seems very sly to me. Doing this because there were 2 entries being added - // one with the right target port and one with zero - // write better logic or verify how baseServiceInfo & endpointPortMap are populated - if targetPort == 0 { - continue - } // DNAT to final destination. args = append(args, "-m", protocol, "-p", protocol, "-j", "DNAT", "--to-destination", net.JoinHostPort(*epIP, strconv.Itoa(targetPort))) t.natRules.Write(args) From 46a10bd6448573d46f853a9f2b1e64931dc0c70a Mon Sep 17 00:00:00 2001 From: Max Neverov Date: Mon, 22 Jan 2024 15:43:02 +0100 Subject: [PATCH 2/2] fmt --- backends/iptables/iptables.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backends/iptables/iptables.go b/backends/iptables/iptables.go index 51221bb7f..20d55130f 100644 --- a/backends/iptables/iptables.go +++ b/backends/iptables/iptables.go @@ -752,8 +752,7 @@ func (t *iptables) writeDNATRules(svcInfo *serviceInfo, svcName types.Namespaced } targetPort := t.getTargetPort(svcInfo, endpointPortMap, *epIP) - - // DNAT to final destination. + // DNAT to final destination. args = append(args, "-m", protocol, "-p", protocol, "-j", "DNAT", "--to-destination", net.JoinHostPort(*epIP, strconv.Itoa(targetPort))) t.natRules.Write(args) }