Skip to content

Commit c4bc7a3

Browse files
Jenny LiuJenny Liu
authored andcommitted
Fix safeguards -g/-n support and update test recordings
1 parent 948caa1 commit c4bc7a3

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

src/aks-preview/azext_aks_preview/aks_safeguards_custom.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from azure.cli.core.aaz import AAZResourceGroupNameArg, AAZStrArg, has_value
1111
from azure.cli.core.azclierror import ArgumentUsageError, CLIError, HTTPError
1212
from azure.cli.core.util import send_raw_request
13+
from azure.mgmt.core.tools import is_valid_resource_id
1314

1415
from azext_aks_preview.aaz.latest.aks.safeguards._create import Create
1516
from azext_aks_preview.aaz.latest.aks.safeguards._delete import Delete
@@ -40,6 +41,28 @@ def _validate_and_set_managed_cluster_argument(ctx):
4041
f"/subscriptions/{ctx.subscription_id}/resourceGroups/{args.resource_group}/"
4142
f"providers/Microsoft.ContainerService/managedClusters/{args.cluster_name}"
4243
)
44+
else:
45+
# If managed_cluster is provided but is not a full resource ID, treat it as a cluster name
46+
# and require resource_group to be provided
47+
managed_cluster_value = args.managed_cluster.to_serialized_data()
48+
49+
# Normalize resource ID: add leading slash if missing for backward compatibility
50+
if managed_cluster_value and not managed_cluster_value.startswith('/'):
51+
managed_cluster_value = f"/{managed_cluster_value}"
52+
53+
if not is_valid_resource_id(managed_cluster_value):
54+
# It's just a cluster name, need resource group
55+
if not has_value(args.resource_group):
56+
raise ArgumentUsageError(
57+
"When providing cluster name via -c/--cluster, you must also provide -g/--resource-group."
58+
)
59+
# Build the full resource ID
60+
managed_cluster_value = (
61+
f"/subscriptions/{ctx.subscription_id}/resourceGroups/{args.resource_group}/"
62+
f"providers/Microsoft.ContainerService/managedClusters/{managed_cluster_value.lstrip('/')}"
63+
)
64+
65+
args.managed_cluster = managed_cluster_value
4366

4467

4568
def _add_resource_group_cluster_name_args(_args_schema):
@@ -60,7 +83,7 @@ def _add_resource_group_cluster_name_args(_args_schema):
6083
"or both --resource-group and --name, but not both.",
6184
required=False,
6285
)
63-
_args_schema.managed_cluster.required = False
86+
_args_schema.managed_cluster._required = False # pylint: disable=protected-access
6487
return _args_schema
6588

6689

src/aks-preview/azext_aks_preview/tests/latest/recordings/test_aks_deployment_safeguards_argument_validation.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ interactions:
9797
body: '{"location": "westus2", "sku": {"name": "Base", "tier": "Free"}, "identity":
9898
{"type": "SystemAssigned"}, "kind": "Base", "properties": {"kubernetesVersion":
9999
"", "dnsPrefix": "aksval-lqt-cli-000001-26fe00", "agentPoolProfiles": [{"count":
100-
3, "vmSize": "standard_a8_v2", "osDiskSizeGB": 0, "workloadRuntime": "OCIContainer",
100+
3, "vmSize": "Standard_DS2_v2", "osDiskSizeGB": 0, "workloadRuntime": "OCIContainer",
101101
"osType": "Linux", "enableAutoScaling": false, "type": "VirtualMachineScaleSets",
102102
"mode": "System", "orchestratorVersion": "", "upgradeSettings": {}, "upgradeSettingsBlueGreen":
103103
{}, "enableNodePublicIP": false, "scaleSetPriority": "Regular", "scaleSetEvictionPolicy":
@@ -140,7 +140,7 @@ interactions:
140140
\ \"fqdn\": \"aksval-lqt-cli-000001-26fe00-8wql3q5r.hcp.westus2.staging.azmk8s.io\",\n
141141
\ \"azurePortalFQDN\": \"aksval-lqt-cli-000001-26fe00-8wql3q5r.portal.hcp.westus2.staging.azmk8s.io\",\n
142142
\ \"agentPoolProfiles\": [\n {\n \"name\": \"nodepool1\",\n \"count\":
143-
3,\n \"vmSize\": \"standard_a8_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
143+
3,\n \"vmSize\": \"Standard_DS2_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
144144
\"Managed\",\n \"kubeletDiskType\": \"OS\",\n \"workloadRuntime\": \"OCIContainer\",\n
145145
\ \"maxPods\": 250,\n \"type\": \"VirtualMachineScaleSets\",\n \"enableAutoScaling\":
146146
false,\n \"scaleDownMode\": \"Delete\",\n \"provisioningState\": \"Creating\",\n
@@ -1229,7 +1229,7 @@ interactions:
12291229
\ \"fqdn\": \"aksval-lqt-cli-000001-26fe00-8wql3q5r.hcp.westus2.staging.azmk8s.io\",\n
12301230
\ \"azurePortalFQDN\": \"aksval-lqt-cli-000001-26fe00-8wql3q5r.portal.hcp.westus2.staging.azmk8s.io\",\n
12311231
\ \"agentPoolProfiles\": [\n {\n \"name\": \"nodepool1\",\n \"count\":
1232-
3,\n \"vmSize\": \"standard_a8_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
1232+
3,\n \"vmSize\": \"Standard_DS2_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
12331233
\"Managed\",\n \"kubeletDiskType\": \"OS\",\n \"workloadRuntime\": \"OCIContainer\",\n
12341234
\ \"maxPods\": 250,\n \"type\": \"VirtualMachineScaleSets\",\n \"enableAutoScaling\":
12351235
false,\n \"scaleDownMode\": \"Delete\",\n \"provisioningState\": \"Succeeded\",\n

src/aks-preview/azext_aks_preview/tests/latest/recordings/test_aks_deployment_safeguards_basic.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ interactions:
9797
body: '{"location": "westus2", "sku": {"name": "Base", "tier": "Free"}, "identity":
9898
{"type": "SystemAssigned"}, "kind": "Base", "properties": {"kubernetesVersion":
9999
"", "dnsPrefix": "akssafegua-cli-000001-26fe00", "agentPoolProfiles": [{"count":
100-
3, "vmSize": "standard_a8_v2", "osDiskSizeGB": 0, "workloadRuntime": "OCIContainer",
100+
3, "vmSize": "Standard_DS2_v2", "osDiskSizeGB": 0, "workloadRuntime": "OCIContainer",
101101
"osType": "Linux", "enableAutoScaling": false, "type": "VirtualMachineScaleSets",
102102
"mode": "System", "orchestratorVersion": "", "upgradeSettings": {}, "upgradeSettingsBlueGreen":
103103
{}, "enableNodePublicIP": false, "scaleSetPriority": "Regular", "scaleSetEvictionPolicy":
@@ -141,7 +141,7 @@ interactions:
141141
\"akssafegua-cli-000001-26fe00-ofss7i1d.hcp.westus2.staging.azmk8s.io\",\n
142142
\ \"azurePortalFQDN\": \"akssafegua-cli-000001-26fe00-ofss7i1d.portal.hcp.westus2.staging.azmk8s.io\",\n
143143
\ \"agentPoolProfiles\": [\n {\n \"name\": \"nodepool1\",\n \"count\":
144-
3,\n \"vmSize\": \"standard_a8_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
144+
3,\n \"vmSize\": \"Standard_DS2_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
145145
\"Managed\",\n \"kubeletDiskType\": \"OS\",\n \"workloadRuntime\": \"OCIContainer\",\n
146146
\ \"maxPods\": 250,\n \"type\": \"VirtualMachineScaleSets\",\n \"enableAutoScaling\":
147147
false,\n \"scaleDownMode\": \"Delete\",\n \"provisioningState\": \"Creating\",\n
@@ -1133,7 +1133,7 @@ interactions:
11331133
\"akssafegua-cli-000001-26fe00-ofss7i1d.hcp.westus2.staging.azmk8s.io\",\n
11341134
\ \"azurePortalFQDN\": \"akssafegua-cli-000001-26fe00-ofss7i1d.portal.hcp.westus2.staging.azmk8s.io\",\n
11351135
\ \"agentPoolProfiles\": [\n {\n \"name\": \"nodepool1\",\n \"count\":
1136-
3,\n \"vmSize\": \"standard_a8_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
1136+
3,\n \"vmSize\": \"Standard_DS2_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
11371137
\"Managed\",\n \"kubeletDiskType\": \"OS\",\n \"workloadRuntime\": \"OCIContainer\",\n
11381138
\ \"maxPods\": 250,\n \"type\": \"VirtualMachineScaleSets\",\n \"enableAutoScaling\":
11391139
false,\n \"scaleDownMode\": \"Delete\",\n \"provisioningState\": \"Succeeded\",\n

src/aks-preview/azext_aks_preview/tests/latest/recordings/test_aks_deployment_safeguards_with_pss.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ interactions:
9797
body: '{"location": "westus2", "sku": {"name": "Base", "tier": "Free"}, "identity":
9898
{"type": "SystemAssigned"}, "kind": "Base", "properties": {"kubernetesVersion":
9999
"", "dnsPrefix": "akspss-xbp-cli-000001-26fe00", "agentPoolProfiles": [{"count":
100-
3, "vmSize": "standard_a8_v2", "osDiskSizeGB": 0, "workloadRuntime": "OCIContainer",
100+
3, "vmSize": "Standard_DS2_v2", "osDiskSizeGB": 0, "workloadRuntime": "OCIContainer",
101101
"osType": "Linux", "enableAutoScaling": false, "type": "VirtualMachineScaleSets",
102102
"mode": "System", "orchestratorVersion": "", "upgradeSettings": {}, "upgradeSettingsBlueGreen":
103103
{}, "enableNodePublicIP": false, "scaleSetPriority": "Regular", "scaleSetEvictionPolicy":
@@ -140,7 +140,7 @@ interactions:
140140
\ \"fqdn\": \"akspss-xbp-cli-000001-26fe00-p47g5s9u.hcp.westus2.staging.azmk8s.io\",\n
141141
\ \"azurePortalFQDN\": \"akspss-xbp-cli-000001-26fe00-p47g5s9u.portal.hcp.westus2.staging.azmk8s.io\",\n
142142
\ \"agentPoolProfiles\": [\n {\n \"name\": \"nodepool1\",\n \"count\":
143-
3,\n \"vmSize\": \"standard_a8_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
143+
3,\n \"vmSize\": \"Standard_DS2_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
144144
\"Managed\",\n \"kubeletDiskType\": \"OS\",\n \"workloadRuntime\": \"OCIContainer\",\n
145145
\ \"maxPods\": 250,\n \"type\": \"VirtualMachineScaleSets\",\n \"enableAutoScaling\":
146146
false,\n \"scaleDownMode\": \"Delete\",\n \"provisioningState\": \"Creating\",\n
@@ -1327,7 +1327,7 @@ interactions:
13271327
\ \"fqdn\": \"akspss-xbp-cli-000001-26fe00-p47g5s9u.hcp.westus2.staging.azmk8s.io\",\n
13281328
\ \"azurePortalFQDN\": \"akspss-xbp-cli-000001-26fe00-p47g5s9u.portal.hcp.westus2.staging.azmk8s.io\",\n
13291329
\ \"agentPoolProfiles\": [\n {\n \"name\": \"nodepool1\",\n \"count\":
1330-
3,\n \"vmSize\": \"standard_a8_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
1330+
3,\n \"vmSize\": \"Standard_DS2_v2\",\n \"osDiskSizeGB\": 256,\n \"osDiskType\":
13311331
\"Managed\",\n \"kubeletDiskType\": \"OS\",\n \"workloadRuntime\": \"OCIContainer\",\n
13321332
\ \"maxPods\": 250,\n \"type\": \"VirtualMachineScaleSets\",\n \"enableAutoScaling\":
13331333
false,\n \"scaleDownMode\": \"Delete\",\n \"provisioningState\": \"Succeeded\",\n

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_aks_deployment_safeguards_basic(self):
4747
self.kwargs.update({
4848
'aks_name': self.create_random_name(prefix='akssafeguards-', length=20),
4949
'ssh_key_value': self.generate_ssh_keys(),
50-
'vm_size': 'standard_a8_v2'
50+
'vm_size': 'Standard_DS2_v2'
5151
})
5252

5353
# Create AKS cluster
@@ -101,7 +101,7 @@ def test_aks_deployment_safeguards_with_pss(self):
101101
self.kwargs.update({
102102
'aks_name': self.create_random_name(prefix='akspss-', length=15),
103103
'ssh_key_value': self.generate_ssh_keys(),
104-
'vm_size': 'standard_a8_v2'
104+
'vm_size': 'Standard_DS2_v2'
105105
})
106106

107107
# Create AKS cluster
@@ -155,7 +155,7 @@ def test_aks_deployment_safeguards_argument_validation(self):
155155
self.kwargs.update({
156156
'aks_name': self.create_random_name(prefix='aksval-', length=15),
157157
'ssh_key_value': self.generate_ssh_keys(),
158-
'vm_size': 'standard_a8_v2'
158+
'vm_size': 'Standard_DS2_v2'
159159
})
160160

161161
# Create AKS cluster

0 commit comments

Comments
 (0)