Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [CNI] NAT hostPort mapping for HNSv2 #1922

Merged
merged 9 commits into from
May 1, 2023

Conversation

jpayne3506
Copy link
Contributor

@jpayne3506 jpayne3506 commented Apr 20, 2023

Reason for Change:

Enables the use of hostport mapping with HNSv2 by setting a flag in PortMappingPolicySetting. This reflects in hnsendpoint by showing a new policy for the route which is created by the OS.

Issue Fixed:

Fixes #1863

Requirements:

Notes:
You can confirm the policy and route through the node by using
get-hnsendpoint | ? IPAddress -Like "node ip" | Convertto-json -d 16
for exclusively policy use
get-hnsendpoint | ? IPAddress -Like "node ip" | Select Policies | Convertto-json -d 16

Internal port / containerPort must match an already listening port on the pod. If not using the default service port 80, user will need to create and open port.

@@ -257,6 +257,7 @@ func getPoliciesFromRuntimeCfg(nwCfg *cni.NetworkConfig) []policy.Policy {
InternalPort: uint16(mapping.ContainerPort),
VIP: mapping.HostIp,
Protocol: protocol,
Flags: hnsv2.NatFlagsLocalRoutedVip, // iota'd, NatFlagsLocalRoutedVip = 1, uint32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a constant value ? What does this mean ? ( Just curious)

Copy link
Contributor Author

@jpayne3506 jpayne3506 Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a constant value set here https://github.com/microsoft/hcsshim/blob/298b31d151ab799c1d7686f8ee9eec1cb4213926/hcn/hcnpolicy.go#L82 .
Was trying to match other code snippets in cni where they match the TCP/UDP to constant values as well.

I could remove the iota'd comment and change it to // uint32 NatFlagsLocalRoutedVip = 1 if that makes it more clear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment above this change saying "its to support hostport policy mapping"

@jpayne3506 jpayne3506 requested a review from daschott April 20, 2023 21:43
@tamilmani1989 tamilmani1989 added cni Related to CNI. windows labels Apr 20, 2023
vipul-21
vipul-21 previously approved these changes Apr 20, 2023
Copy link

@daschott daschott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jpayne3506 jpayne3506 enabled auto-merge (squash) April 20, 2023 23:32
@jpayne3506 jpayne3506 merged commit 4f76b19 into Azure:master May 1, 2023
@jpayne3506 jpayne3506 deleted the portmapping branch August 9, 2023 23:26
rbtr pushed a commit that referenced this pull request Sep 8, 2023
* NAT update

* NAT update

* Cleaning up and unit test

* Fix Lint

* Fix Lint

* Fix Lint - Addr. comments

---------

Co-authored-by: jpayne3506 <[email protected]>
jpayne3506 added a commit that referenced this pull request Sep 11, 2023
* NAT update

* NAT update

* Cleaning up and unit test

* Fix Lint

* Fix Lint

* Fix Lint - Addr. comments

---------

Co-authored-by: jpayne3506 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cni Related to CNI. windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows Nodes cannot access pod's local PortMappings
5 participants