Skip to content

{AKS} az aks enable-addons --addon monitoring: handle existing linked resource in AMPLS gracefully#31899

Merged
yanzhudd merged 11 commits intoAzure:devfrom
zanejohnson-azure:dev
Aug 25, 2025
Merged

{AKS} az aks enable-addons --addon monitoring: handle existing linked resource in AMPLS gracefully#31899
yanzhudd merged 11 commits intoAzure:devfrom
zanejohnson-azure:dev

Conversation

@zanejohnson-azure
Copy link
Copy Markdown
Contributor

@zanejohnson-azure zanejohnson-azure commented Aug 1, 2025

Related command
az aks enable-addons --addon monitoring

Description
if the workspace already exists in the ampls, when enable container insights addon with amplsId for the first time, there will be an resource conflict error.

Testing Guide

  1. add a workspace to ampls.
  2. then run the
    az aks enable-addons --addon monitoring --name {cluster-name} --resource-group {resource-group-name} --workspace-resource-id {law-id} --ampls-resource-id {ampls-id}

commit: e507960

  • without this fix, there will be following error, and container insights feature can't be enabled.

(azure-cli-dev-env-dev-fork) azureuser@jumpbox-vm:/azure-cli-dev-fork$ deactivate
azureuser@jumpbox-vm:~/azure-cli-dev-fork$ az aks enable-addons
--addon monitoring
--name private-aks3
--resource-group private-rg3
--workspace-resource-id "/subscriptions//resourceGroups//providers/Microsoft.OperationalInsights/workspaces/bug-fix-1"
--ampls-resource-id "/subscriptions//resourceGroups//providers/microsoft.insights/privateLinkScopes/private-aks3-ampls"

Conflict({
"error": {
"code": "Conflict",
"message": "Scoped resource with same linked resource id already exists in this private link scope",
"innererror": {
"trace": [
"Microsoft.AppInsights.Nexus.ResourceStore.ResourceStoreException"
]
}
}
})

  • with this fix:
    error is gone. logs can stream to log analytics workspace

azureuser@jumpbox-vm:/azure-cli-dev-fork$ source azure-cli-dev-env-dev-fork/bin/activate
(azure-cli-dev-env-dev-fork) azureuser@jumpbox-vm:~/azure-cli-dev-fork$ az aks enable-addons
--addon monitoring
--name private-aks3
--resource-group private-rg3
--workspace-resource-id "/subscriptions//resourceGroups//providers/Microsoft.OperationalInsights/workspaces/bug-fix-1"
--ampls-resource-id "/subscriptions//resourceGroups//providers/microsoft.insights/privateLinkScopes/private-aks3-ampls"

/home/azureuser/azure-cli-dev-fork/azure-cli-dev-env-dev-fork/bin/az:4: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import('pkg_resources').require('azure-cli==2.76.0')

/ InProgress ..
...
...
"workloadAutoScalerProfile": {
"keda": null,
"verticalPodAutoscaler": null
}
}

  • query heartbeat in law

azureuser@jumpbox-vm:~/azure-cli-dev-fork$ az monitor log-analytics query
--workspace ""
--analytics-query "Heartbeat | where TimeGenerated > ago(30m)"
--timespan "PT30M"

[
{
"Category": "Azure Monitor Agent",
"Computer": "aks-userpool-xxxxxxx-vmss000001",
"ComputerEnvironment": "Non-Azure",
"ComputerIP": "fd40:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx",
"ComputerPrivateIPs": "["10.xxx.xxx.xxx"]",
"OSName": "Common Base Linux Mariner",
"OSType": "Linux",
"Resource": "private-aks3",
"ResourceGroup": "private-rg3",
"ResourceId": "/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/private-aks3",
"SubscriptionId": "",
"TenantId": "",
"TimeGenerated": "2025-08-01T05:16:23.8004461Z",
"_ResourceId": "/subscriptions//resourcegroups//providers/microsoft.containerservice/managedclusters/private-aks3"
}
]

  • query containerV2 log in law

~/Docker-Provider/test/scenario$ az monitor log-analytics query
--workspace "<REDACTED_WORKSPACE_ID>"
--analytics-query "ContainerLogV2 | where TimeGenerated > ago(30m)"
--timespan "PT2M"

/path/to/az:4: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import('pkg_resources').require('azure-cli==2.76.0')

[
{
"Computer": "<REDACTED_COMPUTER_NAME>",
"ContainerId": "<REDACTED_CONTAINER_ID>",
"ContainerName": "second-log-app",
"KubernetesMetadata": "None",
"LogLevel": "unknown",
"LogMessage": "281",
"LogSource": "stdout",
"PodName": "second-log-app-5474ff74c-sfpbm",
"PodNamespace": "windows-log-ltsc2022",
"SourceSystem": "",
"TableName": "PrimaryResult",
"TenantId": "<REDACTED_TENANT_ID>",
"TimeGenerated": "2025-08-01T17:16:23.8465413Z",
"Type": "ContainerLogV2",
"_ResourceId": "/subscriptions/<REDACTED_SUBSCRIPTION_ID>/resourcegroups/<REDACTED_RG>/providers/microsoft.containerservice/managedclusters/<REDACTED_CLUSTER>"
},
{
"Computer": "<REDACTED_COMPUTER_NAME>",
"ContainerId": "<REDACTED_CONTAINER_ID>",
"ContainerName": "second-log-app",
"KubernetesMetadata": "None",
"LogLevel": "unknown",
"LogMessage": "282",
"LogSource": "stdout",
"PodName": "second-log-app-5474ff74c-sfpbm",
"PodNamespace": "windows-log-ltsc2022",
"SourceSystem": "",
"TableName": "PrimaryResult",
"TenantId": "<REDACTED_TENANT_ID>",
"TimeGenerated": "2025-08-01T17:16:24.8573817Z",
"Type": "ContainerLogV2",
"_ResourceId": "/subscriptions/<REDACTED_SUBSCRIPTION_ID>/resourcegroups/<REDACTED_RG>/providers/microsoft.containerservice/managedclusters/<REDACTED_CLUSTER>"
}
]


History Notes

{AKS} az aks enable-addons --addon monitoring: handle existing linked resource in AMPLS gracefully


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


commit: d1e446a

az monitor log-analytics query
--workspace ""
--analytics-query "ContainerLogV2 | where TimeGenerated > ago(5m)"
--timespan "PT30M"
/home//azure-cli-dev-env/bin/az:4: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import('pkg_resources').require('azure-cli==2.76.0')
[
{
"Computer": "",
"ContainerId": "",
"ContainerName": "second-log-app",
"KubernetesMetadata": "None",
"LogLevel": "unknown",
"LogMessage": "20664",
"LogSource": "stdout",
"PodName": "second-log-app-",
"PodNamespace": "windows-log-ltsc2022",
"SourceSystem": "",
"TableName": "PrimaryResult",
"TenantId": "",
"TimeGenerated": "2025-08-01T22:58:45.4967915Z",
"Type": "ContainerLogV2",
"_ResourceId": "/subscriptions//resourcegroups//providers/microsoft.containerservice/managedclusters/"
},
{
"Computer": "",
"ContainerId": "",
"ContainerName": "second-log-app",
"KubernetesMetadata": "None",
"LogLevel": "unknown",
"LogMessage": "20665",
"LogSource": "stdout",
"PodName": "second-log-app-",
"PodNamespace": "windows-log-ltsc2022",
"SourceSystem": "",
"TableName": "PrimaryResult",
"TenantId": "",
"TimeGenerated": "2025-08-01T22:58:46.5169425Z",
"Type": "ContainerLogV2",
"_ResourceId": "/subscriptions//resourcegroups//providers/microsoft.containerservice/managedclusters/"
}
]

Copilot AI review requested due to automatic review settings August 1, 2025 04:48
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Aug 1, 2025

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

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

azure-client-tools-bot-prd bot commented Aug 1, 2025

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Aug 1, 2025

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Aug 1, 2025

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>

This comment was marked as outdated.

This comment was marked as outdated.

@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@FumingZhang FumingZhang requested a review from ganga1980 August 1, 2025 06:30
error = e
except HttpResponseError as e:
if e.status_code == 409 and "Scoped resource with same linked resource id already exists" in str(e):
logger.info("Scoped resource with same linked resource id already exists, skipping")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how reliable this message? don't we have reliable way to check if the resource already exists than checking by message?

Copy link
Copy Markdown
Contributor Author

@zanejohnson-azure zanejohnson-azure Aug 1, 2025

Choose a reason for hiding this comment

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

changed to a more robust way

Comment thread src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py
Comment thread src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py
@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Comment thread src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py
@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Aug 15, 2025

Please fix CI issues

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

This PR fixes a conflict error that occurs when enabling AKS monitoring addon with AMPLS (Azure Monitor Private Link Scope) when the workspace is already linked to the AMPLS. The fix implements graceful handling by checking for existing linked resources before attempting to create new ones.

  • Added a check to verify if a resource is already scoped to AMPLS before creating the scope
  • Refactored the create_ampls_scope function to be more generic and handle any scoped resource
  • Implemented proper error handling and logging for the AMPLS scoped resource verification

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

scoped_resources_data = json.loads(response.text)

# Check if any scoped resource has the same linkedResourceId
for i, scoped_resource in enumerate(scoped_resources_data.get('value', [])):
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

The variable i is unused in the loop. Consider using for scoped_resource in scoped_resources_data.get('value', []): instead to improve code clarity.

Suggested change
for i, scoped_resource in enumerate(scoped_resources_data.get('value', [])):
for scoped_resource in scoped_resources_data.get('value', []):

Copilot uses AI. Check for mistakes.
Comment thread src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py
@FumingZhang
Copy link
Copy Markdown
Member

@zanejohnson-azure please fix failed CI checks.

@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@FumingZhang
Copy link
Copy Markdown
Member

there's still style check failure

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@FumingZhang
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Aug 23, 2025

Please fix CI issues

@yanzhudd
Copy link
Copy Markdown
Contributor

please note that the code completion date for the upcoming release is 08/26/2025 07:00 UTC. If you want to catch this release train, please resolve the CI issues ASAP, otherwise it has to be postponed to next sprint (10/14)

@zanejohnson-azure
Copy link
Copy Markdown
Contributor Author

zanejohnson-azure commented Aug 25, 2025

Please fix CI issues

many other PRs are failing too.
see https://dev.azure.com/azclitools/public/_build?definitionId=62&_a=summary.

i believe the failing checks are caused by some other issues in az cli itself. I see there is a pending PR fix.
#31996
https://dev.azure.com/azclitools/public/_build/results?buildId=267735&view=results

TODO: rebase after the pending PR 31996 is merged.

@yanzhudd
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@yanzhudd yanzhudd merged commit 10efe2d into Azure:dev Aug 25, 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.

7 participants