From c76276834b2494469b55fc3610edffb34503d9de Mon Sep 17 00:00:00 2001 From: Fuming Zhang Date: Fri, 18 Nov 2022 13:21:34 +0800 Subject: [PATCH 1/4] bug fix --- .../managed_cluster_decorator.py | 11 ++++++-- .../latest/test_managed_cluster_decorator.py | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py index b3a126b3c74..c80be663059 100644 --- a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py +++ b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py @@ -3176,14 +3176,21 @@ def update_linux_profile(self, mc: ManagedCluster) -> ManagedCluster: ssh_key_value = self.context.get_ssh_key_value_for_update() if ssh_key_value: - mc.linux_profile.ssh = self.models.ContainerServiceSshConfiguration( + ssh_config = self.models.ContainerServiceSshConfiguration( public_keys=[ self.models.ContainerServiceSshPublicKey( key_data=ssh_key_value ) ] ) - + # apply default linux profile if not set when created + if mc.linux_profile == None: + mc.linux_profile = self.models.ContainerServiceLinuxProfile( + admin_username=self.context.get_admin_username(), + ssh=ssh_config, + ) + else: + mc.linux_profile.ssh = ssh_config return mc def update_mc_profile_preview(self) -> ManagedCluster: diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py b/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py index 152a1b59684..04ae563c5d1 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py +++ b/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py @@ -5804,6 +5804,34 @@ def test_update_azure_monitor_profile(self): ) self.assertEqual(dec_mc_1, ground_truth_mc_1) + def test_update_linux_profile(self): + dec_1 = AKSPreviewManagedClusterUpdateDecorator( + self.cmd, + self.client, + {"ssh_key_value": "test_key"}, + CUSTOM_MGMT_AKS_PREVIEW, + ) + mc_1 = self.models.ManagedCluster( + location="test_location", + ) + dec_1.context.attach_mc(mc_1) + dec_mc_1 = dec_1.update_linux_profile(mc_1) + + ground_truth_mc_1 = self.models.ManagedCluster( + location="test_location", + linux_profile=self.models.ContainerServiceLinuxProfile( + admin_username=None, + ssh=self.models.ContainerServiceSshConfiguration( + public_keys=[ + self.models.ContainerServiceSshPublicKey( + key_data="test_key" + ) + ] + ), + ), + ) + self.assertEqual(dec_mc_1, ground_truth_mc_1) + def test_update_mc_profile_preview(self): import inspect From dcde924efe089058ca932022ccc7edd89da161a1 Mon Sep 17 00:00:00 2001 From: Fuming Zhang Date: Fri, 18 Nov 2022 14:22:08 +0800 Subject: [PATCH 2/4] raise error --- .../managed_cluster_decorator.py | 12 +++--------- .../latest/test_managed_cluster_decorator.py | 19 +++---------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py index c80be663059..49cbfda05ea 100644 --- a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py +++ b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py @@ -3176,21 +3176,15 @@ def update_linux_profile(self, mc: ManagedCluster) -> ManagedCluster: ssh_key_value = self.context.get_ssh_key_value_for_update() if ssh_key_value: - ssh_config = self.models.ContainerServiceSshConfiguration( + if mc.linux_profile == None: + raise InvalidArgumentValueError("Updating the cluster with no ssh key set at creation is not supported") + mc.linux_profile.ssh = self.models.ContainerServiceSshConfiguration( public_keys=[ self.models.ContainerServiceSshPublicKey( key_data=ssh_key_value ) ] ) - # apply default linux profile if not set when created - if mc.linux_profile == None: - mc.linux_profile = self.models.ContainerServiceLinuxProfile( - admin_username=self.context.get_admin_username(), - ssh=ssh_config, - ) - else: - mc.linux_profile.ssh = ssh_config return mc def update_mc_profile_preview(self) -> ManagedCluster: diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py b/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py index 04ae563c5d1..b3e4f17b4e0 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py +++ b/src/aks-preview/azext_aks_preview/tests/latest/test_managed_cluster_decorator.py @@ -5815,22 +5815,9 @@ def test_update_linux_profile(self): location="test_location", ) dec_1.context.attach_mc(mc_1) - dec_mc_1 = dec_1.update_linux_profile(mc_1) - - ground_truth_mc_1 = self.models.ManagedCluster( - location="test_location", - linux_profile=self.models.ContainerServiceLinuxProfile( - admin_username=None, - ssh=self.models.ContainerServiceSshConfiguration( - public_keys=[ - self.models.ContainerServiceSshPublicKey( - key_data="test_key" - ) - ] - ), - ), - ) - self.assertEqual(dec_mc_1, ground_truth_mc_1) + # fail on cluster has no linux profile + with self.assertRaises(InvalidArgumentValueError): + dec_mc_1 = dec_1.update_linux_profile(mc_1) def test_update_mc_profile_preview(self): import inspect From 41e47d21dbc1356a0a0262e815be7e00bcb8d9ba Mon Sep 17 00:00:00 2001 From: Fuming Zhang Date: Fri, 18 Nov 2022 14:25:09 +0800 Subject: [PATCH 3/4] fix lint --- src/aks-preview/azext_aks_preview/managed_cluster_decorator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py index 49cbfda05ea..1eb2f83004c 100644 --- a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py +++ b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py @@ -3176,7 +3176,7 @@ def update_linux_profile(self, mc: ManagedCluster) -> ManagedCluster: ssh_key_value = self.context.get_ssh_key_value_for_update() if ssh_key_value: - if mc.linux_profile == None: + if mc.linux_profile is None: raise InvalidArgumentValueError("Updating the cluster with no ssh key set at creation is not supported") mc.linux_profile.ssh = self.models.ContainerServiceSshConfiguration( public_keys=[ From 9d811eb232f77a2ee0fb0e3bd4fd83ce8ac6dc78 Mon Sep 17 00:00:00 2001 From: Fuming Zhang Date: Fri, 18 Nov 2022 14:32:21 +0800 Subject: [PATCH 4/4] update history --- src/aks-preview/HISTORY.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/aks-preview/HISTORY.rst b/src/aks-preview/HISTORY.rst index be9d2d190af..d9b98ef628f 100644 --- a/src/aks-preview/HISTORY.rst +++ b/src/aks-preview/HISTORY.rst @@ -12,6 +12,7 @@ To release a new version, please select a new version number (usually plus 1 to Pending +++++++ +* Fix `az aks update` command failing on updating the ssh key value if cluster was created without ssh key, see issue `\#5559 `_. * Mark "--enable-pod-security-policy" deprecated 0.5.115 @@ -28,7 +29,7 @@ Pending +++++++ * Fix workload identity update error after oidc issure GA in azure-cli. -* Fix `az aks update` command failing on SP-based cluster blocked by validation in AzureMonitorMetrics Addon, see issue `\#5336 `_. +* Fix `az aks update` command failing on SP-based cluster blocked by validation in AzureMonitorMetrics Addon, see issue `\#5488 `_. * Fix `az aks update` command failing on changes not related to outbound type conversion, see issue `\#24430 https://github.com/Azure/azure-cli/issues/24430>`_. 0.5.112