-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[aks-preview] Add --enable-backup to az aks create and az aks update #9897
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
Open
anshulahuja98
wants to merge
24
commits into
Azure:main
Choose a base branch
from
anshulahuja98:feat/aks-enable-backup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d9a3562
[aks-preview] Add --enable-backup to az aks create and az aks update
d1bb93b
[aks-preview] HISTORY: note --enable-backup under Pending
08bc672
[aks-preview] aks_backup: align continuation indent + silence too-man…
0b138f9
Merge branch 'main' into feat/aks-enable-backup
anshulahuja98 e2739c7
[aks-preview] _params: note backup-strategy enum mirrors dataprotection
237444b
[aks-preview] Address CI lint feedback
2ce8293
[aks-preview] Extract backup-strategy enum into a shared constant
938d597
[aks-preview] aks_backup: prompt to install dataprotection extension …
b70c8ae
[aks-preview] Add live tests for aks create/update --enable-backup
59b7722
Merge branch 'main' into feat/aks-enable-backup
anshulahuja98 cdf039a
[aks-preview] Fix error type and release notes for --enable-backup
1d6194a
[aks-preview][dataprotection] Auto-install dependent CLI extensions o…
61d86c3
[aks-preview] Fix HISTORY.rst: --backup-configuration-file -> --backu…
de88d3e
[aks-preview] Release enable-backup preview support
7bfd2c0
Merge remote-tracking branch 'upstream/main' into feat/aks-enable-backup
9e69b8a
[aks-preview] Fix flake8 indentation in backup parameter
5260826
[dataprotection] Remove redundant prompt import in AKS helper
0b4a133
Refactor docstring in aks_backup.py to simplify description of AKS ba…
3e7cf63
Merge remote-tracking branch 'upstream/main' into feat/aks-enable-backup
b0c335b
[aks-preview] Move pending notes into 21.0.0b4 release
2e020dd
[aks-preview] Remove dataprotection helper changes
bed0ec0
Merge branch 'main' into feat/aks-enable-backup
anshulahuja98 c047a50
Fix AKS backup storage account create payload
f31e690
Revert "Fix AKS backup storage account create payload"
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
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,84 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| """Helpers that delegate AKS backup enablement to the dataprotection extension.""" | ||
|
|
||
| from knack.log import get_logger | ||
| from knack.prompting import prompt_y_n, NoTTYException | ||
|
|
||
| from azure.cli.core.azclierror import RequiredArgumentMissingError | ||
|
|
||
| DATAPROTECTION_EXTENSION_NAME = "dataprotection" | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def _ensure_dataprotection_extension(cmd, yes): | ||
| """Make ``azext_dataprotection.manual.aks.aks_helper`` importable. | ||
|
|
||
| If the ``dataprotection`` extension is not installed, prompt the user to | ||
| install it (or install silently when ``yes`` is True). Raises | ||
| ``RequiredArgumentMissingError`` if the user declines or the install fails. | ||
| """ | ||
| from azure.cli.core.extension.operations import add_extension_to_path | ||
|
|
||
| try: | ||
| add_extension_to_path(DATAPROTECTION_EXTENSION_NAME) | ||
| from azext_dataprotection.manual.aks.aks_helper import ( # pylint: disable=unused-import,import-error | ||
| dataprotection_enable_backup_helper, | ||
| ) | ||
| return | ||
| except Exception: # pylint: disable=broad-except | ||
| pass | ||
|
|
||
| install_msg = ( | ||
| f"The '{DATAPROTECTION_EXTENSION_NAME}' extension is required for " | ||
| "--enable-backup but is not installed. Install it now?" | ||
| ) | ||
| proceed = yes | ||
| if not proceed: | ||
| try: | ||
| proceed = prompt_y_n(install_msg, default="y") | ||
| except NoTTYException: | ||
| proceed = False | ||
| if not proceed: | ||
| raise RequiredArgumentMissingError( | ||
| f"The '{DATAPROTECTION_EXTENSION_NAME}' extension is required for " | ||
| "--enable-backup with 'az aks create' / 'az aks update'.\n" | ||
| f"Run `az extension add --name {DATAPROTECTION_EXTENSION_NAME}` " | ||
| "and retry, or rerun with --yes to auto-install." | ||
| ) | ||
|
anshulahuja98 marked this conversation as resolved.
|
||
|
|
||
| logger.warning("Installing extension '%s'...", DATAPROTECTION_EXTENSION_NAME) | ||
| from azure.cli.core.extension.operations import add_extension | ||
| add_extension(cmd=cmd, extension_name=DATAPROTECTION_EXTENSION_NAME) | ||
| add_extension_to_path(DATAPROTECTION_EXTENSION_NAME) | ||
|
|
||
|
|
||
| def enable_aks_backup(cmd, resource_group_name, cluster_name, # pylint: disable=too-many-positional-arguments | ||
| backup_strategy, backup_configuration_file, yes): | ||
| """Enable Azure Backup for an AKS cluster by delegating to the | ||
| ``dataprotection`` extension. | ||
| """ | ||
| from azure.cli.core.commands.client_factory import get_subscription_id | ||
|
|
||
| _ensure_dataprotection_extension(cmd, yes) | ||
|
|
||
| from azext_dataprotection.manual.aks.aks_helper import ( # pylint: disable=import-error | ||
| dataprotection_enable_backup_helper, | ||
| ) | ||
|
|
||
| subscription_id = get_subscription_id(cmd.cli_ctx) | ||
| datasource_id = ( | ||
| f"/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}" | ||
| f"/providers/Microsoft.ContainerService/managedClusters/{cluster_name}" | ||
| ) | ||
| dataprotection_enable_backup_helper( | ||
| cmd, | ||
| datasource_id, | ||
| backup_strategy or "Week", | ||
| backup_configuration_file or {}, | ||
| yes=yes, | ||
| ) | ||
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
Oops, something went wrong.
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.