Skip to content

Commit 079bca2

Browse files
authored
[AKS] az aks create and az aks nodepool add: Add --pod-ip-allocation-mode to the agentpool profile in AKS for Azure CNI Static Block GA feature support (#31544)
1 parent 10bd3df commit 079bca2

File tree

10 files changed

+1960
-0
lines changed

10 files changed

+1960
-0
lines changed

src/azure-cli/azure/cli/command_modules/acs/_consts.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@
125125
CONST_NETWORK_POLICY_CALICO = "calico"
126126
CONST_NETWORK_POLICY_NONE = "none"
127127

128+
# network pod ip allocation mode
129+
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL = "DynamicIndividual"
130+
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK = "StaticBlock"
131+
128132
# consts for addons
129133
# http application routing
130134
CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME = "httpApplicationRouting"

src/azure-cli/azure/cli/command_modules/acs/_help.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@
290290
- name: --pod-subnet-id
291291
type: string
292292
short-summary: The ID of a subnet in an existing VNet into which to assign pods in the cluster (requires azure network-plugin).
293+
- name: --pod-ip-allocation-mode
294+
type: string
295+
short-summary: Set the ip allocation mode for how Pod IPs from the Azure Pod Subnet are allocated to the nodes in the AKS cluster. The choice is between dynamic batches of individual IPs or static allocation of a set of CIDR blocks. Accepted Values are "DynamicIndividual" or "StaticBlock".
296+
long-summary: |
297+
Used together with the "azure" network plugin.
298+
Requires --pod-subnet-id.
293299
- name: --ppg
294300
type: string
295301
short-summary: The ID of a PPG.
@@ -662,6 +668,8 @@
662668
text: az aks create -g MyResourceGroup -n MyMC --kubernetes-version 1.20.9 --node-vm-size VMSize --assign-identity "subscriptions/SubID/resourceGroups/RGName/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID" --enable-managed-identity --crg-id "subscriptions/SubID/resourceGroups/RGName/providers/Microsoft.ContainerService/CapacityReservationGroups/MyCRGID"
663669
- name: Create a kubernetes cluster with Azure Service Mesh enabled.
664670
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-azure-service-mesh
671+
- name: Create a kubernetes cluster with a nodepool having ip allocation mode set to "StaticBlock"
672+
text: az aks create -g MyResourceGroup -n MyManagedCluster --os-sku Ubuntu --max-pods MaxPodsPerNode --network-plugin azure --vnet-subnet-id /subscriptions/SubID/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/NodeSubnet --pod-subnet-id /subscriptions/SubID/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/PodSubnet --pod-ip-allocation-mode StaticBlock
665673
"""
666674

667675
helps['aks update'] = """
@@ -1595,6 +1603,12 @@
15951603
- name: --pod-subnet-id
15961604
type: string
15971605
short-summary: The Resource Id of a subnet in an existing VNet into which to assign pods in the cluster (requires azure network-plugin).
1606+
- name: --pod-ip-allocation-mode
1607+
type: string
1608+
short-summary: Set the ip allocation mode for how Pod IPs from the Azure Pod Subnet are allocated to the nodes in the AKS cluster. The choice is between dynamic batches of individual IPs or static allocation of a set of CIDR blocks. Accepted Values are "DynamicIndividual" or "StaticBlock".
1609+
long-summary: |
1610+
Used together with the "azure" network plugin.
1611+
Requires --pod-subnet-id.
15981612
- name: --ppg
15991613
type: string
16001614
short-summary: The ID of a PPG.
@@ -1729,6 +1743,8 @@
17291743
text: az aks nodepool add -g MyResourceGroup -n MyNodePool --cluster-name MyMC --host-group-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.ContainerService/hostGroups/myHostGroup --node-vm-size VMSize
17301744
- name: create a nodepool with a Capacity Reservation Group(CRG) ID.
17311745
text: az aks nodepool add -g MyResourceGroup -n MyNodePool --cluster-name MyMC --node-vm-size VMSize --crg-id "/subscriptions/SubID/resourceGroups/ResourceGroupName/providers/Microsoft.ContainerService/CapacityReservationGroups/MyCRGID"
1746+
- name: Create a nodepool with ip allocation mode set to "StaticBlock" and using a pod subnet ID
1747+
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --os-sku Ubuntu --pod-subnet-id /subscriptions/SubID/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/MySubnet --pod-ip-allocation-mode StaticBlock
17321748
"""
17331749

17341750
helps['aks nodepool delete'] = """

src/azure-cli/azure/cli/command_modules/acs/_params.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
CONST_NETWORK_POLICY_AZURE, CONST_NETWORK_POLICY_CALICO, CONST_NETWORK_POLICY_CILIUM, CONST_NETWORK_POLICY_NONE,
2424
CONST_NETWORK_PLUGIN_AZURE, CONST_NETWORK_PLUGIN_KUBENET,
2525
CONST_NETWORK_PLUGIN_MODE_OVERLAY, CONST_NETWORK_PLUGIN_NONE,
26+
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL,
27+
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
2628
CONST_NODE_IMAGE_UPGRADE_CHANNEL, CONST_NONE_UPGRADE_CHANNEL,
2729
CONST_NODE_OS_CHANNEL_NODE_IMAGE,
2830
CONST_NODE_OS_CHANNEL_NONE,
@@ -165,6 +167,7 @@
165167
node_os_skus = node_os_skus_create + [CONST_OS_SKU_WINDOWS2019, CONST_OS_SKU_WINDOWS2022]
166168
node_os_skus_update = [CONST_OS_SKU_AZURELINUX, CONST_OS_SKU_UBUNTU, CONST_OS_SKU_UBUNTU2204]
167169
scale_down_modes = [CONST_SCALE_DOWN_MODE_DELETE, CONST_SCALE_DOWN_MODE_DEALLOCATE]
170+
pod_ip_allocation_modes = [CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL, CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK]
168171

169172
# consts for ManagedCluster
170173
load_balancer_skus = [CONST_LOAD_BALANCER_SKU_BASIC, CONST_LOAD_BALANCER_SKU_STANDARD]
@@ -446,6 +449,7 @@ def load_arguments(self, _):
446449
c.argument('snapshot_id', validator=validate_snapshot_id)
447450
c.argument('vnet_subnet_id', validator=validate_vnet_subnet_id)
448451
c.argument('pod_subnet_id', validator=validate_pod_subnet_id)
452+
c.argument('pod_ip_allocation_mode', arg_type=get_enum_type(pod_ip_allocation_modes))
449453
c.argument('enable_node_public_ip', action='store_true')
450454
c.argument('node_public_ip_prefix_id')
451455
c.argument('enable_cluster_autoscaler', action='store_true')
@@ -824,6 +828,7 @@ def load_arguments(self, _):
824828
c.argument('snapshot_id', validator=validate_snapshot_id)
825829
c.argument('vnet_subnet_id', validator=validate_vnet_subnet_id)
826830
c.argument('pod_subnet_id', validator=validate_pod_subnet_id)
831+
c.argument('pod_ip_allocation_mode', arg_type=get_enum_type(pod_ip_allocation_modes))
827832
c.argument('enable_node_public_ip', action='store_true')
828833
c.argument('node_public_ip_prefix_id')
829834
c.argument('enable_cluster_autoscaler', options_list=["--enable-cluster-autoscaler", "-e"], action='store_true')

src/azure-cli/azure/cli/command_modules/acs/_validators.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
CONST_OS_SKU_AZURELINUX,
1717
CONST_OS_SKU_CBLMARINER,
1818
CONST_OS_SKU_MARINER,
19+
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL,
20+
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
1921
CONST_NODEPOOL_MODE_GATEWAY,
2022
)
2123
from azure.cli.core import keys
@@ -372,6 +374,16 @@ def validate_pod_subnet_id(namespace):
372374
_validate_subnet_id(namespace.pod_subnet_id, "--pod-subnet-id")
373375

374376

377+
def validate_pod_ip_allocation_mode(namespace):
378+
"""Validates the pod ip allocation mode string."""
379+
if namespace.pod_ip_allocation_mode is not None:
380+
if namespace.pod_ip_allocation_mode not in (
381+
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL,
382+
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
383+
):
384+
raise InvalidArgumentValueError("--pod-ip-allocation-mode can only be DynamicIndividual or StaticBlock")
385+
386+
375387
def validate_apiserver_subnet_id(namespace):
376388
_validate_subnet_id(namespace.apiserver_subnet_id, "--apiserver-subnet-id")
377389

src/azure-cli/azure/cli/command_modules/acs/agentpool_decorator.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,26 @@ def get_pod_subnet_id(self) -> Union[str, None]:
763763
# this parameter does not need validation
764764
return pod_subnet_id
765765

766+
def get_pod_ip_allocation_mode(self: bool = False) -> Union[str, None]:
767+
"""Get the value of pod_ip_allocation_mode.
768+
769+
:return: str or None
770+
"""
771+
772+
# Get the value of pod_ip_allocation_mode from the raw parameters provided by the user
773+
pod_ip_allocation_mode = self.raw_param.get("pod_ip_allocation_mode")
774+
# In create mode, try to read the property value corresponding to the parameter from the `agentpool` object
775+
# if it exists and user has not provided any value in raw parameters
776+
if self.decorator_mode == DecoratorMode.CREATE:
777+
if (
778+
pod_ip_allocation_mode and
779+
self.agentpool and
780+
self.agentpool.pod_ip_allocation_mode is not None
781+
):
782+
pod_ip_allocation_mode = self.agentpool.pod_ip_allocation_mode
783+
784+
return pod_ip_allocation_mode
785+
766786
def get_enable_node_public_ip(self) -> bool:
767787
"""Obtain the value of enable_node_public_ip, default value is False.
768788
@@ -1785,6 +1805,7 @@ def set_up_node_network_properties(self, agentpool: AgentPool) -> AgentPool:
17851805

17861806
agentpool.vnet_subnet_id = self.context.get_vnet_subnet_id()
17871807
agentpool.pod_subnet_id = self.context.get_pod_subnet_id()
1808+
agentpool.pod_ip_allocation_mode = self.context.get_pod_ip_allocation_mode()
17881809
agentpool.enable_node_public_ip = self.context.get_enable_node_public_ip()
17891810
agentpool.node_public_ip_prefix_id = self.context.get_node_public_ip_prefix_id()
17901811
return agentpool
@@ -2030,6 +2051,19 @@ def set_up_agentpool_gateway_profile(self, agentpool: AgentPool) -> AgentPool:
20302051

20312052
return agentpool
20322053

2054+
def set_up_pod_ip_allocation_mode(self, agentpool: AgentPool) -> AgentPool:
2055+
"""Set up pod ip allocation mode for the AgentPool object.
2056+
2057+
:return: the AgentPool object
2058+
"""
2059+
self._ensure_agentpool(agentpool)
2060+
2061+
pod_ip_allocation_mode = self.context.get_pod_ip_allocation_mode()
2062+
if pod_ip_allocation_mode is not None:
2063+
agentpool.pod_ip_allocation_mode = pod_ip_allocation_mode
2064+
2065+
return agentpool
2066+
20332067
def construct_agentpool_profile_default(self, bypass_restore_defaults: bool = False) -> AgentPool:
20342068
"""The overall controller used to construct the AgentPool profile by default.
20352069
@@ -2066,6 +2100,8 @@ def construct_agentpool_profile_default(self, bypass_restore_defaults: bool = Fa
20662100
agentpool = self.set_up_gpu_properties(agentpool)
20672101
# set up agentpool network profile
20682102
agentpool = self.set_up_agentpool_network_profile(agentpool)
2103+
# set up agentpool pod ip allocation mode
2104+
agentpool = self.set_up_pod_ip_allocation_mode(agentpool)
20692105
# set up agentpool windows profile
20702106
agentpool = self.set_up_agentpool_windows_profile(agentpool)
20712107
# set up crg id

src/azure-cli/azure/cli/command_modules/acs/custom.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ def aks_create(
610610
snapshot_id=None,
611611
vnet_subnet_id=None,
612612
pod_subnet_id=None,
613+
pod_ip_allocation_mode=None,
613614
enable_node_public_ip=False,
614615
node_public_ip_prefix_id=None,
615616
enable_cluster_autoscaler=False,
@@ -2396,6 +2397,7 @@ def aks_agentpool_add(
23962397
snapshot_id=None,
23972398
vnet_subnet_id=None,
23982399
pod_subnet_id=None,
2400+
pod_ip_allocation_mode=None,
23992401
enable_node_public_ip=False,
24002402
node_public_ip_prefix_id=None,
24012403
enable_cluster_autoscaler=False,

0 commit comments

Comments
 (0)