Skip to content

Commit f9a4685

Browse files
authored
AKS] az aks update: Fix bug where supportPlan can be reset to None (#27554)
1 parent c59fef9 commit f9a4685

File tree

2 files changed

+116
-9
lines changed

2 files changed

+116
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,17 +4706,13 @@ def get_k8s_support_plan(self) -> Union[str, None]:
47064706
47074707
:return: string or None
47084708
"""
4709-
# default to None
4710-
support_plan = None
4711-
# try to read the property value corresponding to the parameter from the `mc` object
4712-
if self.mc and hasattr(self.mc, "support_plan") and self.mc.support_plan is not None:
4713-
support_plan = self.mc.support_plan
4714-
4715-
# if specified by customer, use the specified value
4709+
# take input
47164710
support_plan = self.raw_param.get("k8s_support_plan")
4711+
if support_plan is None:
4712+
# user didn't update this property, load from existing ManagedCluster
4713+
if self.mc and hasattr(self.mc, "support_plan") and self.mc.support_plan is not None:
4714+
support_plan = self.mc.support_plan
47174715

4718-
# this parameter does not need dynamic completion
4719-
# this parameter does not need validation
47204716
return support_plan
47214717

47224718
def get_yes(self) -> bool:

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

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10467,5 +10467,116 @@ def test_update_http_proxy_config(self):
1046710467
)
1046810468
self.assertEqual(dec_mc_1, ground_truth_mc_1)
1046910469

10470+
def test_setup_supportPlan(self):
10471+
# default value in `aks_create`
10472+
ltsDecorator = AKSManagedClusterCreateDecorator(
10473+
self.cmd,
10474+
self.client,
10475+
{
10476+
"k8s_support_plan": "AKSLongTermSupport"
10477+
},
10478+
ResourceType.MGMT_CONTAINERSERVICE,
10479+
)
10480+
10481+
premiumSKU = self.models.ManagedClusterSKU(
10482+
name="Base",
10483+
tier="Premium")
10484+
premiumCluster = self.models.ManagedCluster(
10485+
location="test_location",
10486+
support_plan=None,
10487+
sku=premiumSKU,
10488+
)
10489+
ltsDecorator.context.attach_mc(premiumCluster)
10490+
10491+
# fail on passing the wrong mc object
10492+
with self.assertRaises(CLIInternalError):
10493+
ltsDecorator.set_up_k8s_support_plan(None)
10494+
10495+
ltsClusterCalculated = ltsDecorator.set_up_k8s_support_plan(premiumCluster)
10496+
expectedLTSCluster = self.models.ManagedCluster(
10497+
location="test_location",
10498+
support_plan="AKSLongTermSupport",
10499+
sku=premiumSKU,
10500+
)
10501+
self.assertEqual(ltsClusterCalculated, expectedLTSCluster)
10502+
10503+
nonLTSDecorator = AKSManagedClusterCreateDecorator(
10504+
self.cmd,
10505+
self.client,
10506+
{
10507+
"k8s_support_plan": "KubernetesOfficial"
10508+
},
10509+
ResourceType.MGMT_CONTAINERSERVICE,
10510+
)
10511+
nonLTSDecorator.context.attach_mc(premiumCluster)
10512+
nonLTSClusterCalculated = nonLTSDecorator.set_up_k8s_support_plan(premiumCluster)
10513+
expectedNonLTSCluster = self.models.ManagedCluster(
10514+
location="test_location",
10515+
support_plan="KubernetesOfficial",
10516+
sku=premiumSKU,
10517+
)
10518+
self.assertEqual(nonLTSClusterCalculated, expectedNonLTSCluster)
10519+
10520+
def test_update_supportPlan(self):
10521+
# default value in `aks_create`
10522+
noopDecorator = AKSManagedClusterUpdateDecorator(
10523+
self.cmd,
10524+
self.client,
10525+
{},
10526+
ResourceType.MGMT_CONTAINERSERVICE,
10527+
)
10528+
10529+
premiumSKU = self.models.ManagedClusterSKU(
10530+
name="Base",
10531+
tier="Premium")
10532+
ltsCluster = self.models.ManagedCluster(
10533+
location="test_location",
10534+
sku=premiumSKU,
10535+
support_plan="AKSLongTermSupport",
10536+
)
10537+
noopDecorator.context.attach_mc(ltsCluster)
10538+
10539+
# fail on passing the wrong mc object
10540+
with self.assertRaises(CLIInternalError):
10541+
noopDecorator.update_k8s_support_plan(None)
10542+
10543+
ltsClusterCalculated = noopDecorator.update_k8s_support_plan(ltsCluster)
10544+
self.assertEqual(ltsClusterCalculated, ltsCluster)
10545+
10546+
disableLTSDecorator = AKSManagedClusterUpdateDecorator(
10547+
self.cmd,
10548+
self.client,
10549+
{
10550+
"k8s_support_plan": "KubernetesOfficial"
10551+
},
10552+
ResourceType.MGMT_CONTAINERSERVICE,
10553+
)
10554+
disableLTSDecorator.context.attach_mc(ltsCluster)
10555+
nonLTSClusterCalculated = disableLTSDecorator.update_k8s_support_plan(ltsCluster)
10556+
expectedNonLTSCluster = self.models.ManagedCluster(
10557+
location="test_location",
10558+
support_plan="KubernetesOfficial",
10559+
sku=premiumSKU,
10560+
)
10561+
self.assertEqual(nonLTSClusterCalculated, expectedNonLTSCluster)
10562+
10563+
normalCluster = self.models.ManagedCluster(
10564+
location="test_location",
10565+
sku=self.models.ManagedClusterSKU(
10566+
name="Base",
10567+
tier="Standard"),
10568+
support_plan="KubernetesOfficial",
10569+
)
10570+
noopDecorator3 = AKSManagedClusterUpdateDecorator(
10571+
self.cmd,
10572+
self.client,
10573+
{},
10574+
ResourceType.MGMT_CONTAINERSERVICE,
10575+
)
10576+
noopDecorator3.context.attach_mc(normalCluster)
10577+
normalClusterCalculated = noopDecorator3.update_k8s_support_plan(normalCluster)
10578+
self.assertEqual(normalClusterCalculated, normalCluster)
10579+
10580+
1047010581
if __name__ == "__main__":
1047110582
unittest.main()

0 commit comments

Comments
 (0)