-
Notifications
You must be signed in to change notification settings - Fork 1.6k
AKS: Implement support to perform Azure container storage operations #6837
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
Merged
Merged
Changes from 40 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
c7f9c66
Adding azure container storage support to az aks preview extension
mukhoakash 2b42cb4
Fixes and restructuring
mukhoakash 2b3a10d
Design change to call the azure container storage installation from M…
mukhoakash 93be0fb
Missed out a couple of changes
mukhoakash fdf93ec
Merge branch 'main' of github.com:Azure/azure-cli-extensions into acs…
mukhoakash f5b860a
More fixes to the cli logic
mukhoakash fb95dc5
Merge branch 'main' of github.com:Azure/azure-cli-extensions into acs…
mukhoakash 3194da7
Adding history and bumping the version
mukhoakash 8daa9b6
Lint fixes and some more changes
mukhoakash a9923f9
Lint error fixes
mukhoakash c0daa32
Adding help text for the azure container storage params
mukhoakash 32e9eb6
Lint fixes and some final logic changes
mukhoakash c3978af
Test cases for enable and disable azure container storage for aks cre…
mukhoakash 5717138
Merge branch 'main' of github.com:Azure/azure-cli-extensions into acs…
mukhoakash f8fd49d
Fixing a bug
mukhoakash 3263793
Adding help for --storage-pool-name
mukhoakash a262a6d
Reverting some testing changes
mukhoakash 3b71064
Review comments and unittest cases added
mukhoakash f910bc9
Lint fixes
mukhoakash 86a4ce2
Moving the helper functions to a new file
mukhoakash c2f057a
Test case compilation fixes
mukhoakash ed79001
Lint and test fixes
mukhoakash 9c51248
Adding try catch to the delete operation and fixing a test case
mukhoakash 296039d
Small bug fix in the test code
mukhoakash bad5c9e
Test fix
mukhoakash 102598c
Small fixes and indentation fixes
mukhoakash 8cb95b0
Some compilation fix
mukhoakash fa1068f
Removing extension add to validate if tests run
mukhoakash 7e6fc88
Fixing the error message
mukhoakash 29a2a8b
Introducing extension add in test run
mukhoakash f3b9343
Removing unwanted dependent resource providers since ManagedClusters …
mukhoakash 2b94a54
Marking azurecontainerstorage test for bypass
mukhoakash a6f40ca
Fix lint issue
mukhoakash fa7cc4e
Merge branch 'main' of github.com:Azure/azure-cli-extensions into acs…
mukhoakash 8bae3ca
Adding the size of the Large response from index url. Also, removing …
mukhoakash f9c91fd
Add recording for test_aks_create_with_azurecontainerstorage and comm…
mukhoakash 8a86fe9
Introducing the test once again
mukhoakash 6949be3
Revert "Introducing the test once again"
mukhoakash f742701
Merge branch 'main' of github.com:Azure/azure-cli-extensions into acs…
mukhoakash 8bda8f7
Review comments
mukhoakash 52272d9
Adding a validator to ensure elastic san storagepools are atleast 1 Ti
mukhoakash a19da97
Fix compile issue
mukhoakash 8655c6f
Fix error statement
mukhoakash 6d031c4
Improving install time delay for role assignment and adding relevant …
mukhoakash 58cda5f
Remove --storage-pool-type and use --enable-azure-container-storage i…
mukhoakash d07bf68
Fixing the empty space after log lines. Fix a compile issue
mukhoakash 25281eb
Merge branch 'main' of github.com:Azure/azure-cli-extensions into acs…
mukhoakash c5cb1ee
Moving prompt to start of disable. Fix a test
mukhoakash 9914bc5
Small fix
mukhoakash 52aa0dc
Fix a constant typo
mukhoakash 60d60b6
Fixing some lint issues
mukhoakash 4d8d9a5
Fixing an indentation issue
mukhoakash ac95736
Formatting fix
mukhoakash d451aec
Updating the param in live test
mukhoakash 4e0e320
Changing exception to logger.error
mukhoakash f5789c2
Adding the temp local disk value
mukhoakash 29f77dd
Removing unused param
mukhoakash 711ee46
Changing exceptions to logger in install call
mukhoakash a8c5201
Review comment addressed
mukhoakash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/aks-preview/azext_aks_preview/azurecontainerstorage/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- |
27 changes: 27 additions & 0 deletions
27
src/aks-preview/azext_aks_preview/azurecontainerstorage/_consts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| CONST_ACSTOR_K8S_EXTENSION_NAME = "microsoft.azurecontainerstorage" | ||
| CONST_EXT_INSTALLATION_NAME = "azurecontainerstorage" | ||
| CONST_K8S_EXTENSION_CLIENT_FACTORY_MOD_NAME = "azext_k8s_extension._client_factory" | ||
| CONST_K8S_EXTENSION_CUSTOM_MOD_NAME = "azext_k8s_extension.custom" | ||
| CONST_K8S_EXTENSION_NAME = "k8s-extension" | ||
| CONST_STORAGE_POOL_DEFAULT_SIZE = "512Gi" | ||
| CONST_STORAGE_POOL_NAME_PREFIX = "mypool-" | ||
| CONST_STORAGE_POOL_OPTION_NVME = "LsV2" | ||
| CONST_STORAGE_POOL_OPTION_TEMP = "temp" | ||
| CONST_STORAGE_POOL_SKU_PREMIUM_LRS = "Premium_LRS" | ||
| CONST_STORAGE_POOL_SKU_PREMIUM_ZRS = "Premium_ZRS" | ||
| CONST_STORAGE_POOL_SKU_PREMIUMV2_ZRS = "PremiumV2_LRS" | ||
| CONST_STORAGE_POOL_SKU_STANDARD_LRS = "Standard_LRS" | ||
| CONST_STORAGE_POOL_SKU_STANDARDSSD_LRS = "StandardSSD_LRS" | ||
| CONST_STORAGE_POOL_SKU_STANDARDSSD_ZRS = "StandardSSD_ZRS" | ||
| CONST_STORAGE_POOL_SKU_ULTRASSD_LRS = "UltraSSD_LRS" | ||
| CONST_STORAGE_POOL_TYPE_AZURE_DISK = "azureDisk" | ||
| CONST_STORAGE_POOL_TYPE_ELASTIC_SAN = "elasticSan" | ||
| CONST_STORAGE_POOL_TYPE_EPHEMERAL_DISK = "ephemeralDisk" | ||
|
|
||
| CONST_STORAGE_POOL_RANDOM_LENGTH = 7 | ||
| RP_REGISTRATION_POLLING_INTERVAL_IN_SEC = 5 |
124 changes: 124 additions & 0 deletions
124
src/aks-preview/azext_aks_preview/azurecontainerstorage/_helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from azure.cli.core.azclierror import UnknownError | ||
| from azure.cli.command_modules.acs._roleassignments import ( | ||
| add_role_assignment, | ||
| build_role_scope, | ||
| delete_role_assignments, | ||
| ) | ||
| from azext_aks_preview._client_factory import get_providers_client_factory | ||
| from azext_aks_preview.azurecontainerstorage._consts import ( | ||
| CONST_K8S_EXTENSION_NAME, | ||
| CONST_STORAGE_POOL_NAME_PREFIX, | ||
| CONST_STORAGE_POOL_RANDOM_LENGTH, | ||
| RP_REGISTRATION_POLLING_INTERVAL_IN_SEC, | ||
| ) | ||
|
|
||
| from datetime import datetime | ||
| from knack.log import get_logger | ||
| import random | ||
| import string | ||
| import time | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def _register_dependent_rps(cmd, subscription_id): | ||
| required_rp = 'Microsoft.KubernetesConfiguration' | ||
| from azure.mgmt.resource.resources.models import ProviderRegistrationRequest, ProviderConsentDefinition | ||
|
|
||
| properties = ProviderRegistrationRequest(third_party_provider_consent=ProviderConsentDefinition(consent_to_authorization=False)) | ||
| client = get_providers_client_factory(cmd.cli_ctx) | ||
| try: | ||
| is_registered = _is_rp_registered(cmd, required_rp, subscription_id) | ||
| if is_registered: | ||
| return | ||
| client.register(required_rp, properties=properties) | ||
| # wait for registration to finish | ||
| timeout_secs = 120 | ||
| start = datetime.utcnow() | ||
| is_registered = _is_rp_registered(cmd, required_rp, subscription_id) | ||
| while not is_registered: | ||
| is_registered = _is_rp_registered(cmd, required_rp, subscription_id) | ||
| time.sleep(RP_REGISTRATION_POLLING_INTERVAL_IN_SEC) | ||
| if (datetime.utcnow() - start).seconds >= timeout_secs: | ||
| raise UnknownError("Timed out while waiting for the {0} resource provider to be registered.".format(required_rp)) | ||
|
|
||
| except Exception as e: | ||
| raise UnknownError( | ||
| "Installation of Azure Container Storage requires registering to the following resource providers: {0}. " | ||
| "We were unable to perform the registration on your behalf. " | ||
| "The following error was received: {1}\n" | ||
| "Please check with your admin on permissions, " | ||
| "or try running registration manually with: `az provider register --namespace {0}` command." | ||
| .format(required_rp, e.msg) | ||
| ) | ||
|
|
||
|
|
||
| def _is_rp_registered(cmd, required_rp, subscription_id): | ||
| registered = False | ||
| try: | ||
| providers_client = get_providers_client_factory(cmd.cli_ctx, subscription_id) | ||
| registration_state = getattr(providers_client.get(required_rp), 'registration_state', "NotRegistered") | ||
|
|
||
| registered = (registration_state and registration_state.lower() == 'registered') | ||
| except Exception: # pylint: disable=broad-except | ||
| pass | ||
| return registered | ||
|
|
||
|
|
||
| def _perform_role_operations_on_managed_rg(cmd, subscription_id, node_resource_group, kubelet_identity_object_id, assign): | ||
| managed_rg_role_scope = build_role_scope(node_resource_group, None, subscription_id) | ||
| roles = ["Reader", "Network Contributor", "Elastic SAN Owner", "Elastic SAN Volume Group Owner"] | ||
| exception = False | ||
|
|
||
| for role in roles: | ||
| try: | ||
| if assign: | ||
| add_role_assignment( | ||
| cmd, | ||
| role, | ||
| kubelet_identity_object_id, | ||
| scope=managed_rg_role_scope, | ||
| ) | ||
| else: | ||
| # NOTE: delete_role_assignments accepts cli_ctx | ||
| # instead of cmd unlike add_role_assignment. | ||
| delete_role_assignments( | ||
| cmd.cli_ctx, | ||
| role, | ||
| kubelet_identity_object_id, | ||
| scope=managed_rg_role_scope, | ||
| ) | ||
| except Exception as ex: | ||
| exception = True | ||
|
|
||
| if assign and exception: | ||
| logger.warning( | ||
| "Unable to add Role Assignments needed for Elastic SAN storagepools to be functional. " | ||
| "Going ahead with the installation of Azure Container Storage..." | ||
| ) | ||
|
|
||
|
|
||
| def _generate_random_storage_pool_name(): | ||
| random_name = CONST_STORAGE_POOL_NAME_PREFIX + ''.join(random.choices(string.ascii_lowercase, k=CONST_STORAGE_POOL_RANDOM_LENGTH)) | ||
| return random_name | ||
|
|
||
|
|
||
| def _get_k8s_extension_module(module_name): | ||
| try: | ||
| # adding the installed extension in the path | ||
| from azure.cli.core.extension.operations import add_extension_to_path | ||
| add_extension_to_path(CONST_K8S_EXTENSION_NAME) | ||
| # import the extension module | ||
| from importlib import import_module | ||
| azext_custom = import_module(module_name) | ||
| return azext_custom | ||
| except ImportError as ie: | ||
| raise UnknownError( | ||
| "Please add CLI extension `k8s-extension` for performing Azure Container Storage operations.\n" | ||
| "Run command `az extension --name k8s-extension`" | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.