Skip to content

Commit e293266

Browse files
authored
[AKS] Add Podsubnet argument to cluster create and nodepool add (Azure#2655)
1 parent 66bf5a6 commit e293266

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@
205205
- name: --vnet-subnet-id
206206
type: string
207207
short-summary: The ID of a subnet in an existing VNet into which to deploy the cluster.
208+
- name: --pod-subnet-id
209+
type: string
210+
short-summary: The ID of a subnet in an existing VNet into which to assign pods in the cluster (requires azure network-plugin)
208211
- name: --ppg
209212
type: string
210213
short-summary: The ID of a PPG.
@@ -572,6 +575,9 @@
572575
- name: --vnet-subnet-id
573576
type: string
574577
short-summary: The ID of a subnet in an existing VNet into which to deploy the cluster.
578+
- name: --pod-subnet-id
579+
type: string
580+
short-summary: The ID of a subnet in an existing VNet into which to assign pods in the cluster (requires azure network-plugin)
575581
- name: --ppg
576582
type: string
577583
short-summary: The ID of a PPG.

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
validate_load_balancer_outbound_ips, validate_load_balancer_outbound_ip_prefixes,
2323
validate_taints, validate_priority, validate_eviction_policy, validate_spot_max_price, validate_acr, validate_user,
2424
validate_load_balancer_outbound_ports, validate_load_balancer_idle_timeout, validate_nodepool_tags,
25-
validate_nodepool_labels, validate_vnet_subnet_id, validate_max_surge, validate_assign_identity, validate_addons)
25+
validate_nodepool_labels, validate_vnet_subnet_id, validate_pod_subnet_id, validate_max_surge, validate_assign_identity, validate_addons)
2626
from ._consts import CONST_OUTBOUND_TYPE_LOAD_BALANCER, \
2727
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, CONST_SCALE_SET_PRIORITY_REGULAR, CONST_SCALE_SET_PRIORITY_SPOT, \
2828
CONST_SPOT_EVICTION_POLICY_DELETE, CONST_SPOT_EVICTION_POLICY_DEALLOCATE, \
@@ -86,6 +86,7 @@ def load_arguments(self, _):
8686
c.argument('pod_cidr')
8787
c.argument('service_cidr')
8888
c.argument('vnet_subnet_id', type=str, validator=validate_vnet_subnet_id)
89+
c.argument('pod_subnet_id', type=str, validator=validate_pod_subnet_id)
8990
c.argument('ppg')
9091
c.argument('workspace_resource_id')
9192
c.argument('skip_subnet_role_assignment', action='store_true')
@@ -167,6 +168,8 @@ def load_arguments(self, _):
167168
c.argument('ppg')
168169
c.argument('max_surge', type=str, validator=validate_max_surge)
169170
c.argument('node_os_disk_type', arg_type=get_enum_type([CONST_OS_DISK_TYPE_MANAGED, CONST_OS_DISK_TYPE_EPHEMERAL]))
171+
c.argument('vnet_subnet_id', type=str, validator=validate_vnet_subnet_id)
172+
c.argument('pod_subnet_id', type=str, validator=validate_pod_subnet_id)
170173
c.argument('kubelet_config', type=str)
171174
c.argument('linux_os_config', type=str)
172175

src/aks-preview/azext_aks_preview/_validators.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from azure.cli.core.commands.validators import validate_tag
1616
from azure.cli.core.util import CLIError
17+
from azure.cli.core.azclierror import InvalidArgumentValueError
1718
import azure.cli.core.keys as keys
1819

1920
from .vendored_sdks.azure_mgmt_preview_aks.v2020_11_01.models import ManagedClusterPropertiesAutoScalerProfile
@@ -234,12 +235,19 @@ def validate_user(namespace):
234235

235236

236237
def validate_vnet_subnet_id(namespace):
237-
if namespace.vnet_subnet_id is not None:
238-
if namespace.vnet_subnet_id == '':
239-
return
240-
from msrestazure.tools import is_valid_resource_id
241-
if not is_valid_resource_id(namespace.vnet_subnet_id):
242-
raise CLIError("--vnet-subnet-id is not a valid Azure resource ID.")
238+
_validate_subnet_id(namespace.vnet_subnet_id, "--vnet-subnet-id")
239+
240+
241+
def validate_pod_subnet_id(namespace):
242+
_validate_subnet_id(namespace.pod_subnet_id, "--pod-subnet-id")
243+
244+
245+
def _validate_subnet_id(subnet_id, name):
246+
if subnet_id is None or subnet_id == '':
247+
return
248+
from msrestazure.tools import is_valid_resource_id
249+
if not is_valid_resource_id(subnet_id):
250+
raise InvalidArgumentValueError(name + " is not a valid Azure resource ID.")
243251

244252

245253
def validate_load_balancer_outbound_ports(namespace):

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
851851
min_count=None,
852852
max_count=None,
853853
vnet_subnet_id=None,
854+
pod_subnet_id=None,
854855
ppg=None,
855856
max_pods=0,
856857
aad_client_app_id=None,
@@ -922,6 +923,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
922923
os_type="Linux",
923924
mode="System",
924925
vnet_subnet_id=vnet_subnet_id,
926+
pod_subnet_id=pod_subnet_id,
925927
proximity_placement_group_id=ppg,
926928
availability_zones=node_zones,
927929
enable_node_public_ip=enable_node_public_ip,
@@ -2320,6 +2322,7 @@ def aks_agentpool_add(cmd, # pylint: disable=unused-argument,too-many-local
23202322
node_osdisk_size=0,
23212323
node_count=3,
23222324
vnet_subnet_id=None,
2325+
pod_subnet_id=None,
23232326
ppg=None,
23242327
max_pods=0,
23252328
os_type="Linux",
@@ -2372,6 +2375,7 @@ def aks_agentpool_add(cmd, # pylint: disable=unused-argument,too-many-local
23722375
os_type=os_type,
23732376
storage_profile=ContainerServiceStorageProfileTypes.managed_disks,
23742377
vnet_subnet_id=vnet_subnet_id,
2378+
pod_subnet_id=pod_subnet_id,
23752379
proximity_placement_group_id=ppg,
23762380
agent_pool_type="VirtualMachineScaleSets",
23772381
max_pods=int(max_pods) if max_pods else None,

src/aks-preview/azext_aks_preview/tests/latest/test_validators.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,35 +118,24 @@ def __init__(self, api_server_authorized_ip_ranges=None, cluster_autoscaler_prof
118118
self.cluster_autoscaler_profile = cluster_autoscaler_profile
119119

120120

121-
class TestVNetSubnetId(unittest.TestCase):
122-
def test_invalid_vnet_subnet_id(self):
121+
class TestSubnetId(unittest.TestCase):
122+
def test_invalid_subnet_id(self):
123123
invalid_vnet_subnet_id = "dummy subnet id"
124-
namespace = VnetSubnetIdNamespace(invalid_vnet_subnet_id)
125124
err = ("--vnet-subnet-id is not a valid Azure resource ID.")
126125

127126
with self.assertRaises(CLIError) as cm:
128-
validators.validate_vnet_subnet_id(namespace)
127+
validators._validate_subnet_id(invalid_vnet_subnet_id, "--vnet-subnet-id")
129128
self.assertEqual(str(cm.exception), err)
130129

131130
def test_valid_vnet_subnet_id(self):
132-
invalid_vnet_subnet_id = "/subscriptions/testid/resourceGroups/MockedResourceGroup/providers/Microsoft.Network/virtualNetworks/MockedNetworkId/subnets/MockedSubNetId"
133-
namespace = VnetSubnetIdNamespace(invalid_vnet_subnet_id)
134-
validators.validate_vnet_subnet_id(namespace)
131+
valid_subnet_id = "/subscriptions/testid/resourceGroups/MockedResourceGroup/providers/Microsoft.Network/virtualNetworks/MockedNetworkId/subnets/MockedSubNetId"
132+
validators._validate_subnet_id(valid_subnet_id, "something")
135133

136134
def test_none_vnet_subnet_id(self):
137-
invalid_vnet_subnet_id = None
138-
namespace = VnetSubnetIdNamespace(invalid_vnet_subnet_id)
139-
validators.validate_vnet_subnet_id(namespace)
135+
validators._validate_subnet_id(None, "something")
140136

141137
def test_empty_vnet_subnet_id(self):
142-
invalid_vnet_subnet_id = ""
143-
namespace = VnetSubnetIdNamespace(invalid_vnet_subnet_id)
144-
validators.validate_vnet_subnet_id(namespace)
145-
146-
147-
class VnetSubnetIdNamespace:
148-
def __init__(self, vnet_subnet_id):
149-
self.vnet_subnet_id = vnet_subnet_id
138+
validators._validate_subnet_id("", "something")
150139

151140

152141
class MaxSurgeNamespace:

0 commit comments

Comments
 (0)