fix: [CNI] NAT hostPort mapping for HNSv2 (#1922)
* NAT update * NAT update * Cleaning up and unit test * Fix Lint * Fix Lint * Fix Lint - Addr. comments --------- Co-authored-by: jpayne3506 <johnpayne@microsoft.com>
This commit is contained in:
Родитель
2df9d27b73
Коммит
4f76b19c21
|
@ -252,11 +252,14 @@ func getPoliciesFromRuntimeCfg(nwCfg *cni.NetworkConfig) []policy.Policy {
|
|||
protocol = policy.ProtocolUdp
|
||||
}
|
||||
|
||||
// To support hostport policy mapping
|
||||
// uint32 NatFlagsLocalRoutedVip = 1
|
||||
rawPolicy, _ := json.Marshal(&hnsv2.PortMappingPolicySetting{
|
||||
ExternalPort: uint16(mapping.HostPort),
|
||||
InternalPort: uint16(mapping.ContainerPort),
|
||||
VIP: mapping.HostIp,
|
||||
Protocol: protocol,
|
||||
Flags: hnsv2.NatFlagsLocalRoutedVip,
|
||||
})
|
||||
|
||||
hnsv2Policy, _ := json.Marshal(&hnsv2.EndpointPolicy{
|
||||
|
|
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче