Skip to content

Commit 9a8aa57

Browse files
authored
[AKS] az aks namespace update: Fix the location logic for managed namespace update operation (#33054)
1 parent 88958c7 commit 9a8aa57

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def aks_managed_namespace_update(cmd, client, raw_parameters, headers, existedNa
201201
namespace_name = raw_parameters.get("name")
202202

203203
namespace_config = updateNamespace(cmd, raw_parameters, existedNamespace)
204-
namespace_config.location = get_cluster_location(cmd, resource_group_name, cluster_name)
204+
namespace_config.location = existedNamespace.location
205205

206206
return sdk_no_wait(
207207
no_wait,

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managednamespace.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,51 @@ def test_update_managed_namespace_with_invalid_delete_policy(self, mock_get_clie
275275
ns.aks_managed_namespace_update(cmd, None, raw_parameters, None, None, False)
276276
self.assertIn(err, str(cm.exception))
277277

278+
def test_update_managed_namespace_sets_location_from_existing_namespace(self, mock_get_client):
279+
cli_ctx = MockCLI()
280+
cmd = MockCmd(cli_ctx)
281+
282+
mock_client = Mock()
283+
284+
existing_ns = Mock()
285+
existing_ns.name = "test_managed_namespace"
286+
existing_ns.location = "westus2"
287+
existing_ns.properties.default_resource_quota.cpu_request = "300m"
288+
existing_ns.properties.default_resource_quota.cpu_limit = "500m"
289+
existing_ns.properties.default_resource_quota.memory_request = "1Gi"
290+
existing_ns.properties.default_resource_quota.memory_limit = "2Gi"
291+
existing_ns.properties.default_network_policy.ingress = "DenyAll"
292+
existing_ns.properties.default_network_policy.egress = "AllowAll"
293+
existing_ns.properties.adoption_policy = "Never"
294+
existing_ns.properties.delete_policy = "Keep"
295+
296+
raw_parameters = {
297+
"resource_group_name": "test_rg",
298+
"cluster_name": "test_cluster",
299+
"name": "test_managed_namespace",
300+
"tags": {},
301+
"labels": None,
302+
"annotations": ["a=c"],
303+
"cpu_request": None,
304+
"cpu_limit": None,
305+
"memory_request": None,
306+
"memory_limit": None,
307+
"ingress_policy": None,
308+
"egress_policy": None,
309+
"adoption_policy": None,
310+
"delete_policy": None,
311+
}
312+
313+
ns.aks_managed_namespace_update(cmd, mock_client, raw_parameters, None, existing_ns, False)
314+
315+
# The namespace that passed to begin_create_or_update should carry the existing location
316+
call_args = mock_client.begin_create_or_update.call_args
317+
namespace_config = call_args[0][3] # 4th positional arg
318+
self.assertEqual(namespace_config.location, "westus2")
319+
320+
# No managed cluster GET should be needed for the update path
321+
mock_get_client.assert_not_called()
322+
278323

279324
if __name__ == "__main__":
280325
unittest.main()

0 commit comments

Comments
 (0)