Skip to content

Commit c191d40

Browse files
feat: use host gw, subnet when in nodesubnet mode, rather than nc gw, subnet
1 parent 7bd2f6d commit c191d40

File tree

4 files changed

+70
-20
lines changed

4 files changed

+70
-20
lines changed

cni/network/invoker_cns.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
205205
}
206206
}
207207

208-
overlayMode := (invoker.ipamMode == util.V4Overlay) || (invoker.ipamMode == util.DualStackOverlay) || (invoker.ipamMode == util.Overlay)
209-
if err := configureDefaultAddResult(&info, &addConfig, &addResult, overlayMode, key); err != nil {
208+
if err := configureDefaultAddResult(&info, &addConfig, &addResult, key); err != nil {
210209
return IPAMAddResult{}, err
211210
}
212211
default:
@@ -379,32 +378,48 @@ func getRoutes(cnsRoutes []cns.Route, skipDefaultRoutes bool) ([]network.RouteIn
379378
return routes, nil
380379
}
381380

382-
func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, addResult *IPAMAddResult, overlayMode bool, key string) error {
381+
func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, addResult *IPAMAddResult, key string) error {
382+
ipamMode := util.IpamMode(addConfig.nwCfg.IPAM.Mode)
383383
// set the NC Primary IP in options
384384
// SNATIPKey is not set for ipv6
385-
if net.ParseIP(info.ncPrimaryIP).To4() != nil {
385+
if ipamMode != util.Nodesubnet && net.ParseIP(info.ncPrimaryIP).To4() != nil {
386386
addConfig.options[network.SNATIPKey] = info.ncPrimaryIP
387387
}
388388

389+
if ipamMode == util.Nodesubnet {
390+
info.ncGatewayIPAddress = info.hostGateway
391+
info.ncPrimaryIP = info.hostPrimaryIP
392+
_, ncIPNet, err := net.ParseCIDR(info.hostSubnet)
393+
if err != nil {
394+
return errors.Wrap(err, "Unable to parse hostSubnet from response: "+info.hostSubnet+" with err %w")
395+
}
396+
397+
maskLen, _ := ncIPNet.Mask.Size()
398+
info.ncSubnetPrefix = uint8(maskLen)
399+
}
400+
389401
ip, ncIPNet, err := net.ParseCIDR(info.podIPAddress + "/" + fmt.Sprint(info.ncSubnetPrefix))
402+
390403
if ip == nil || err != nil {
391404
return errors.Wrap(err, "Unable to parse IP from response: "+info.podIPAddress+" with err %w")
392405
}
393406

394-
ncgw := net.ParseIP(info.ncGatewayIPAddress)
395-
if ncgw == nil {
396-
// TODO: Remove v4overlay and dualstackoverlay options, after 'overlay' rolls out in AKS-RP
397-
if !overlayMode {
407+
podGateway := net.ParseIP(info.ncGatewayIPAddress)
408+
// TODO: Remove v4overlay and dualstackoverlay options, after 'overlay' rolls out in AKS-RP
409+
isPodSubnetMode := (ipamMode != util.V4Overlay) && (ipamMode != util.DualStackOverlay) && (ipamMode != util.Overlay) && (ipamMode != util.Nodesubnet)
410+
411+
if podGateway == nil {
412+
if isPodSubnetMode {
398413
return errors.Wrap(errInvalidArgs, "%w: Gateway address "+info.ncGatewayIPAddress+" from response is invalid")
399414
}
400415

401416
if net.ParseIP(info.podIPAddress).To4() != nil { //nolint:gocritic
402-
ncgw, err = getOverlayGateway(ncIPNet)
417+
podGateway, err = getOverlayGateway(ncIPNet)
403418
if err != nil {
404419
return err
405420
}
406421
} else if net.ParseIP(info.podIPAddress).To16() != nil {
407-
ncgw = net.ParseIP(overlayGatewayV6IP)
422+
podGateway = net.ParseIP(overlayGatewayV6IP)
408423
} else {
409424
return errors.Wrap(err, "No podIPAddress is found: %w")
410425
}
@@ -430,7 +445,7 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
430445
IP: ip,
431446
Mask: ncIPNet.Mask,
432447
},
433-
Gateway: ncgw,
448+
Gateway: podGateway,
434449
})
435450

436451
routes, getRoutesErr := getRoutes(info.routes, info.skipDefaultRoutes)
@@ -444,7 +459,7 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
444459
} else { // add default routes if none are provided
445460
resRoute = append(resRoute, network.RouteInfo{
446461
Dst: defaultRouteDstPrefix,
447-
Gw: ncgw,
462+
Gw: podGateway,
448463
})
449464
}
450465

@@ -461,9 +476,8 @@ func configureDefaultAddResult(info *IPResultInfo, addConfig *IPAMAddConfig, add
461476
}
462477

463478
// set subnet prefix for host vm
464-
// setHostOptions will execute if IPAM mode is not v4 overlay and not dualStackOverlay mode
465-
// TODO: Remove v4overlay and dualstackoverlay options, after 'overlay' rolls out in AKS-RP
466-
if !overlayMode {
479+
// setHostOptions will execute if IPAM mode is podsubnet
480+
if isPodSubnetMode {
467481
if err := setHostOptions(ncIPNet, addConfig.options, info); err != nil {
468482
return err
469483
}

cni/network/invoker_cns_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,3 +2298,38 @@ func TestMultipleIBNICsToResult(t *testing.T) {
22982298
})
22992299
}
23002300
}
2301+
2302+
func Test_configureDefaultAddResult(t *testing.T) {
2303+
ipResultInfo := IPResultInfo{
2304+
podIPAddress: "10.240.2.10",
2305+
ncSubnetPrefix: 0,
2306+
ncPrimaryIP: "",
2307+
ncGatewayIPAddress: "",
2308+
hostSubnet: "10.240.0.0/16",
2309+
hostPrimaryIP: "10.240.1.246",
2310+
hostGateway: "10.240.0.1",
2311+
nicType: "InfraNIC",
2312+
macAddress: "",
2313+
skipDefaultRoutes: false,
2314+
routes: []cns.Route{},
2315+
}
2316+
addResult := IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
2317+
ipamAddConfig := IPAMAddConfig{nwCfg: &cni.NetworkConfig{IPAM: cni.IPAM{Type: "azure-cns", Mode: string(util.Nodesubnet)}}}
2318+
err := configureDefaultAddResult(
2319+
&ipResultInfo,
2320+
&ipamAddConfig,
2321+
&addResult,
2322+
"00-15-5D-3D-AD-5D")
2323+
if err != nil {
2324+
t.Fatalf("configureDefaultAddResult due to error: %v", err)
2325+
}
2326+
2327+
require.Equal(t, 1, len(addResult.interfaceInfo))
2328+
require.Equal(t, 1, len(addResult.interfaceInfo["00-15-5D-3D-AD-5D"].IPConfigs))
2329+
require.Equal(t, "10.240.2.10/16", addResult.interfaceInfo["00-15-5D-3D-AD-5D"].IPConfigs[0].Address.String())
2330+
require.Equal(t, "10.240.0.1", addResult.interfaceInfo["00-15-5D-3D-AD-5D"].IPConfigs[0].Gateway.String())
2331+
require.Equal(t, 1, len(addResult.interfaceInfo["00-15-5D-3D-AD-5D"].Routes))
2332+
require.Equal(t, "0.0.0.0/0", addResult.interfaceInfo["00-15-5D-3D-AD-5D"].Routes[0].Dst.String())
2333+
require.Equal(t, "10.240.0.1", addResult.interfaceInfo["00-15-5D-3D-AD-5D"].Routes[0].Gw.String())
2334+
require.Equal(t, cns.InfraNIC, addResult.interfaceInfo["00-15-5D-3D-AD-5D"].NICType)
2335+
}

cni/util/const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
V4Overlay IpamMode = "v4overlay"
1717
DualStackOverlay IpamMode = "dualStackOverlay"
1818
Overlay IpamMode = "overlay" // Nothing changes between 'v4overlay' and 'dualStackOverlay' mode, so consolidating to one
19+
Nodesubnet IpamMode = "nodesubnet"
1920
)
2021

2122
// Overlay consolidation plan

hack/aks/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ AZCLI ?= docker run --rm -v $(AZCFG):/root/.azure -v $(KUBECFG):/root/.kube -v
99

1010
# overrideable defaults
1111
AUTOUPGRADE ?= patch
12-
K8S_VER ?= 1.30
12+
K8S_VER ?= 1.31
1313
NODE_COUNT ?= 2
1414
NODE_COUNT_WIN ?= $(NODE_COUNT)
1515
NODEUPGRADE ?= NodeImage
1616
OS ?= linux # Used to signify if you want to bring up a windows nodePool on byocni clusters
17-
OS_SKU ?= Ubuntu
17+
OS_SKU ?= AzureLinux
1818
OS_SKU_WIN ?= Windows2022
1919
REGION ?= westus2
2020
VM_SIZE ?= Standard_B2s
@@ -136,15 +136,13 @@ endif
136136

137137
overlay-byocni-nokubeproxy-up: rg-up overlay-net-up ## Brings up an Overlay BYO CNI cluster without kube-proxy
138138
$(AZCLI) aks create -n $(CLUSTER) -g $(GROUP) -l $(REGION) \
139-
--auto-upgrade-channel $(AUTOUPGRADE) \
140-
--node-os-upgrade-channel $(NODEUPGRADE) \
141139
--kubernetes-version $(K8S_VER) \
142140
--node-count $(NODE_COUNT) \
143141
--node-vm-size $(VM_SIZE) \
144-
--load-balancer-sku basic \
145142
--network-plugin none \
146143
--network-plugin-mode overlay \
147144
--pod-cidr 192.168.0.0/16 \
145+
--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/UseCustomizedOSImage,OSImageSubscriptionID=109a5e88-712a-48ae-9078-9ca8b3c81345,OSImageResourceGroup=AKS-Ubuntu,OSImageGallery=AKSUbuntu,OSImageName=2404gen2containerd,OSImageVersion=202501.05.0 \
148146
--vnet-subnet-id /subscriptions/$(SUB)/resourceGroups/$(GROUP)/providers/Microsoft.Network/virtualNetworks/$(VNET)/subnets/nodenet \
149147
--no-ssh-key \
150148
--kube-proxy-config $(KUBE_PROXY_JSON_PATH) \
@@ -163,6 +161,8 @@ overlay-cilium-up: rg-up overlay-net-up ## Brings up an Overlay Cilium cluster
163161
--network-dataplane cilium \
164162
--network-plugin-mode overlay \
165163
--pod-cidr 192.168.0.0/16 \
164+
--os-sku $(OS_SKU) \
165+
--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/AzureLinuxV3Preview \
166166
--vnet-subnet-id /subscriptions/$(SUB)/resourceGroups/$(GROUP)/providers/Microsoft.Network/virtualNetworks/$(VNET)/subnets/nodenet \
167167
--no-ssh-key \
168168
--yes

0 commit comments

Comments
 (0)