Skip to content

Commit

Permalink
{AKS} Fix regression of option --uptime-sla and --no-uptime-sla c…
Browse files Browse the repository at this point in the history
…aused by change in #7478 (#7510)
  • Loading branch information
FumingZhang authored Apr 17, 2024
1 parent 480501f commit fbae3ee
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

3.0.0b4
+++++++
* Fix the issue that option `--uptime-sla` is ignored in command `az aks create`.
* Fix the issue that option `--uptime-sla` and `--no-uptime-sla` are ignored in command `az aks update`.

3.0.0b3
+++++++
* Add `--nodepool-initialization-taints` to `az aks create` and `az aks update`.
Expand Down
35 changes: 19 additions & 16 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3211,21 +3211,26 @@ def set_up_sku(self, mc: ManagedCluster) -> ManagedCluster:

mc.sku = self.models.ManagedClusterSKU()
skuName = self.context.get_sku_name()
if skuName is not None and skuName == CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC:
tier = self.context.get_tier()
if skuName == CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC:
mc.sku.name = "Automatic"
# passive Kind should always to match sku.name
mc.kind = "Automatic"

# default tier for automatic sku is standard
mc.sku.tier = "Standard"
else:
mc.sku.name = "Base"
# passive Kind should always match sku.name
mc.kind = "Base"
mc.sku.tier = "Free"
if self.context.get_uptime_sla() or self.context.get_tier() == CONST_MANAGED_CLUSTER_SKU_TIER_STANDARD:
mc.sku.tier = "Standard"

if self.context.get_tier() == CONST_MANAGED_CLUSTER_SKU_TIER_PREMIUM:
if self.context.get_uptime_sla() or tier == CONST_MANAGED_CLUSTER_SKU_TIER_STANDARD:
mc.sku.tier = "Standard"
if tier == CONST_MANAGED_CLUSTER_SKU_TIER_PREMIUM:
mc.sku.tier = "Premium"
# backfill the tier to "Free" if it's not set
if mc.sku.tier is None:
mc.sku.tier = "Free"
return mc

def set_up_k8s_support_plan(self, mc: ManagedCluster) -> ManagedCluster:
Expand Down Expand Up @@ -4498,13 +4503,10 @@ def update_sku(self, mc: ManagedCluster) -> ManagedCluster:

# there are existing MCs with nil sku, that is Base/Free
if mc.sku is None:
mc.sku = self.models.ManagedClusterSKU(
sku="Base",
tier="Free",
)
mc.sku = self.models.ManagedClusterSKU()
skuName = self.context.get_sku_name()

if skuName is not None and skuName == CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC:
tier = self.context.get_tier()
if skuName == CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC:
mc.sku.name = "Automatic"
# passive Kind should always to match sku.name
mc.kind = "Automatic"
Expand All @@ -4514,13 +4516,14 @@ def update_sku(self, mc: ManagedCluster) -> ManagedCluster:
mc.kind = "Base"

# Premium without LTS is ok (not vice versa)
if self.context.get_tier() == CONST_MANAGED_CLUSTER_SKU_TIER_PREMIUM:
if tier == CONST_MANAGED_CLUSTER_SKU_TIER_PREMIUM:
mc.sku.tier = "Premium"

if self.context.get_uptime_sla() or self.context.get_tier() == CONST_MANAGED_CLUSTER_SKU_TIER_STANDARD:
if self.context.get_uptime_sla() or tier == CONST_MANAGED_CLUSTER_SKU_TIER_STANDARD:
mc.sku.tier = "Standard"

if self.context.get_no_uptime_sla() or self.context.get_tier() == CONST_MANAGED_CLUSTER_SKU_TIER_FREE:
if self.context.get_no_uptime_sla() or tier == CONST_MANAGED_CLUSTER_SKU_TIER_FREE:
mc.sku.tier = "Free"
# backfill the tier to "Free" if it's not set
if mc.sku.tier is None:
mc.sku.tier = "Free"
return mc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5218,6 +5218,26 @@ def test_set_up_sku(self):
)
self.assertEqual(dec_mc_2, expect_mc_2)

dec_3 = AKSPreviewManagedClusterCreateDecorator(
self.cmd,
self.client,
{"uptime_sla": True},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_3 = self.models.ManagedCluster(
location="test_location",
sku=None,
)
dec_3.context.attach_mc(mc_3)
dec_mc_3 = dec_3.set_up_sku(mc_3)
baseSKU = self.models.ManagedClusterSKU(name="Base", tier="Standard")
expect_mc_3 = self.models.ManagedCluster(
location="test_location",
sku=baseSKU,
kind="Base",
)
self.assertEqual(dec_mc_3, expect_mc_3)


class AKSPreviewManagedClusterUpdateDecoratorTestCase(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -8289,6 +8309,83 @@ def test_update_sku(self):
)
self.assertEqual(dec_mc_2, expect_mc_2)

dec_3 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
self.client,
{
"uptime_sla": True,
"no_uptime_sla": True,
},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_3 = self.models.ManagedCluster(
location="test_location",
sku=self.models.ManagedClusterSKU(
name="Base",
tier="Free",
),
)
dec_3.context.attach_mc(mc_3)
# fail on mutually exclusive uptime_sla and no_uptime_sla
with self.assertRaises(MutuallyExclusiveArgumentError):
dec_3.update_sku(mc_3)

dec_4 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
self.client,
{
"uptime_sla": False,
"no_uptime_sla": True,
},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_4 = self.models.ManagedCluster(
location="test_location",
sku=self.models.ManagedClusterSKU(
name="Base",
tier="Standard",
),
)
dec_4.context.attach_mc(mc_4)
dec_mc_4 = dec_4.update_sku(mc_4)
ground_truth_mc_4 = self.models.ManagedCluster(
location="test_location",
sku=self.models.ManagedClusterSKU(
name="Base",
tier="Free",
),
kind="Base",
)
self.assertEqual(dec_mc_4, ground_truth_mc_4)

dec_5 = AKSPreviewManagedClusterUpdateDecorator(
self.cmd,
self.client,
{
"uptime_sla": True,
"no_uptime_sla": False,
},
CUSTOM_MGMT_AKS_PREVIEW,
)
mc_5 = self.models.ManagedCluster(
location="test_location",
sku=self.models.ManagedClusterSKU(
name="Base",
tier="Free",
),
)
dec_5.context.attach_mc(mc_5)
dec_mc_5 = dec_5.update_sku(mc_5)
ground_truth_mc_5 = self.models.ManagedCluster(
location="test_location",
sku=self.models.ManagedClusterSKU(
name="Base",
tier="Standard",
),
kind="Base",
)
self.assertEqual(dec_mc_5, ground_truth_mc_5)

def test_setup_supportPlan(self):
# default value in `aks_create`
ltsDecorator = AKSPreviewManagedClusterCreateDecorator(
Expand Down
2 changes: 1 addition & 1 deletion src/aks-preview/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from setuptools import setup, find_packages

VERSION = "3.0.0b3"
VERSION = "3.0.0b4"

CLASSIFIERS = [
"Development Status :: 4 - Beta",
Expand Down

0 comments on commit fbae3ee

Please sign in to comment.