Skip to content

[AKS Preview] Add backup enablement support via dataprotection extension#9615

Closed
anshulahuja98 wants to merge 1 commit intoAzure:mainfrom
anshulahuja98:aksbackup-aks-preview
Closed

[AKS Preview] Add backup enablement support via dataprotection extension#9615
anshulahuja98 wants to merge 1 commit intoAzure:mainfrom
anshulahuja98:aksbackup-aks-preview

Conversation

@anshulahuja98
Copy link


This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)
  • My extension version conforms to the Extension version schema

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

Copilot AI review requested due to automatic review settings February 16, 2026 06:53
@azure-client-tools-bot-prd
Copy link

Validation for Breaking Change Starting...

Thanks for your contribution!

@azure-client-tools-bot-prd
Copy link

Hi @anshulahuja98,
Please write the description of changes which can be perceived by customers into HISTORY.rst.
If you want to release a new extension version, please update the version in setup.py as well.

@yonzhan
Copy link
Collaborator

yonzhan commented Feb 16, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@github-actions
Copy link

CodeGen Tools Feedback Collection

Thank you for using our CodeGen tool. We value your feedback, and we would like to know how we can improve our product. Please take a few minutes to fill our codegen survey

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for enabling AKS cluster backups via the dataprotection extension during cluster updates. The feature allows users to configure backup settings through the az aks update command with options to specify backup strategies and configuration files.

Changes:

  • Added set_up_backup method to handle backup enablement during cluster updates
  • Introduced three new parameters: enable_backup, backup_strategy, and backup_configuration_file
  • Imported backup strategy constants from the dataprotection extension to support argument validation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
src/aks-preview/azext_aks_preview/managed_cluster_decorator.py Added set_up_backup method to orchestrate backup enablement and added json import
src/aks-preview/azext_aks_preview/custom.py Added three backup-related parameters to the aks_update function signature
src/aks-preview/azext_aks_preview/_params.py Defined backup parameter arguments and imported backup strategy constants from dataprotection extension

Comment on lines +28 to +40
from azure.cli.core.extension.operations import add_extension_to_path
add_extension_to_path("dataprotection")
from azext_dataprotection.manual._consts import (
CONST_AKS_BACKUP_STRATEGIES,
CONST_BACKUP_STRATEGY_WEEK,
CONST_BACKUP_STRATEGY_MONTH,
CONST_BACKUP_STRATEGY_IMMUTABLE,
CONST_BACKUP_STRATEGY_DISASTER_RECOVERY,
CONST_BACKUP_STRATEGY_CUSTOM,
)

backup_presets = CONST_AKS_BACKUP_STRATEGIES

Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dataprotection extension is imported at module load time (lines 28-37), which means the extension must be installed even when users are not using the backup functionality. This will cause import errors for users who don't have the dataprotection extension installed. Consider wrapping these imports in a try-except block similar to how it's done in managed_cluster_decorator.py (lines 7387-7395), or move the imports into a function that's only called when backup functionality is needed. See _helpers.py:414-427 for the pattern used with k8s-extension.

Suggested change
from azure.cli.core.extension.operations import add_extension_to_path
add_extension_to_path("dataprotection")
from azext_dataprotection.manual._consts import (
CONST_AKS_BACKUP_STRATEGIES,
CONST_BACKUP_STRATEGY_WEEK,
CONST_BACKUP_STRATEGY_MONTH,
CONST_BACKUP_STRATEGY_IMMUTABLE,
CONST_BACKUP_STRATEGY_DISASTER_RECOVERY,
CONST_BACKUP_STRATEGY_CUSTOM,
)
backup_presets = CONST_AKS_BACKUP_STRATEGIES
try:
from azure.cli.core.extension.operations import add_extension_to_path
add_extension_to_path("dataprotection")
from azext_dataprotection.manual._consts import (
CONST_AKS_BACKUP_STRATEGIES,
CONST_BACKUP_STRATEGY_WEEK,
CONST_BACKUP_STRATEGY_MONTH,
CONST_BACKUP_STRATEGY_IMMUTABLE,
CONST_BACKUP_STRATEGY_DISASTER_RECOVERY,
CONST_BACKUP_STRATEGY_CUSTOM,
)
backup_presets = CONST_AKS_BACKUP_STRATEGIES
except Exception: # pylint: disable=broad-except
# Fallback definitions when the dataprotection extension is not installed.
CONST_AKS_BACKUP_STRATEGIES = None
CONST_BACKUP_STRATEGY_WEEK = None
CONST_BACKUP_STRATEGY_MONTH = None
CONST_BACKUP_STRATEGY_IMMUTABLE = None
CONST_BACKUP_STRATEGY_DISASTER_RECOVERY = None
CONST_BACKUP_STRATEGY_CUSTOM = None
backup_presets = CONST_AKS_BACKUP_STRATEGIES

Copilot uses AI. Check for mistakes.
c.argument("backup_configuration_file", type=validate_file_or_dict,
options_list=['--backup-configuration-file', '-f'],
help="Path to backup configuration file (JSON) or inline JSON string.", is_preview=True)
# In update scenario, use emtpy str as default.
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: 'emtpy' should be 'empty'.

Suggested change
# In update scenario, use emtpy str as default.
# In update scenario, use empty str as default.

Copilot uses AI. Check for mistakes.
Comment on lines +7382 to +7408
def set_up_backup(self, mc: ManagedCluster) -> ManagedCluster:

enable_backup = self.context.raw_param.get("enable_backup")
if enable_backup:
# Validate that dataprotection extension is installed
try:
from azure.cli.core.extension.operations import add_extension_to_path
add_extension_to_path("dataprotection")
from azext_dataprotection.manual.aks.aks_helper import dataprotection_enable_backup_helper
except (ImportError, ModuleNotFoundError):
raise CLIError(
"The 'dataprotection' extension is required for AKS backup functionality.\n"
"Please install it using: az extension add --name dataprotection"
)

backup_strategy = self.context.raw_param.get("backup_strategy")
backup_configuration_file = self.context.raw_param.get("backup_configuration_file")

# Build the cluster resource ID
cluster_resource_id = (
f"/subscriptions/{self.context.get_subscription_id()}"
f"/resourceGroups/{self.context.get_resource_group_name()}"
f"/providers/Microsoft.ContainerService/managedClusters/{self.context.get_name()}"
)

dataprotection_enable_backup_helper(self.cmd, str(cluster_resource_id), backup_strategy, backup_configuration_file)
return mc
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage: The new set_up_backup method lacks test coverage. The codebase has comprehensive tests for similar set_up methods in managed_cluster_decorator.py (see test_managed_cluster_decorator.py). Add unit tests that verify the method's behavior including successful backup enablement, handling missing dataprotection extension, and correct parameter passing.

Copilot uses AI. Check for mistakes.
# pylint: disable=too-many-lines
import copy
import datetime
import json
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import: The json module is imported but not used anywhere in the file. Remove this import unless it's needed for functionality not visible in this diff.

Suggested change
import json

Copilot uses AI. Check for mistakes.
f"/providers/Microsoft.ContainerService/managedClusters/{self.context.get_name()}"
)

dataprotection_enable_backup_helper(self.cmd, str(cluster_resource_id), backup_strategy, backup_configuration_file)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary type conversion: The cluster_resource_id is already a string (f-string concatenation), so wrapping it with str() on line 7407 is redundant. Remove the str() call for cleaner code.

Suggested change
dataprotection_enable_backup_helper(self.cmd, str(cluster_resource_id), backup_strategy, backup_configuration_file)
dataprotection_enable_backup_helper(self.cmd, cluster_resource_id, backup_strategy, backup_configuration_file)

Copilot uses AI. Check for mistakes.
Comment on lines +1759 to +1765
c.argument("enable_backup", help="Enable backup for the cluster", is_preview=True, action="store_true")
c.argument("backup_strategy", arg_type=get_enum_type(backup_presets), help="Backup strategy for the cluster. Defaults to Week.", is_preview=True)
c.argument("backup_configuration_file", type=validate_file_or_dict,
options_list=['--backup-configuration-file', '-f'],
help="Path to backup configuration file (JSON) or inline JSON string.", is_preview=True)
# In update scenario, use emtpy str as default.
c.argument('ssh_access', arg_type=get_enum_type(ssh_accesses), is_preview=True)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poor code organization: The backup-related parameters (lines 1759-1763) are inserted between unrelated parameters, with a comment on line 1764 that applies to the ssh_access parameter on line 1765, not to the backup parameters. This makes the code harder to read and maintain. Consider grouping related parameters together and ensuring comments are adjacent to the parameters they describe.

Copilot uses AI. Check for mistakes.
# Backup
enable_backup=False,
backup_strategy=None,
backup_configuration_parameters=None,
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter name mismatch: The function parameter is named 'backup_configuration_parameters' but the code uses 'backup_configuration_file' when accessing it via context.raw_param.get(). This inconsistency will cause the parameter value to not be retrieved correctly. Either rename the parameter in custom.py to 'backup_configuration_file' to match the _params.py definition, or update the context.raw_param.get() call to use 'backup_configuration_parameters'.

Suggested change
backup_configuration_parameters=None,
backup_configuration_file=None,

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments