diff --git a/cns/kubecontroller/nodenetworkconfig/conversion.go b/cns/kubecontroller/nodenetworkconfig/conversion.go index 8f6346ce52..01bda6780e 100644 --- a/cns/kubecontroller/nodenetworkconfig/conversion.go +++ b/cns/kubecontroller/nodenetworkconfig/conversion.go @@ -87,14 +87,20 @@ func CreateNCRequestFromStaticNC(nc v1alpha.NetworkContainer) (*cns.CreateNetwor if err != nil { return nil, errors.Wrapf(err, "invalid SubnetAddressSpace %s", nc.SubnetAddressSpace) } + subnet := cns.IPSubnet{ - IPAddress: primaryPrefix.Addr().String(), PrefixLength: uint8(subnetPrefix.Bits()), } + if nc.Type == v1alpha.VNETBlock { + subnet.IPAddress = nc.NodeIP + } else { + subnet.IPAddress = primaryPrefix.Addr().String() + } req, err := createNCRequestFromStaticNCHelper(nc, primaryPrefix, subnet) if err != nil { return nil, errors.Wrapf(err, "error while creating NC request from static NC") } + return req, err } diff --git a/cns/kubecontroller/nodenetworkconfig/conversion_linux.go b/cns/kubecontroller/nodenetworkconfig/conversion_linux.go index a22dbd4bd8..c89d41646b 100644 --- a/cns/kubecontroller/nodenetworkconfig/conversion_linux.go +++ b/cns/kubecontroller/nodenetworkconfig/conversion_linux.go @@ -27,8 +27,6 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre // Add IPs from CIDR block to the secondary IPConfigs if nc.Type == v1alpha.VNETBlock { - // Delete primary IP reserved for Primary IP for NC - delete(secondaryIPConfigs, primaryIPPrefix.Addr().String()) for _, ipAssignment := range nc.IPAssignments { cidrPrefix, err := netip.ParsePrefix(ipAssignment.IP) @@ -48,6 +46,7 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre } return &cns.CreateNetworkContainerRequest{ + HostPrimaryIP: nc.NodeIP, SecondaryIPConfigs: secondaryIPConfigs, NetworkContainerid: nc.ID, NetworkContainerType: cns.Docker, diff --git a/cns/kubecontroller/nodenetworkconfig/conversion_linux_test.go b/cns/kubecontroller/nodenetworkconfig/conversion_linux_test.go index b30b53bb69..440cb691c4 100644 --- a/cns/kubecontroller/nodenetworkconfig/conversion_linux_test.go +++ b/cns/kubecontroller/nodenetworkconfig/conversion_linux_test.go @@ -7,7 +7,8 @@ import ( ) var validOverlayRequest = &cns.CreateNetworkContainerRequest{ - Version: strconv.FormatInt(0, 10), + HostPrimaryIP: validOverlayNC.NodeIP, + Version: strconv.FormatInt(0, 10), IPConfiguration: cns.IPConfiguration{ IPSubnet: cns.IPSubnet{ PrefixLength: uint8(subnetPrefixLen), @@ -37,18 +38,23 @@ var validOverlayRequest = &cns.CreateNetworkContainerRequest{ } var validVNETBlockRequest = &cns.CreateNetworkContainerRequest{ - Version: strconv.FormatInt(version, 10), + Version: strconv.FormatInt(version, 10), + HostPrimaryIP: vnetBlockNodeIP, IPConfiguration: cns.IPConfiguration{ GatewayIPAddress: vnetBlockDefaultGateway, IPSubnet: cns.IPSubnet{ PrefixLength: uint8(vnetBlockSubnetPrefixLen), - IPAddress: vnetBlockPrimaryIP, + IPAddress: vnetBlockNodeIP, }, }, NetworkContainerid: ncID, NetworkContainerType: cns.Docker, // Ignore first IP in first CIDR Block, i.e. 10.224.0.4 SecondaryIPConfigs: map[string]cns.SecondaryIPConfig{ + "10.224.0.4": { + IPAddress: "10.224.0.4", + NCVersion: version, + }, "10.224.0.5": { IPAddress: "10.224.0.5", NCVersion: version,