Skip to content

Commit 7d4f0fe

Browse files
authored
[AKS] Add --disable-windows-outbound-nat for az aks nodepool add to add a Windows agent pool which the Windows OutboundNAT is disabled (#28806)
1 parent 5cc6e80 commit 7d4f0fe

File tree

9 files changed

+1744
-0
lines changed

9 files changed

+1744
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,9 @@
15681568
- name: --crg-id
15691569
type: string
15701570
short-summary: The crg id used to associate the new nodepool with the existed Capacity Reservation Group resource.
1571+
- name: --disable-windows-outbound-nat
1572+
type: bool
1573+
short-summary: Disable Windows OutboundNAT on Windows agent node pool.
15711574
15721575
examples:
15731576
- name: Create a nodepool in an existing AKS cluster with ephemeral os enabled.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
validate_force_upgrade_disable_and_enable_parameters,
8989
validate_allowed_host_ports, validate_application_security_groups,
9090
validate_node_public_ip_tags,
91+
validate_disable_windows_outbound_nat,
9192
validate_crg_id,
9293
validate_azure_service_mesh_revision)
9394
from azure.cli.core.commands.parameters import (
@@ -706,6 +707,7 @@ def load_arguments(self, _):
706707
c.argument('enable_encryption_at_host', action='store_true')
707708
c.argument('enable_ultra_ssd', action='store_true')
708709
c.argument('enable_fips_image', action='store_true')
710+
c.argument("disable_windows_outbound_nat", action="store_true", validator=validate_disable_windows_outbound_nat)
709711
c.argument('kubelet_config')
710712
c.argument('linux_os_config')
711713
c.argument('host_group_id', validator=validate_host_group_id)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,11 @@ def validate_azure_service_mesh_revision(namespace):
797797
found = asm_revision_regex.findall(revision)
798798
if not found:
799799
raise InvalidArgumentValueError(f"Revision {revision} is not supported by the service mesh add-on.")
800+
801+
802+
def validate_disable_windows_outbound_nat(namespace):
803+
"""Validates disable_windows_outbound_nat can only be used on Windows."""
804+
if namespace.disable_windows_outbound_nat:
805+
if hasattr(namespace, 'os_type') and str(namespace.os_type).lower() != "windows":
806+
raise ArgumentUsageError(
807+
'--disable-windows-outbound-nat can only be set for Windows nodepools')

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,34 @@ def get_ip_tags(self) -> Union[List[IPTag], None]:
13451345
))
13461346
return res
13471347

1348+
def _get_disable_windows_outbound_nat(self) -> bool:
1349+
"""Internal function to obtain the value of disable_windows_outbound_nat.
1350+
1351+
:return: bool
1352+
"""
1353+
# read the original value passed by the command
1354+
disable_windows_outbound_nat = self.raw_param.get("disable_windows_outbound_nat")
1355+
# In create mode, try to read the property value corresponding to the parameter from the `agentpool` object
1356+
if self.decorator_mode == DecoratorMode.CREATE:
1357+
if (
1358+
self.agentpool and
1359+
hasattr(self.agentpool, "windows_profile") and
1360+
self.agentpool.windows_profile and
1361+
self.agentpool.windows_profile.disable_windows_outbound_nat is not None
1362+
):
1363+
disable_windows_outbound_nat = self.agentpool.windows_profile.disable_windows_outbound_nat
1364+
1365+
# this parameter does not need dynamic completion
1366+
# this parameter does not need validation
1367+
return disable_windows_outbound_nat
1368+
1369+
def get_disable_windows_outbound_nat(self) -> bool:
1370+
"""Obtain the value of disable_windows_outbound_nat.
1371+
1372+
:return: bool
1373+
"""
1374+
return self._get_disable_windows_outbound_nat()
1375+
13481376

13491377
class AKSAgentPoolAddDecorator:
13501378
def __init__(
@@ -1660,6 +1688,23 @@ def set_up_agentpool_network_profile(self, agentpool: AgentPool) -> AgentPool:
16601688

16611689
return agentpool
16621690

1691+
def set_up_agentpool_windows_profile(self, agentpool: AgentPool) -> AgentPool:
1692+
"""Set up windows profile for the AgentPool object.
1693+
1694+
:return: the AgentPool object
1695+
"""
1696+
self._ensure_agentpool(agentpool)
1697+
1698+
disable_windows_outbound_nat = self.context.get_disable_windows_outbound_nat()
1699+
1700+
# Construct AgentPoolWindowsProfile if one of the fields has been set
1701+
if disable_windows_outbound_nat:
1702+
agentpool.windows_profile = self.models.AgentPoolWindowsProfile( # pylint: disable=no-member
1703+
disable_outbound_nat=disable_windows_outbound_nat
1704+
)
1705+
1706+
return agentpool
1707+
16631708
def construct_agentpool_profile_default(self, bypass_restore_defaults: bool = False) -> AgentPool:
16641709
"""The overall controller used to construct the AgentPool profile by default.
16651710
@@ -1696,6 +1741,8 @@ def construct_agentpool_profile_default(self, bypass_restore_defaults: bool = Fa
16961741
agentpool = self.set_up_gpu_properties(agentpool)
16971742
# set up agentpool network profile
16981743
agentpool = self.set_up_agentpool_network_profile(agentpool)
1744+
# set up agentpool windows profile
1745+
agentpool = self.set_up_agentpool_windows_profile(agentpool)
16991746
# set up crg id
17001747
agentpool = self.set_up_crg_id(agentpool)
17011748
# restore defaults

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,7 @@ def aks_agentpool_add(
23002300
allowed_host_ports=None,
23012301
asg_ids=None,
23022302
node_public_ip_tags=None,
2303+
disable_windows_outbound_nat=False,
23032304
):
23042305
# DO NOT MOVE: get all the original parameters and save them as a dictionary
23052306
raw_parameters = locals()

src/azure-cli/azure/cli/command_modules/acs/linter_exclusions.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,9 @@ aks update:
132132
azure_container_storage_nodepools:
133133
rule_exclusions:
134134
- option_length_too_long
135+
aks nodepool add:
136+
parameters:
137+
disable_windows_outbound_nat:
138+
rule_exclusions:
139+
- option_length_too_long
135140
...

0 commit comments

Comments
 (0)