Skip to content

Commit

Permalink
Prompt when disabling CSI Drivers (#4868)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMagic committed Jun 2, 2022
1 parent 33a77ae commit d47de83
Show file tree
Hide file tree
Showing 10 changed files with 916 additions and 1,001 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
+++++++

0.5.78
++++++

* Prompt when disabling CSI Drivers.

0.5.77
++++++

Expand Down
20 changes: 10 additions & 10 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def load_arguments(self, _):
c.argument('gmsa_root_domain_name')
c.argument('attach_acr', acr_arg_type)
c.argument('skip_subnet_role_assignment', action='store_true')
c.argument('disk_driver_version', arg_type=get_enum_type(disk_driver_versions))
c.argument('disable_disk_driver', action='store_true')
c.argument('disable_file_driver', action='store_true')
c.argument('disable_snapshot_controller', action='store_true')
# addons
c.argument('enable_addons', options_list=['--enable-addons', '-a'], validator=validate_addons)
c.argument('workspace_resource_id')
Expand Down Expand Up @@ -272,10 +276,6 @@ def load_arguments(self, _):
c.argument('enable_fips_image', action='store_true')
c.argument('kubelet_config')
c.argument('linux_os_config')
c.argument('disk_driver_version', arg_type=get_enum_type(disk_driver_versions))
c.argument('disable_disk_driver', arg_type=get_three_state_flag())
c.argument('disable_file_driver', arg_type=get_three_state_flag())
c.argument('disable_snapshot_controller', arg_type=get_three_state_flag())
c.argument('yes', options_list=[
'--yes', '-y'], help='Do not prompt for confirmation.', action='store_true')
c.argument('aks_custom_headers')
Expand Down Expand Up @@ -340,13 +340,13 @@ def load_arguments(self, _):
c.argument('enable_windows_gmsa', action='store_true')
c.argument('gmsa_dns_server')
c.argument('gmsa_root_domain_name')
c.argument('enable_disk_driver', arg_type=get_three_state_flag())
c.argument('enable_disk_driver', action='store_true')
c.argument('disk_driver_version', arg_type=get_enum_type(disk_driver_versions))
c.argument('disable_disk_driver', arg_type=get_three_state_flag())
c.argument('enable_file_driver', arg_type=get_three_state_flag())
c.argument('disable_file_driver', arg_type=get_three_state_flag())
c.argument('enable_snapshot_controller', arg_type=get_three_state_flag())
c.argument('disable_snapshot_controller', arg_type=get_three_state_flag())
c.argument('disable_disk_driver', action='store_true')
c.argument('enable_file_driver', action='store_true')
c.argument('disable_file_driver', action='store_true')
c.argument('enable_snapshot_controller', action='store_true')
c.argument('disable_snapshot_controller', action='store_true')
c.argument('attach_acr', acr_arg_type, validator=validate_acr)
c.argument('detach_acr', acr_arg_type, validator=validate_acr)
# addons
Expand Down
18 changes: 9 additions & 9 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,9 @@ def aks_create(cmd,
edge_zone=None,
enable_secret_rotation=False,
disk_driver_version=None,
disable_disk_driver=None,
disable_file_driver=None,
disable_snapshot_controller=None,
disable_disk_driver=False,
disable_file_driver=False,
disable_snapshot_controller=False,
rotation_poll_interval=None,
disable_local_accounts=False,
no_wait=False,
Expand Down Expand Up @@ -880,13 +880,13 @@ def aks_update(cmd, # pylint: disable=too-many-statements,too-many-branches,
enable_secret_rotation=False,
disable_secret_rotation=False,
rotation_poll_interval=None,
enable_disk_driver=None,
enable_disk_driver=False,
disk_driver_version=None,
disable_disk_driver=None,
enable_file_driver=None,
disable_file_driver=None,
enable_snapshot_controller=None,
disable_snapshot_controller=None,
disable_disk_driver=False,
enable_file_driver=False,
disable_file_driver=False,
enable_snapshot_controller=False,
disable_snapshot_controller=False,
disable_local_accounts=False,
enable_local_accounts=False,
enable_public_fqdn=False,
Expand Down
21 changes: 17 additions & 4 deletions src/aks-preview/azext_aks_preview/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1717,13 +1717,14 @@ def get_node_vm_size(self) -> str:
return self._get_node_vm_size()

def get_disk_driver(self) -> Optional[ManagedClusterStorageProfileDiskCSIDriver]:
"""Obtrain the value of storage_profile.disk_csi_driver
"""Obtain the value of storage_profile.disk_csi_driver
:return: Optional[ManagedClusterStorageProfileDiskCSIDriver]
"""
enable_disk_driver = self.raw_param.get("enable_disk_driver")
disable_disk_driver = self.raw_param.get("disable_disk_driver")
disk_driver_version = self.raw_param.get("disk_driver_version")

if not enable_disk_driver and not disable_disk_driver and not disk_driver_version:
return None
profile = self.models.ManagedClusterStorageProfileDiskCSIDriver()
Expand Down Expand Up @@ -1759,17 +1760,21 @@ def get_disk_driver(self) -> Optional[ManagedClusterStorageProfileDiskCSIDriver]
if disk_driver_version:
profile.version = disk_driver_version
elif disable_disk_driver:
msg = "Please make sure there are no existing PVs and PVCs that are used by AzureDisk CSI driver before disabling."
if not self.get_yes() and not prompt_y_n(msg, default="n"):
raise DecoratorEarlyExitException()
profile.enabled = False

return profile

def get_file_driver(self) -> Optional[ManagedClusterStorageProfileFileCSIDriver]:
"""Obtrain the value of storage_profile.file_csi_driver
"""Obtain the value of storage_profile.file_csi_driver
:return: 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()
Expand All @@ -1790,17 +1795,21 @@ def get_file_driver(self) -> Optional[ManagedClusterStorageProfileFileCSIDriver]
if enable_file_driver:
profile.enabled = True
elif disable_file_driver:
msg = "Please make sure there are no existing PVs and PVCs that are used by AzureFile CSI driver before disabling."
if not self.get_yes() and not prompt_y_n(msg, default="n"):
raise DecoratorEarlyExitException()
profile.enabled = False

return profile

def get_snapshot_controller(self) -> Optional[ManagedClusterStorageProfileSnapshotController]:
"""Obtrain the value of storage_profile.snapshot_controller
"""Obtain the value of storage_profile.snapshot_controller
:return: Optional[ManagedClusterStorageProfileSnapshotController]
"""
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

Expand All @@ -1822,12 +1831,16 @@ def get_snapshot_controller(self) -> Optional[ManagedClusterStorageProfileSnapsh
if enable_snapshot_controller:
profile.enabled = True
elif disable_snapshot_controller:
msg = "Please make sure there are no existing VolumeSnapshots, VolumeSnapshotClasses and VolumeSnapshotContents " \
"that are used by the snapshot controller before disabling."
if not self.get_yes() and not prompt_y_n(msg, default="n"):
raise DecoratorEarlyExitException()
profile.enabled = False

return profile

def get_storage_profile(self) -> Optional[ManagedClusterStorageProfile]:
"""Obtrain the value of storage_profile.
"""Obtain the value of storage_profile.
:return: Optional[ManagedClusterStorageProfile]
"""
Expand Down
Loading

0 comments on commit d47de83

Please sign in to comment.