Skip to content

[AKS] az aks safeguards: Add command group to manage deployment safeguards#31793

Merged
yanzhudd merged 6 commits intoAzure:devfrom
NickKeller:nikelle/azakssafeguards
Jul 24, 2025
Merged

[AKS] az aks safeguards: Add command group to manage deployment safeguards#31793
yanzhudd merged 6 commits intoAzure:devfrom
NickKeller:nikelle/azakssafeguards

Conversation

@NickKeller
Copy link
Copy Markdown
Member

Related command
az aks

Description
Previously I had created a PR to azure-cli-extensions to add an "aks-safeguards" extension. However, after discussion with PMs, the decision was to move it to the core cli experience to be next to the rest of the GA "az aks" implementations

Testing Guide

  • az aks safeguards create -g rg1 -n clustername --level Warn
  • `az aks safeguards update -c <CLUSTER_RESOURCE_ID> -n

History Notes

[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change
[Component Name 2] az command b: Add some customer-facing feature


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

Copilot AI review requested due to automatic review settings July 11, 2025 00:44
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Jul 11, 2025

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.9
️✔️acs
️✔️latest
️✔️3.12
️✔️3.9
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.9
️✔️ams
️✔️latest
️✔️3.12
️✔️3.9
️✔️apim
️✔️latest
️✔️3.12
️✔️3.9
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.9
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️aro
️✔️latest
️✔️3.12
️✔️3.9
️✔️backup
️✔️latest
️✔️3.12
️✔️3.9
️✔️batch
️✔️latest
️✔️3.12
️✔️3.9
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.9
️✔️billing
️✔️latest
️✔️3.12
️✔️3.9
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.9
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.9
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.9
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.9
️✔️config
️✔️latest
️✔️3.12
️✔️3.9
️✔️configure
️✔️latest
️✔️3.12
️✔️3.9
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.9
️✔️container
️✔️latest
️✔️3.12
️✔️3.9
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.9
️✔️core
️✔️latest
️✔️3.12
️✔️3.9
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.9
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.9
️✔️dls
️✔️latest
️✔️3.12
️✔️3.9
️✔️dms
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.9
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.9
️✔️find
️✔️latest
️✔️3.12
️✔️3.9
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.9
️✔️identity
️✔️latest
️✔️3.12
️✔️3.9
️✔️iot
️✔️latest
️✔️3.12
️✔️3.9
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.9
️✔️lab
️✔️latest
️✔️3.12
️✔️3.9
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️maps
️✔️latest
️✔️3.12
️✔️3.9
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.9
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.9
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.9
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.9
️✔️network
️✔️latest
️✔️3.12
️✔️3.9
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.9
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.9
️✔️profile
️✔️latest
️✔️3.12
️✔️3.9
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.9
️✔️redis
️✔️latest
️✔️3.12
️✔️3.9
️✔️relay
️✔️latest
️✔️3.12
️✔️3.9
️✔️resource
️✔️latest
️✔️3.12
️✔️3.9
️✔️role
️✔️latest
️✔️3.12
️✔️3.9
️✔️search
️✔️latest
️✔️3.12
️✔️3.9
️✔️security
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.9
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.9
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.9
️✔️sql
️✔️latest
️✔️3.12
️✔️3.9
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.9
️✔️storage
️✔️latest
️✔️3.12
️✔️3.9
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.9
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.9
️✔️util
️✔️latest
️✔️3.12
️✔️3.9
️✔️vm
️✔️latest
️✔️3.12
️✔️3.9

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

azure-client-tools-bot-prd bot commented Jul 11, 2025

⚠️AzureCLI-BreakingChangeTest
⚠️acs
rule cmd_name rule_message suggest_message
⚠️ 1011 - SubgroupAdd aks safeguards sub group aks safeguards added

@github-actions
Copy link
Copy Markdown

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>

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Jul 11, 2025

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

Copy link
Copy Markdown
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

Adds a new “aks safeguards” command group to the core AKS CLI, migrating functionality from the extension into the main azure-cli repository.

  • Introduces AAZ-based command implementations and custom wrappers for create, show, update, delete, list, and wait.
  • Registers the new command group in commands.py and loads it via the ACS module’s initializer.
  • Provides an end-to-end scenario test covering the full CRUD lifecycle of deployment safeguards.

Reviewed Changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_safeguards.py Adds a scenario test for the full safeguards lifecycle
src/azure-cli/azure/cli/command_modules/acs/custom.py Implements argument validation and custom command classes
src/azure-cli/azure/cli/command_modules/acs/commands.py Registers the new aks safeguards commands in the CLI table
src/azure-cli/azure/cli/command_modules/acs/aaz/latest/aks/safeguards/ Adds generated AAZ command and operation definitions for safeguards
src/azure-cli/azure/cli/command_modules/acs/init.py Loads AAZ commands when the ACS module initializes
Comments suppressed due to low confidence (3)

src/azure-cli/azure/cli/command_modules/acs/custom.py:146

  • [nitpick] Add a space after the period before 'You may provide...', and correct the mismatched quote around 'name' for clarity in the help text.
        help="The name of the resource group. You can configure the default group using az configure --defaults group=`<name>`. You may provide either 'managed_cluster' or both 'resource_group' and 'name', but not both",

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_safeguards.py:16

  • [nitpick] Remove the TODO comment or implement the remaining tests to avoid leaving placeholder comments in the scenario test.
    # TODO: add tests here

src/azure-cli/azure/cli/command_modules/acs/custom.py:123

  • The function get_logger is used without importing it. Add the appropriate import, for example from knack.log import get_logger, to avoid a NameError.
logger = get_logger(__name__)

Copy link
Copy Markdown
Member

@FumingZhang FumingZhang left a comment

Choose a reason for hiding this comment

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

Queued live test for case test_aks_deployment_safeguards to validate the change, the test failed with following error,

          raise AAZInvalidValueError("Expect <class 'dict'>, got {} ({})".format(data, type(data)))

E azure.cli.core.aaz.exceptions.AAZInvalidValueError: Expect <class 'dict'>, got {"eTag":"8f1dd5e3-7f38-4fc0-8f4e-8d182c991fb0","id":"/subscriptions/79a7390d-3a85-432d-9f6f-a11a703c8b83/resourceGroups/cli-qxps/providers/Microsoft.ContainerService/managedClusters/akssafeguards-neobhd/providers/Microsoft.ContainerService/deploymentSafeguards/default","name":"default","properties":{"level":"Warn","provisioningState":"Succeeded","systemExcludedNamespaces":["kube-system","calico-system","tigera-system","gatekeeper-system"]},"type":"Microsoft.ContainerService/deploymentSafeguards"} (<class 'str'>)

I am not very familiar with aaz, and I am not sure whether there is a problem with the case or a configuration problem with the live test pipeline, because this live test is designed for non-aaz mode commands in test_aks_commands.py.

@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@NickKeller
Copy link
Copy Markdown
Member Author

NickKeller commented Jul 11, 2025

Yep, that's a known error with my service for now, not an error with aaz. We have a fix deployed in staging, so I queued up a test for that:https://dev.azure.com/msazure/CloudNativeCompute/_build/results?buildId=130078326&view=results.

Looks like the test framework isn't obfuscating the subscription id properly?

The error you saw will be fixed with the new official release which will be rolling soon

@FumingZhang
Copy link
Copy Markdown
Member

The test actually passed when executed in live mode, but failed when executed in replay mode, apparently because it did not handle some variable substitutions well, and I suppose failures in replay mode can be ignored.

[gw0] [100%] PASSED azure-cli/src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_safeguards.py::AksSafeguardsScenario::test_aks_deployment_safeguards

https://dev.azure.com/msazure/CloudNativeCompute/_build/results?buildId=130078326&view=logs&j=b162b355-d59d-5864-ce0f-0a70f12dd28b&t=dc59ccd1-231f-538b-777f-33a592c7ca57&l=2577

@NickKeller
Copy link
Copy Markdown
Member Author

@yanzhudd any objections to this PR?

FumingZhang
FumingZhang previously approved these changes Jul 18, 2025
@yanzhudd yanzhudd changed the title [AKS] Add "aks safeguards" command group to aks command modules [AKS] az aks safeguards: Add command group to manage deployment safeguards Jul 22, 2025
Comment thread src/azure-cli/azure/cli/command_modules/acs/aaz/latest/aks/safeguards/_create.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acs/aaz/latest/aks/safeguards/_delete.py Outdated
…eguards/_create.py

Co-authored-by: Yan Zhu <105691024+yanzhudd@users.noreply.github.com>
…eguards/_delete.py

Co-authored-by: Yan Zhu <105691024+yanzhudd@users.noreply.github.com>
@NickKeller
Copy link
Copy Markdown
Member Author

@yanzhudd I've addressed your comments, thanks!

@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Copy Markdown
Member

@FumingZhang FumingZhang left a comment

Choose a reason for hiding this comment

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

CI failed with following error, please update the API version used in your recording file.

      raise AssertionError(ex)

E AssertionError: Can't overwrite existing cassette ('/mnt/vss/_work/1/s/src/azure-cli/azure/cli/command_modules/acs/tests/latest/recordings/test_aks_deployment_safeguards.yaml') in your current record mode ('once').
E No match for the request (<Request (PUT) https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/akssafeguards-000002?api-version=2025-05-01>) was found.
E Found 1 similar requests with 1 different matcher(s) :
E
E 1 - (<Request (PUT) https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli-000001/providers/Microsoft.ContainerService/managedClusters/akssafeguards-000002?api-version=2025-04-01>)..)
E Matchers succeeded : ['method', 'scheme', 'host', 'port', 'path']
E Matchers failed :
E _custom_request_query_matcher - assertion failure :
E None

@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@NickKeller
Copy link
Copy Markdown
Member Author

@yanzhudd can you please take another look?

@yanzhudd yanzhudd merged commit bbd3acc into Azure:dev Jul 24, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AKS az aks/acs/openshift Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants