Skip to content
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

{AKS} Monitoring addon MSI auth - Remove unused ContainerInsights Solution resource #23076

Merged
merged 16 commits into from
Jul 6, 2022
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 0 additions & 116 deletions src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import datetime
import json

from azure.cli.command_modules.acs._client_factory import cf_resource_groups, cf_resources
Expand Down Expand Up @@ -459,121 +458,6 @@ def ensure_container_insights_for_monitoring(
error = e
else:
raise error
if not _is_container_insights_solution_exists(cmd, workspace_resource_id):
unix_time_in_millis = int(
(
datetime.datetime.utcnow() -
datetime.datetime.utcfromtimestamp(0)
).total_seconds() * 1000.0
)

solution_deployment_name = "ContainerInsights-{}".format(
unix_time_in_millis
)

# pylint: disable=line-too-long
template = {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceResourceId": {
"type": "string",
"metadata": {
"description": "Azure Monitor Log Analytics Resource ID"
},
},
"workspaceRegion": {
"type": "string",
"metadata": {
"description": "Azure Monitor Log Analytics workspace region"
},
},
"solutionDeploymentName": {
"type": "string",
"metadata": {
"description": "Name of the solution deployment"
},
},
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"name": "[parameters('solutionDeploymentName')]",
"apiVersion": "2017-05-10",
"subscriptionId": "[split(parameters('workspaceResourceId'),'/')[2]]",
"resourceGroup": "[split(parameters('workspaceResourceId'),'/')[4]]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"apiVersion": "2015-11-01-preview",
"type": "Microsoft.OperationsManagement/solutions",
"location": "[parameters('workspaceRegion')]",
"name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')[8], ')')]",
"properties": {
"workspaceResourceId": "[parameters('workspaceResourceId')]"
},
"plan": {
"name": "[Concat('ContainerInsights', '(', split(parameters('workspaceResourceId'),'/')[8], ')')]",
"product": "[Concat('OMSGallery/', 'ContainerInsights')]",
"promotionCode": "",
"publisher": "Microsoft",
},
}
],
},
"parameters": {},
},
}
],
}

params = {
"workspaceResourceId": {"value": workspace_resource_id},
"workspaceRegion": {"value": location},
"solutionDeploymentName": {"value": solution_deployment_name},
}

deployment_name = "aks-monitoring-{}".format(unix_time_in_millis)
# publish the Container Insights solution to the Log Analytics workspace
return _invoke_deployment(
cmd,
resource_group,
deployment_name,
template,
params,
validate=False,
no_wait=False,
subscription_id=subscription_id,)


def _is_container_insights_solution_exists(cmd, workspace_resource_id):
# extract subscription ID and resource group from workspace_resource_id URL
is_exists = False
_MAX_RETRY_TIMES = 3
parsed = parse_resource_id(workspace_resource_id)
subscription_id, resource_group, workspace_name = parsed[
"subscription"], parsed["resource_group"], parsed["name"]
solution_resource_id = "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.OperationsManagement/solutions/ContainerInsights({2})".format(
subscription_id, resource_group, workspace_name)
resources = cf_resources(cmd.cli_ctx, subscription_id)
for retry_count in range(0, _MAX_RETRY_TIMES):
try:
resources.get_by_id(solution_resource_id, '2015-11-01-preview')
is_exists = True
break
except HttpResponseError as ex:
if ex.status_code == 404:
is_exists = False
break
if retry_count >= (_MAX_RETRY_TIMES - 1):
raise ex
return is_exists


def _invoke_deployment(
ganga1980 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down