Skip to content

portmap: make DNAT entries last-write-wins - #1267

Open
hemeimei wants to merge 1 commit into
containernetworking:mainfrom
hemeimei:portmap-last-write-wins
Open

portmap: make DNAT entries last-write-wins#1267
hemeimei wants to merge 1 commit into
containernetworking:mainfrom
hemeimei:portmap-last-write-wins

Conversation

@hemeimei

Copy link
Copy Markdown

The iptables portmap backend currently appends each per-container DNAT
entry to CNI-HOSTPORT-DNAT. If a container is recreated with the same
HostPort before the old mapping is fully removed, the older entry can
continue to match first.

Make genDnatChain set prependEntry=true so newly-created per-container
DNAT entries are inserted before older entries in CNI-HOSTPORT-DNAT,
giving hostport mappings last-write-wins semantics.

This does not revert the service-ordering fix from #269. That fix was
about not prepending CNI-HOSTPORT-DNAT into nat/PREROUTING or nat/OUTPUT,
where it could take precedence over kube-proxy's KUBE-SERVICES rules.

This change only affects ordering inside CNI-HOSTPORT-DNAT. The top-level
CNI-HOSTPORT-DNAT jump remains appended to PREROUTING/OUTPUT, while
kube-proxy ensures KUBE-SERVICES is installed in those top-level NAT
chains. Therefore Kubernetes Service and NodePort rules continue to run
before CNI hostport dispatch.

Validation:

  • gofmt
  • git diff --check
  • focused portmap chain-generation tests with Go 1.25

@hemeimei
hemeimei force-pushed the portmap-last-write-wins branch from 19e8631 to 14b8a58 Compare June 24, 2026 13:42
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: hemeimei <hemeimei@baidu.com>
@hemeimei
hemeimei force-pushed the portmap-last-write-wins branch from 14b8a58 to e1a6104 Compare July 13, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant