Skip to content

Commit

Permalink
Adding the cli command option for --pod-ip-allocation-mode for cluste…
Browse files Browse the repository at this point in the history
…r creation and nodepool addition in AKS (#7288)

* Adding the cli command option for --pod-ip-allocation-mode

* Added all the fields to read and populate the pod ip allocation mode from the az aks create and az aks nodepool commands with validations

* Addressed all the code review comments by removing the Unassigned from the CLI, use the raw_param as the source of truth else fallback on agentpool config

* Added a UT for the new podIPAllocationProperty

* Added the new UT to be called on the required decorators

* Added a live test case for podIPAllocationMode and creating a StaticBlock cluster

* Added the necessary space

* Simplified the logic to read from the agentpool profile if the value exists else deafault to the value provided by the user in the command line

* Trying to fix the linter issues

* Updated the code to adhere to the azdev styles

* Fixed errors to adhere to the azdev styles

* Attempting to not initialize any pod-ip-allocation-mode by default and then attach an agentpool with StaticBlock

* Fixed param list

* Adding the live only tag for the live test added

* Fixed the missing '-' from the max-pods argument

* Attempting to fix the resource ID for the node subnet

* Attempting to fix the resource ID for the node subnet

* Fixed the property name of the agentpoolprofile

* Updated the expected value for podSubnetID

* Added the logic to add the podIPAllocationMode to the agentpool network profile which was what was failing the CI

* Removed the reference to agentpool network profile

* Added a test case for managed_cluster properties generation

* Added methods to update the pod ip allocation mode property of the agentpool to both the create and update methods

* Fixing the variable name in the live test aks_name

* Added the live test recording to the PR

* Updated the PR based on the review comments to reorder the logic in the get method for the pod-ip-allocation-mode property and also removed the definition and call to set the property in the AgentPoolUpdateDecorator as the property option is only available in the aks create and aks nodepool add commands.

* Updated the test cases based on the suggestions made in the PR review

* Upated the History and setup.py files after rebasing to merge the new property in the next version

* Fixed the assertion value

* Fixed the azdev styles issue

* Removed the liveonly tag

* Excluding the test from the live test as it requires feature registration

* Update src/aks-preview/azext_aks_preview/_help.py based on the suggested change

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>

* Update src/aks-preview/azext_aks_preview/_help.py to use first-person voice.

Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>

---------

Co-authored-by: Ashish Nair <ashish.nair@microsoft.com>
Co-authored-by: Xing Zhou <Zhou.Xing@microsoft.com>
  • Loading branch information
3 people committed Feb 29, 2024
1 parent 7b2ba86 commit c4eaa7d
Show file tree
Hide file tree
Showing 13 changed files with 2,309 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ If there is no rush to release a new version, please just add a description of t

To release a new version, please select a new version number (usually plus 1 to last patch version, X.Y.Z -> Major.Minor.Patch, more details in `\doc <https://semver.org/>`_), and then add a new section named as the new version number in this file, the content should include the new modifications and everything from the *Pending* section. Finally, update the `VERSION` variable in `setup.py` with this new version number.

2.0.0b2
+++++++
* Add `--pod-ip-allocation-mode` to `az aks create` and `az aks nodepool` commands.

2.0.0b1
+++++++
* [BREAKING CHANGE] Replace `guardrails` parameters with `safeguards`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"overlay migration, missing toggle": [
"test_aks_azure_cni_overlay_migration"
],
"pod ip allocation mode static block, missing feature registration": [
"test_aks_create_with_pod_ip_allocation_mode_static_block"
],
"slb to nat gateway": [
"test_aks_update_outbound_from_slb_to_natgateway"
],
Expand Down
4 changes: 4 additions & 0 deletions src/aks-preview/azext_aks_preview/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
CONST_NETWORK_POLICY_CILIUM = "cilium"
CONST_NETWORK_POLICY_NONE = "none"

# network pod ip allocation mode
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL = "DynamicIndividual"
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK = "StaticBlock"

# disk driver versions
CONST_DISK_DRIVER_V1 = "v1"
CONST_DISK_DRIVER_V2 = "v2"
Expand Down
16 changes: 16 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@
- name: --ssh-access
type: string
short-summary: Configure SSH setting for all node pools in this cluster. Use "disabled" to disable SSH access, "localuser" to enable SSH access using private key.
- name: --pod-ip-allocation-mode
type: string
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".
long-summary: |
Used together with the "azure" network plugin.
Requires --pod-subnet-id.
examples:
- name: Create a Kubernetes cluster with an existing SSH public key.
text: az aks create -g MyResourceGroup -n MyManagedCluster --ssh-key-value /path/to/publickey
Expand Down Expand Up @@ -665,6 +671,8 @@
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-azure-service-mesh
- name: Create a kubernetes cluster with Azure Monitor Metrics enabled.
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-azuremonitormetrics
- name: Create a kubernetes cluster with a nodepool having ip allocation mode set to "StaticBlock"
text: az aks create -g MyResourceGroup -n MyManagedCluster --os-sku Ubuntu --max-pods MaxPodsPerNode --network-plugin azure --vnet-subnet-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/NodeSubnet --pod-subnet-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/PodSubnet --pod-ip-allocation-mode StaticBlock
"""

Expand Down Expand Up @@ -1725,6 +1733,12 @@
- name: --ssh-access
type: string
short-summary: Configure SSH setting for the node pool. Use "disabled" to disable SSH access, "localuser" to enable SSH access using private key.
- name: --pod-ip-allocation-mode
type: string
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".
long-summary: |
Used together with the "azure" network plugin.
Requires --pod-subnet-id.
examples:
- name: Create a nodepool in an existing AKS cluster with ephemeral os enabled.
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --node-osdisk-type Ephemeral --node-osdisk-size 48
Expand All @@ -1740,6 +1754,8 @@
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"
- name: create a nodepool in an existing AKS cluster with host group id
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
- name: Create a nodepool with ip allocation mode set to "StaticBlock" and using a pod subnet ID
text: az aks nodepool add -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --os-sku Ubuntu --pod-subnet-id /subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.Network/virtualNetworks/MyVnet/subnets/MySubnet --pod-ip-allocation-mode StaticBlock
"""

helps['aks nodepool scale'] = """
Expand Down
17 changes: 17 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
CONST_NETWORK_PLUGIN_KUBENET,
CONST_NETWORK_PLUGIN_MODE_OVERLAY,
CONST_NETWORK_PLUGIN_NONE,
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL,
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
CONST_NODE_IMAGE_UPGRADE_CHANNEL,
CONST_NODE_OS_CHANNEL_NODE_IMAGE,
CONST_NODE_OS_CHANNEL_NONE,
Expand Down Expand Up @@ -157,6 +159,7 @@
validate_pod_identity_resource_name,
validate_pod_identity_resource_namespace,
validate_pod_subnet_id,
validate_pod_ip_allocation_mode,
validate_priority,
validate_sku_tier,
validate_snapshot_id,
Expand Down Expand Up @@ -224,6 +227,10 @@
CONST_GPU_INSTANCE_PROFILE_MIG4_G,
CONST_GPU_INSTANCE_PROFILE_MIG7_G,
]
pod_ip_allocation_modes = [
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL,
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
]

# consts for ManagedCluster
load_balancer_skus = [CONST_LOAD_BALANCER_SKU_BASIC, CONST_LOAD_BALANCER_SKU_STANDARD]
Expand Down Expand Up @@ -583,6 +590,11 @@ def load_arguments(self, _):
c.argument("snapshot_id", validator=validate_snapshot_id)
c.argument("vnet_subnet_id", validator=validate_vnet_subnet_id)
c.argument("pod_subnet_id", validator=validate_pod_subnet_id)
c.argument(
"pod_ip_allocation_mode",
arg_type=get_enum_type(pod_ip_allocation_modes),
validator=validate_pod_ip_allocation_mode,
)
c.argument("enable_node_public_ip", action="store_true")
c.argument("node_public_ip_prefix_id")
c.argument("enable_cluster_autoscaler", action="store_true")
Expand Down Expand Up @@ -1269,6 +1281,11 @@ def load_arguments(self, _):
c.argument("snapshot_id", validator=validate_snapshot_id)
c.argument("vnet_subnet_id", validator=validate_vnet_subnet_id)
c.argument("pod_subnet_id", validator=validate_pod_subnet_id)
c.argument(
"pod_ip_allocation_mode",
arg_type=get_enum_type(pod_ip_allocation_modes),
validator=validate_pod_ip_allocation_mode,
)
c.argument("enable_node_public_ip", action="store_true")
c.argument("node_public_ip_prefix_id")
c.argument(
Expand Down
12 changes: 12 additions & 0 deletions src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
CONST_OS_SKU_AZURELINUX,
CONST_OS_SKU_CBLMARINER,
CONST_OS_SKU_MARINER,
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL,
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
)
from azext_aks_preview._helpers import _fuzzy_match
from knack.log import get_logger
Expand Down Expand Up @@ -298,6 +300,16 @@ def validate_user(namespace):
"--user can only be clusterUser or clusterMonitoringUser")


def validate_pod_ip_allocation_mode(namespace):
"""Validates the pod ip allocation mode string."""
if namespace.pod_ip_allocation_mode is not None:
if namespace.pod_ip_allocation_mode not in (
CONST_NETWORK_POD_IP_ALLOCATION_MODE_DYNAMIC_INDIVIDUAL,
CONST_NETWORK_POD_IP_ALLOCATION_MODE_STATIC_BLOCK,
):
raise InvalidArgumentValueError("--pod-ip-allocation-mode can only be DynamicIndividual or StaticBlock")


def validate_vnet_subnet_id(namespace):
_validate_subnet_id(namespace.vnet_subnet_id, "--vnet-subnet-id")

Expand Down
30 changes: 30 additions & 0 deletions src/aks-preview/azext_aks_preview/agentpool_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,25 @@ def get_enable_artifact_streaming(self) -> bool:
enable_artifact_streaming = self.agentpool.artifact_streaming_profile.enabled
return enable_artifact_streaming

def get_pod_ip_allocation_mode(self: bool = False) -> Union[str, None]:
"""Get the value of pod_ip_allocation_mode.
:return: str or None
"""

# Get the value of pod_ip_allocation_mode from the raw parameters provided by the user
pod_ip_allocation_mode = self.raw_param.get("pod_ip_allocation_mode")
# In create mode, try to read the property value corresponding to the parameter from the `agentpool` object
# if it exists and user has not provided any value in raw parameters
if self.decorator_mode == DecoratorMode.CREATE:
if (
pod_ip_allocation_mode and
self.agentpool and
self.agentpool.pod_ip_allocation_mode is not None
):
pod_ip_allocation_mode = self.agentpool.pod_ip_allocation_mode

return pod_ip_allocation_mode

def get_ssh_access(self) -> Union[str, None]:
"""Obtain the value of ssh_access.
"""
Expand Down Expand Up @@ -606,6 +625,15 @@ def set_up_skip_gpu_driver_install(self, agentpool: AgentPool) -> AgentPool:
agentpool.gpu_profile.install_gpu_driver = False
return agentpool

def set_up_pod_ip_allocation_mode(self, agentpool: AgentPool) -> AgentPool:
"""Set up pod ip allocation mode for the AgentPool object."""
self._ensure_agentpool(agentpool)

pod_ip_allocation_mode = self.context.get_pod_ip_allocation_mode()
if pod_ip_allocation_mode is not None:
agentpool.pod_ip_allocation_mode = pod_ip_allocation_mode
return agentpool

def construct_agentpool_profile_preview(self) -> AgentPool:
"""The overall controller used to construct the preview AgentPool profile.
Expand Down Expand Up @@ -635,6 +663,8 @@ def construct_agentpool_profile_preview(self) -> AgentPool:
agentpool = self.set_up_skip_gpu_driver_install(agentpool)
# set up agentpool ssh access
agentpool = self.set_up_ssh_access(agentpool)
# set up agentpool pod ip allocation mode
agentpool = self.set_up_pod_ip_allocation_mode(agentpool)
# DO NOT MOVE: keep this at the bottom, restore defaults
agentpool = self._restore_defaults_in_agentpool(agentpool)
return agentpool
Expand Down
2 changes: 2 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ def aks_create(
snapshot_id=None,
vnet_subnet_id=None,
pod_subnet_id=None,
pod_ip_allocation_mode=None,
enable_node_public_ip=False,
node_public_ip_prefix_id=None,
enable_cluster_autoscaler=False,
Expand Down Expand Up @@ -1142,6 +1143,7 @@ def aks_agentpool_add(
snapshot_id=None,
vnet_subnet_id=None,
pod_subnet_id=None,
pod_ip_allocation_mode=None,
enable_node_public_ip=False,
node_public_ip_prefix_id=None,
enable_cluster_autoscaler=False,
Expand Down
Loading

0 comments on commit c4eaa7d

Please sign in to comment.