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
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cni/network/network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

})

hnsv2Policy, _ := json.Marshal(&hnsv2.EndpointPolicy{
Expand Down
15 changes: 14 additions & 1 deletion cni/network/network_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,21 @@ func TestSetPoliciesFromNwCfg(t *testing.T) {
},
},
},
{
name: "Runtime hostPort mapping polices",
nwCfg: cni.NetworkConfig{
RuntimeConfig: cni.RuntimeConfig{
PortMappings: []cni.PortMapping{
{
Protocol: "tcp",
HostPort: 44000,
ContainerPort: 80,
},
},
},
},
}
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand Down