Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AKS]fix: don't update storageProfile if not set #4817

Merged
merged 8 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

0.5.70
++++++
* Fix: Don't update storageProfile if not set .

0.5.69
++++++
* Fix: Raise error when user provides invalid value for `--os-sku`.
Expand Down
7 changes: 7 additions & 0 deletions src/aks-preview/azext_aks_preview/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,8 @@ def get_disk_driver(self) -> Optional[ManagedClusterStorageProfileDiskCSIDriver]
"""
enable_disk_driver = self.raw_param.get("enable_disk_driver")
disable_disk_driver = self.raw_param.get("disable_disk_driver")
if not enable_disk_driver and not disable_disk_driver:
return None
profile = self.models.ManagedClusterStorageProfileDiskCSIDriver()

if enable_disk_driver and disable_disk_driver:
Expand Down Expand Up @@ -1713,6 +1715,8 @@ def get_file_driver(self) -> Optional[ManagedClusterStorageProfileFileCSIDriver]
"""
enable_file_driver = self.raw_param.get("enable_file_driver")
disable_file_driver = self.raw_param.get("disable_file_driver")
if not enable_file_driver and not disable_file_driver:
return None
profile = self.models.ManagedClusterStorageProfileFileCSIDriver()

if enable_file_driver and disable_file_driver:
Expand Down Expand Up @@ -1742,6 +1746,9 @@ def get_snapshot_controller(self) -> Optional[ManagedClusterStorageProfileSnapsh
"""
enable_snapshot_controller = self.raw_param.get("enable_snapshot_controller")
disable_snapshot_controller = self.raw_param.get("disable_snapshot_controller")
if not enable_snapshot_controller and not disable_snapshot_controller:
return None

profile = self.models.ManagedClusterStorageProfileSnapshotController()

if enable_snapshot_controller and disable_snapshot_controller:
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4063,6 +4063,16 @@ def test_aks_create_and_update_with_csi_drivers_extensibility(self, resource_gro
self.check('storageProfile.snapshotController.enabled', False),
])

# check standard reconcile scenario
update_cmd = 'aks update --resource-group={resource_group} --name={name} -y -o json'
self.cmd(update_cmd
, checks=[
self.check('provisioningState', 'Succeeded'),
self.check('storageProfile.diskCsiDriver.enabled', False),
self.check('storageProfile.fileCsiDriver.enabled', False),
self.check('storageProfile.snapshotController.enabled', False),
])

enable_cmd = 'aks update --resource-group={resource_group} --name={name} -o json \
--enable-disk-driver \
--enable-file-driver \
Expand All @@ -4074,6 +4084,16 @@ def test_aks_create_and_update_with_csi_drivers_extensibility(self, resource_gro
self.check('storageProfile.snapshotController.enabled', True),
])

# check standard reconcile scenario
update_cmd = 'aks update --resource-group={resource_group} --name={name} -y -o json'
self.cmd(update_cmd
, checks=[
self.check('provisioningState', 'Succeeded'),
self.check('storageProfile.diskCsiDriver.enabled', True),
self.check('storageProfile.fileCsiDriver.enabled', True),
self.check('storageProfile.snapshotController.enabled', True),
])

disable_cmd = 'aks update --resource-group={resource_group} --name={name} -o json \
--disable-disk-driver \
--disable-file-driver \
Expand Down Expand Up @@ -4105,9 +4125,18 @@ def test_aks_create_with_standard_csi_drivers(self, resource_group, resource_gro
create_cmd = 'aks create --resource-group={resource_group} --name={name} --ssh-key-value={ssh_key_value} -o json'
self.cmd(create_cmd, checks=[
self.check('provisioningState', 'Succeeded'),
self.check('storageProfile.diskCsiDriver.enabled', True),
self.check('storageProfile.fileCsiDriver.enabled', True),
self.check('storageProfile.snapshotController.enabled', True),
self.check('storageProfile.diskCsiDriver.enabled', None),
self.check('storageProfile.fileCsiDriver.enabled', None),
self.check('storageProfile.snapshotController.enabled', None),
])

# check standard reconcile scenario
update_cmd = 'aks update --resource-group={resource_group} --name={name} -y -o json'
self.cmd(update_cmd, checks=[
self.check('provisioningState', 'Succeeded'),
self.check('storageProfile.diskCsiDriver', None),
self.check('storageProfile.fileCsiDriver', None),
self.check('storageProfile.snapshotController', None),
])

# delete
Expand Down
152 changes: 136 additions & 16 deletions src/aks-preview/azext_aks_preview/tests/latest/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,83 @@ def test_get_nat_gateway_idle_timeout(self):
ctx_1.attach_mc(mc)
self.assertEqual(ctx_1.get_nat_gateway_idle_timeout(), 20)

def test_get_disk_driver(self):
def test_get_disk_driver_update(self):
# default
ctx_1 = AKSPreviewContext(
self.cmd,
{},
self.models,
decorator_mode=DecoratorMode.UPDATE,
)
storage_profile = (
self.models.ManagedClusterStorageProfile(
disk_csi_driver = None,
file_csi_driver = None,
snapshot_controller = None,
)
)
mc = self.models.ManagedCluster(
location="test_location",
storage_profile=storage_profile,
)
ctx_1.attach_mc(mc)
self.assertEqual(
ctx_1.get_storage_profile(), storage_profile
)

# custom disk value
ctx_2 = AKSPreviewContext(
self.cmd,
{
"enable_disk_driver": True,
"disable_disk_driver": True,
},
self.models,
decorator_mode=DecoratorMode.UPDATE,
)
# fail on mutually exclusive enable_disk_driver and disable_disk_driver
with self.assertRaises(MutuallyExclusiveArgumentError):
ctx_2.get_disk_driver()

# custom file alue
ctx_3 = AKSPreviewContext(
self.cmd,
{
"enable_file_driver": True,
"disable_file_driver": True,
},
self.models,
decorator_mode=DecoratorMode.UPDATE,
)
# fail on mutually exclusive enable_file_driver and disable_file_driver
with self.assertRaises(MutuallyExclusiveArgumentError):
ctx_3.get_file_driver()

# custom file alue
ctx_4 = AKSPreviewContext(
self.cmd,
{
"enable_snapshot_controller": True,
"disable_snapshot_controller": True,
},
self.models,
decorator_mode=DecoratorMode.UPDATE,
)
# fail on mutually exclusive enable_snapshot_controller and disable_snapshot_controller
with self.assertRaises(MutuallyExclusiveArgumentError):
ctx_4.get_snapshot_controller()

# default with csi driver enabled flag
ctx_5 = AKSPreviewContext(
self.cmd,
{
"enable_disk_driver": True,
"enable_file_driver": True,
"enable_snapshot_controller": True,
},
self.models,
decorator_mode=DecoratorMode.UPDATE,
)
storage_profile = (
self.models.ManagedClusterStorageProfile(
disk_csi_driver = self.models.ManagedClusterStorageProfileDiskCSIDriver(
Expand All @@ -820,6 +889,30 @@ def test_get_disk_driver(self):
location="test_location",
storage_profile=storage_profile,
)
ctx_5.attach_mc(mc)
self.assertEqual(
ctx_5.get_storage_profile(), storage_profile
)

def test_get_disk_driver_create(self):
# default
ctx_1 = AKSPreviewContext(
self.cmd,
{},
self.models,
decorator_mode=DecoratorMode.CREATE,
)
storage_profile = (
self.models.ManagedClusterStorageProfile(
disk_csi_driver = None,
file_csi_driver = None,
snapshot_controller = None,
)
)
mc = self.models.ManagedCluster(
location="test_location",
storage_profile=storage_profile,
)
ctx_1.attach_mc(mc)
self.assertEqual(
ctx_1.get_storage_profile(), storage_profile
Expand All @@ -833,7 +926,7 @@ def test_get_disk_driver(self):
"disable_disk_driver": True,
},
self.models,
decorator_mode=DecoratorMode.UPDATE,
decorator_mode=DecoratorMode.CREATE,
)
# fail on mutually exclusive enable_disk_driver and disable_disk_driver
with self.assertRaises(MutuallyExclusiveArgumentError):
Expand All @@ -847,7 +940,7 @@ def test_get_disk_driver(self):
"disable_file_driver": True,
},
self.models,
decorator_mode=DecoratorMode.UPDATE,
decorator_mode=DecoratorMode.CREATE,
)
# fail on mutually exclusive enable_file_driver and disable_file_driver
with self.assertRaises(MutuallyExclusiveArgumentError):
Expand All @@ -861,12 +954,45 @@ def test_get_disk_driver(self):
"disable_snapshot_controller": True,
},
self.models,
decorator_mode=DecoratorMode.UPDATE,
decorator_mode=DecoratorMode.CREATE,
)
# fail on mutually exclusive enable_snapshot_controller and disable_snapshot_controller
with self.assertRaises(MutuallyExclusiveArgumentError):
ctx_4.get_snapshot_controller()

# default with csi driver enabled flag
ctx_5 = AKSPreviewContext(
self.cmd,
{
"enable_disk_driver": True,
"enable_file_driver": True,
"enable_snapshot_controller": True,
},
self.models,
decorator_mode=DecoratorMode.CREATE,
)
storage_profile = (
self.models.ManagedClusterStorageProfile(
disk_csi_driver = self.models.ManagedClusterStorageProfileDiskCSIDriver(
enabled = True,
),
file_csi_driver = self.models.ManagedClusterStorageProfileFileCSIDriver(
enabled = True,
),
snapshot_controller = self.models.ManagedClusterStorageProfileSnapshotController(
enabled = True,
),
)
)
mc = self.models.ManagedCluster(
location="test_location",
storage_profile=storage_profile,
)
ctx_5.attach_mc(mc)
self.assertEqual(
ctx_5.get_storage_profile(), storage_profile
)

def test_get_enable_pod_security_policy(self):
# default
ctx_1 = AKSPreviewContext(
Expand Down Expand Up @@ -3429,15 +3555,9 @@ def test_construct_mc_preview_profile(self):
identity_1 = self.models.ManagedClusterIdentity(type="SystemAssigned")

storage_profile_1 = self.models.ManagedClusterStorageProfile(
disk_csi_driver = self.models.ManagedClusterStorageProfileDiskCSIDriver(
enabled=True,
),
file_csi_driver = self.models.ManagedClusterStorageProfileFileCSIDriver(
enabled=True,
),
snapshot_controller = self.models.ManagedClusterStorageProfileSnapshotController(
enabled=True,
),
disk_csi_driver = None,
file_csi_driver = None,
snapshot_controller = None,
)

ground_truth_mc_1 = self.models.ManagedCluster(
Expand Down Expand Up @@ -4814,9 +4934,9 @@ def test_update_mc_preview_profile(self):
)
}
ground_truth_storage_profile_1=self.models.ManagedClusterStorageProfile(
disk_csi_driver = self.models.ManagedClusterStorageProfileDiskCSIDriver(),
file_csi_driver = self.models.ManagedClusterStorageProfileFileCSIDriver(),
snapshot_controller = self.models.ManagedClusterStorageProfileSnapshotController(),
disk_csi_driver = None,
file_csi_driver = None,
snapshot_controller = None
)
ground_truth_mc_1 = self.models.ManagedCluster(
location="test_location",
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 = "0.5.69"
VERSION = "0.5.70"
CLASSIFIERS = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand Down