Skip to content

Commit 364c168

Browse files
authored
fix: Using Node IP as the primary IP allowing the use of all the IPs in the subnet for pods in Vnet Scale Mode and added the fix for Vnet Scale Cillium (#2660)
* Testing with NodeIP as the PrimaryIP * Updated the secondary IP configs to not delete the first IP from Primary IP field as we will now use the Node IP for all functions related to Primary IP * Fixed the invalid UT to test out and validate the use of Node IP for SNAT and including the primary IP for use in secondary IP blocks * Combined the common code for Prefix Length * Updated to set the Host Primary IP for both Overlay and Vnet Scale as it is primarily only being used to setup IMDS SNAT Rules * Fixing the valid overlay UT to include the Host Primary IP
1 parent 7c4e48c commit 364c168

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

cns/kubecontroller/nodenetworkconfig/conversion.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,20 @@ func CreateNCRequestFromStaticNC(nc v1alpha.NetworkContainer) (*cns.CreateNetwor
8787
if err != nil {
8888
return nil, errors.Wrapf(err, "invalid SubnetAddressSpace %s", nc.SubnetAddressSpace)
8989
}
90+
9091
subnet := cns.IPSubnet{
91-
IPAddress: primaryPrefix.Addr().String(),
9292
PrefixLength: uint8(subnetPrefix.Bits()),
9393
}
94+
if nc.Type == v1alpha.VNETBlock {
95+
subnet.IPAddress = nc.NodeIP
96+
} else {
97+
subnet.IPAddress = primaryPrefix.Addr().String()
98+
}
9499

95100
req, err := createNCRequestFromStaticNCHelper(nc, primaryPrefix, subnet)
96101
if err != nil {
97102
return nil, errors.Wrapf(err, "error while creating NC request from static NC")
98103
}
104+
99105
return req, err
100106
}

cns/kubecontroller/nodenetworkconfig/conversion_linux.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
2727

2828
// Add IPs from CIDR block to the secondary IPConfigs
2929
if nc.Type == v1alpha.VNETBlock {
30-
// Delete primary IP reserved for Primary IP for NC
31-
delete(secondaryIPConfigs, primaryIPPrefix.Addr().String())
3230

3331
for _, ipAssignment := range nc.IPAssignments {
3432
cidrPrefix, err := netip.ParsePrefix(ipAssignment.IP)
@@ -48,6 +46,7 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
4846
}
4947

5048
return &cns.CreateNetworkContainerRequest{
49+
HostPrimaryIP: nc.NodeIP,
5150
SecondaryIPConfigs: secondaryIPConfigs,
5251
NetworkContainerid: nc.ID,
5352
NetworkContainerType: cns.Docker,

cns/kubecontroller/nodenetworkconfig/conversion_linux_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import (
77
)
88

99
var validOverlayRequest = &cns.CreateNetworkContainerRequest{
10-
Version: strconv.FormatInt(0, 10),
10+
HostPrimaryIP: validOverlayNC.NodeIP,
11+
Version: strconv.FormatInt(0, 10),
1112
IPConfiguration: cns.IPConfiguration{
1213
IPSubnet: cns.IPSubnet{
1314
PrefixLength: uint8(subnetPrefixLen),
@@ -37,18 +38,23 @@ var validOverlayRequest = &cns.CreateNetworkContainerRequest{
3738
}
3839

3940
var validVNETBlockRequest = &cns.CreateNetworkContainerRequest{
40-
Version: strconv.FormatInt(version, 10),
41+
Version: strconv.FormatInt(version, 10),
42+
HostPrimaryIP: vnetBlockNodeIP,
4143
IPConfiguration: cns.IPConfiguration{
4244
GatewayIPAddress: vnetBlockDefaultGateway,
4345
IPSubnet: cns.IPSubnet{
4446
PrefixLength: uint8(vnetBlockSubnetPrefixLen),
45-
IPAddress: vnetBlockPrimaryIP,
47+
IPAddress: vnetBlockNodeIP,
4648
},
4749
},
4850
NetworkContainerid: ncID,
4951
NetworkContainerType: cns.Docker,
5052
// Ignore first IP in first CIDR Block, i.e. 10.224.0.4
5153
SecondaryIPConfigs: map[string]cns.SecondaryIPConfig{
54+
"10.224.0.4": {
55+
IPAddress: "10.224.0.4",
56+
NCVersion: version,
57+
},
5258
"10.224.0.5": {
5359
IPAddress: "10.224.0.5",
5460
NCVersion: version,

0 commit comments

Comments
 (0)