Skip to content

Commit 6c77be6

Browse files
committed
[AKS] az aks create/update: Add distributedcache storage option to --enable/--disable-azure-container-storage
1 parent 2737399 commit 6c77be6

8 files changed

Lines changed: 571 additions & 5 deletions

File tree

src/aks-preview/HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ To release a new version, please select a new version number (usually plus 1 to
1111

1212
Pending
1313
+++++++
14+
* `az aks create/update`: Add `distributedcache` storage option to `--enable-azure-container-storage` and `--disable-azure-container-storage` to install/uninstall the Azure Container Storage distributed cache controller.
1415

1516
21.0.0b10
1617
++++++++

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
CONST_STORAGE_POOL_TYPE_AZURE_DISK,
268268
CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK,
269269
CONST_STORAGE_POOL_TYPE_ELASTIC_SAN,
270+
CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE,
270271
CONST_STORAGE_POOL_SKU_PREMIUM_LRS,
271272
CONST_STORAGE_POOL_SKU_STANDARD_LRS,
272273
CONST_STORAGE_POOL_SKU_STANDARDSSD_LRS,
@@ -480,12 +481,14 @@
480481
CONST_STORAGE_POOL_TYPE_AZURE_DISK,
481482
CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK,
482483
CONST_STORAGE_POOL_TYPE_ELASTIC_SAN,
484+
CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE,
483485
]
484486

485487
disable_storage_pool_types = [
486488
CONST_STORAGE_POOL_TYPE_AZURE_DISK,
487489
CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK,
488490
CONST_STORAGE_POOL_TYPE_ELASTIC_SAN,
491+
CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE,
489492
CONST_ACSTOR_ALL,
490493
]
491494

@@ -1198,7 +1201,7 @@ def load_arguments(self, _):
11981201
"enable_azure_container_storage",
11991202
arg_type=_get_container_storage_enum_type(storage_pool_types),
12001203
help="enable azure container storage. Can be used as a flag (defaults to True) or with a"
1201-
" storage pool type value: (azureDisk, ephemeralDisk, elasticSan)",
1204+
" storage pool type value: (azureDisk, ephemeralDisk, elasticSan, distributedcache)",
12021205
)
12031206
c.argument(
12041207
"container_storage_version",
@@ -1907,14 +1910,14 @@ def load_arguments(self, _):
19071910
"enable_azure_container_storage",
19081911
arg_type=_get_container_storage_enum_type(storage_pool_types),
19091912
help="enable azure container storage. Can be used as a flag (defaults to True) or with a"
1910-
" storage pool type value: (azureDisk, ephemeralDisk, elasticSan)",
1913+
" storage pool type value: (azureDisk, ephemeralDisk, elasticSan, distributedcache)",
19111914
)
19121915
c.argument(
19131916
"disable_azure_container_storage",
19141917
arg_type=_get_container_storage_enum_type(disable_storage_pool_types),
1915-
help="disable azure container storage or any one of the storage pool types."
1916-
" Can be used as a flag (defaults to True) or with a storagepool type value:"
1917-
" azureDisk, ephemeralDisk, elasticSan, all (to disable all storage pools).",
1918+
help="disable azure container storage or any one of the storage types."
1919+
" Can be used as a flag (defaults to True) or with a storage type value:"
1920+
" azureDisk, ephemeralDisk, elasticSan, distributedcache, all (to disable all storage types).",
19181921
)
19191922
c.argument(
19201923
"container_storage_version",

src/aks-preview/azext_aks_preview/azurecontainerstorage/_consts.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
CONST_ACSTOR_EXT_INSTALLATION_NAME = "acstor"
1818
CONST_ACSTOR_EXT_INSTALLATION_NAMESPACE = "kube-system"
1919
CONST_ACSTOR_K8S_EXTENSION_NAME = "microsoft.azurecontainerstoragev2"
20+
# Distributed cache (Distributed Accelerator for Cloud Storage) install controller.
21+
CONST_DISTRIBUTED_CACHE_EXT_INSTALLATION_NAME = "distributedcache"
22+
CONST_DISTRIBUTED_CACHE_EXT_INSTALLATION_NAMESPACE = "kube-system"
23+
CONST_DISTRIBUTED_CACHE_K8S_EXTENSION_NAME = "microsoft.dacs"
2024
CONST_K8S_EXTENSION_CLIENT_FACTORY_MOD_NAME = "azext_k8s_extension._client_factory"
2125
CONST_K8S_EXTENSION_CUSTOM_MOD_NAME = "azext_k8s_extension.custom"
2226
CONST_K8S_EXTENSION_NAME = "k8s-extension"
@@ -35,3 +39,4 @@
3539
CONST_STORAGE_POOL_TYPE_AZURE_DISK = "azureDisk"
3640
CONST_STORAGE_POOL_TYPE_ELASTIC_SAN = "elasticSan"
3741
CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK = "ephemeralDisk"
42+
CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE = "distributedcache"

src/aks-preview/azext_aks_preview/azurecontainerstorage/_helpers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
CONST_STORAGE_POOL_TYPE_AZURE_DISK,
2424
CONST_STORAGE_POOL_TYPE_ELASTIC_SAN,
2525
CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK,
26+
CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE,
2627
CONST_ACSTOR_V1_K8S_EXTENSION_NAME,
2728
CONST_ACSTOR_V1_EXT_INSTALLATION_NAME,
2829
)
@@ -304,6 +305,15 @@ def should_delete_extension(storage_options_to_remove) -> bool:
304305
)
305306

306307

308+
def is_distributed_cache_requested(storage_options) -> bool:
309+
# Detect whether distributed cache is among the requested storage options.
310+
if storage_options is None or storage_options is True:
311+
return False
312+
if isinstance(storage_options, list):
313+
return CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE in storage_options
314+
return storage_options == CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE
315+
316+
307317
def get_container_storage_extension_installed(
308318
cmd,
309319
resource_group,

src/aks-preview/azext_aks_preview/azurecontainerstorage/_validators.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
CONST_STORAGE_POOL_TYPE_AZURE_DISK,
2222
CONST_STORAGE_POOL_TYPE_ELASTIC_SAN,
2323
CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK,
24+
CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE,
2425
)
2526
from azext_aks_preview.azurecontainerstorage._helpers import (
2627
get_vm_sku_details
@@ -571,6 +572,114 @@ def validate_disable_azure_container_storage_params(
571572
)
572573

573574

575+
def validate_enable_distributed_cache_params(
576+
enablement_option,
577+
is_extension_installed,
578+
storage_pool_name,
579+
storage_pool_sku,
580+
storage_pool_option,
581+
storage_pool_size,
582+
ephemeral_disk_volume_type,
583+
ephemeral_disk_nvme_perf_tier,
584+
container_storage_version=None,
585+
):
586+
# Distributed cache has no storage pool construct, so none of the storage
587+
# pool parameters are supported.
588+
enablement_option_arr = enablement_option if isinstance(enablement_option, list) else [enablement_option]
589+
other_pool_types = [
590+
opt for opt in enablement_option_arr
591+
if opt != CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE
592+
]
593+
if other_pool_types:
594+
options_display = "', '".join(other_pool_types)
595+
raise InvalidArgumentValueError(
596+
f"'{CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE}' cannot be combined with other storage "
597+
f"options ('{options_display}'). Distributed cache is enabled independently. "
598+
f"Please run --enable-azure-container-storage {CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE} "
599+
"on its own."
600+
)
601+
602+
if is_extension_installed:
603+
raise InvalidArgumentValueError(
604+
'Cannot enable distributed cache as it is already enabled on the cluster.'
605+
)
606+
607+
unsupported_params = []
608+
if storage_pool_name is not None:
609+
unsupported_params.append('--storage-pool-name')
610+
if storage_pool_sku is not None:
611+
unsupported_params.append('--storage-pool-sku')
612+
if storage_pool_option is not None:
613+
unsupported_params.append('--storage-pool-option')
614+
if storage_pool_size is not None:
615+
unsupported_params.append('--storage-pool-size')
616+
if ephemeral_disk_volume_type is not None:
617+
unsupported_params.append('--ephemeral-disk-volume-type')
618+
if ephemeral_disk_nvme_perf_tier is not None:
619+
unsupported_params.append('--ephemeral-disk-nvme-perf-tier')
620+
if container_storage_version is not None:
621+
unsupported_params.append('--container-storage-version')
622+
623+
if unsupported_params:
624+
params_defined = ', '.join(unsupported_params)
625+
raise InvalidArgumentValueError(
626+
f'{params_defined} cannot be used with '
627+
f'--enable-azure-container-storage {CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE}. '
628+
'Distributed cache does not require or support any storage pool configuration. '
629+
'Please remove these parameters and try again.'
630+
)
631+
632+
633+
def validate_disable_distributed_cache_params(
634+
disablement_option,
635+
is_extension_installed,
636+
storage_pool_name,
637+
storage_pool_sku,
638+
storage_pool_option,
639+
storage_pool_size,
640+
container_storage_version=None,
641+
):
642+
disablement_option_arr = disablement_option if isinstance(disablement_option, list) else [disablement_option]
643+
other_pool_types = [
644+
opt for opt in disablement_option_arr
645+
if opt != CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE
646+
]
647+
if other_pool_types:
648+
options_display = "', '".join(other_pool_types)
649+
raise InvalidArgumentValueError(
650+
f"'{CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE}' cannot be combined with other storage "
651+
f"options ('{options_display}'). Distributed cache is disabled independently. "
652+
f"Please run --disable-azure-container-storage {CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE} "
653+
"on its own."
654+
)
655+
656+
if not is_extension_installed:
657+
raise InvalidArgumentValueError(
658+
'Cannot disable distributed cache as it could not be found on the cluster.'
659+
)
660+
661+
unsupported_params = []
662+
if storage_pool_name is not None:
663+
unsupported_params.append('--storage-pool-name')
664+
if storage_pool_sku is not None:
665+
unsupported_params.append('--storage-pool-sku')
666+
if storage_pool_option is not None:
667+
unsupported_params.append('--storage-pool-option')
668+
if storage_pool_size is not None:
669+
unsupported_params.append('--storage-pool-size')
670+
if container_storage_version is not None:
671+
unsupported_params.append('--container-storage-version')
672+
673+
if unsupported_params:
674+
params_defined = ', '.join(unsupported_params)
675+
raise InvalidArgumentValueError(
676+
f'{params_defined} cannot be used with '
677+
f'--disable-azure-container-storage {CONST_STORAGE_POOL_TYPE_DISTRIBUTED_CACHE}. '
678+
'Distributed cache does not require or support any storage pool configuration. '
679+
'Please remove these parameters and try again.'
680+
)
681+
682+
574683
# _Validate_storage_pool_size validates that the storage_pool_size is
575684
# string of a combination of a float number immediately followed by
576685
# Ti or Gi e.g. 2Ti, 512Gi, 1.5Ti. The function also validates that the

src/aks-preview/azext_aks_preview/azurecontainerstorage/acstor_ops.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
CONST_ACSTOR_EXT_INSTALLATION_NAME,
1313
CONST_ACSTOR_EXT_INSTALLATION_NAMESPACE,
1414
CONST_ACSTOR_K8S_EXTENSION_NAME,
15+
CONST_DISTRIBUTED_CACHE_EXT_INSTALLATION_NAME,
16+
CONST_DISTRIBUTED_CACHE_EXT_INSTALLATION_NAMESPACE,
17+
CONST_DISTRIBUTED_CACHE_K8S_EXTENSION_NAME,
1518
CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY,
1619
CONST_DISK_TYPE_PV_WITH_ANNOTATION,
1720
CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD,
@@ -797,3 +800,109 @@ def perform_azure_container_storage_update(
797800
raise UnknownError(
798801
"Failed to disable Azure Container Storage with error: %s" % delete_ex
799802
) from delete_ex
803+
804+
805+
def perform_enable_distributed_cache(
806+
cmd,
807+
resource_group,
808+
cluster_name,
809+
is_extension_installed=False,
810+
is_called_from_extension=False,
811+
):
812+
# This will be set true only when aks-preview extension is used
813+
# and we want the aks-preview ManagedClusterDecorator to call the
814+
# perform_enable_distributed_cache function.
815+
if not is_called_from_extension:
816+
return
817+
818+
# Enabling only installs the install controller. Cache components are
819+
# deployed later, driven by the creation of the corresponding CR.
820+
client_factory = get_k8s_extension_module(CONST_K8S_EXTENSION_CLIENT_FACTORY_MOD_NAME)
821+
client = client_factory.cf_k8s_extension_operation(cmd.cli_ctx)
822+
k8s_extension_custom_mod = get_k8s_extension_module(CONST_K8S_EXTENSION_CUSTOM_MOD_NAME)
823+
824+
if is_extension_installed:
825+
logger.warning("Distributed cache is already enabled on the cluster.")
826+
return
827+
828+
try:
829+
result = k8s_extension_custom_mod.create_k8s_extension(
830+
cmd,
831+
client,
832+
resource_group,
833+
cluster_name,
834+
CONST_DISTRIBUTED_CACHE_EXT_INSTALLATION_NAME,
835+
"managedClusters",
836+
CONST_DISTRIBUTED_CACHE_K8S_EXTENSION_NAME,
837+
auto_upgrade_minor_version=True,
838+
release_train="stable",
839+
scope="cluster",
840+
release_namespace=CONST_DISTRIBUTED_CACHE_EXT_INSTALLATION_NAMESPACE,
841+
)
842+
long_op_result = LongRunningOperation(cmd.cli_ctx)(result)
843+
if long_op_result.provisioning_state == "Succeeded":
844+
logger.warning("Distributed cache successfully installed")
845+
except Exception as ex: # pylint: disable=broad-except
846+
logger.error("Distributed cache failed to install.\nError: %s", ex)
847+
logger.warning("Cleaning up the cluster by disabling distributed cache")
848+
try:
849+
delete_op_result = k8s_extension_custom_mod.delete_k8s_extension(
850+
cmd,
851+
client,
852+
resource_group,
853+
cluster_name,
854+
CONST_DISTRIBUTED_CACHE_EXT_INSTALLATION_NAME,
855+
"managedClusters",
856+
yes=True,
857+
)
858+
LongRunningOperation(cmd.cli_ctx)(delete_op_result)
859+
logger.warning(
860+
"Please retry enabling distributed cache by running "
861+
"`az aks update` along with "
862+
"`--enable-azure-container-storage distributedcache`"
863+
)
864+
except Exception as delete_ex: # pylint: disable=broad-except
865+
raise UnknownError(
866+
"Failed to clean up distributed cache with error: %s" % delete_ex
867+
) from delete_ex
868+
869+
870+
def perform_disable_distributed_cache(
871+
cmd,
872+
resource_group,
873+
cluster_name,
874+
is_extension_installed=False,
875+
is_called_from_extension=False,
876+
):
877+
# This will be set true only when aks-preview extension is used
878+
# and we want the aks-preview ManagedClusterDecorator to call the
879+
# perform_disable_distributed_cache function.
880+
if not is_called_from_extension:
881+
return
882+
883+
client_factory = get_k8s_extension_module(CONST_K8S_EXTENSION_CLIENT_FACTORY_MOD_NAME)
884+
client = client_factory.cf_k8s_extension_operation(cmd.cli_ctx)
885+
k8s_extension_custom_mod = get_k8s_extension_module(CONST_K8S_EXTENSION_CUSTOM_MOD_NAME)
886+
887+
if not is_extension_installed:
888+
logger.warning("Distributed cache is not enabled on the cluster.")
889+
return
890+
891+
# Deleting the install controller triggers removal of the remaining cache
892+
# components from the cluster.
893+
try:
894+
delete_op_result = k8s_extension_custom_mod.delete_k8s_extension(
895+
cmd,
896+
client,
897+
resource_group,
898+
cluster_name,
899+
CONST_DISTRIBUTED_CACHE_EXT_INSTALLATION_NAME,
900+
"managedClusters",
901+
yes=True,
902+
)
903+
LongRunningOperation(cmd.cli_ctx)(delete_op_result)
904+
logger.warning("Distributed cache has been disabled.")
905+
except Exception as delete_ex: # pylint: disable=broad-except
906+
raise UnknownError(
907+
"Failed to disable distributed cache with error: %s" % delete_ex
908+
) from delete_ex

0 commit comments

Comments
 (0)