Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b633783
add cluster spn with metric publisher role to aks cluster resource
ganga1980 Feb 14, 2019
34b4ff2
refactor the code
ganga1980 Feb 14, 2019
5d5e06f
fix default workspace issue in china cloud
ganga1980 Feb 15, 2019
13b28a1
add metrics publisher role assignment only in public cloud
ganga1980 Feb 15, 2019
20b8de5
fix pr feedback
ganga1980 Feb 15, 2019
459c11e
fix build error
ganga1980 Feb 20, 2019
77582df
fix lint error
ganga1980 Feb 20, 2019
86b7364
Merge remote-tracking branch 'upstream/dev' into dev
ganga1980 May 18, 2019
552d381
update region mapping
ganga1980 May 18, 2019
c345d65
order regions in sortorder
ganga1980 May 18, 2019
72aa35f
fix trailing whitespaces
ganga1980 May 18, 2019
f98956b
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
ganga1980 Jun 3, 2019
c284e2c
fix default log analytics region mapping
ganga1980 Jun 3, 2019
6849944
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
ganga1980 Jun 4, 2019
da318f6
merge upstream changes
ganga1980 Jul 15, 2019
c88769c
fix map index error if key not found
ganga1980 Jul 18, 2019
df2bd1b
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
ganga1980 Jul 19, 2019
20a1e9e
fix lint errors
ganga1980 Jul 19, 2019
36d0726
fix uninitialized error
ganga1980 Jul 20, 2019
5f2f854
get latest changes from upstream
ganga1980 Nov 26, 2019
38eb2f9
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
ganga1980 Dec 1, 2019
6e5e85f
update to new API version for ARO
ganga1980 Dec 2, 2019
6fbbcc6
use latest api version for ARO
ganga1980 Dec 3, 2019
296e1b3
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
ganga1980 Jan 6, 2020
0f753b1
revert to workspace_resource_id in os management profile
ganga1980 Jan 6, 2020
a9a196e
fix test case
ganga1980 Jan 10, 2020
b15b774
fixed test failure
ganga1980 Jan 13, 2020
c898fa2
added recording file
ganga1980 Jan 13, 2020
ae6c3e7
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
ganga1980 Jan 13, 2020
5a665f4
merge upstream changes
ganga1980 Jan 28, 2022
a0acadd
dont containerinsights solution
ganga1980 Feb 2, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -479,99 +479,6 @@ def ensure_container_insights_for_monitoring(
else:
raise error

else:
# legacy auth with LA workspace solution
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 _invoke_deployment(
Expand Down
122 changes: 0 additions & 122 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2951,128 +2951,6 @@ def _get_or_add_extension(cmd, extension_name, extension_module, update=False):
return _install_dev_spaces_extension(cmd, extension_name)
return True


def _ensure_container_insights_for_monitoring(cmd, addon):
# Workaround for this addon key which has been seen lowercased in the wild.
for key in list(addon.config):
if (key.lower() == CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID.lower() and
key != CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID):
addon.config[CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID] = addon.config.pop(
key)

workspace_resource_id = addon.config[CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID]

workspace_resource_id = workspace_resource_id.strip()

if not workspace_resource_id.startswith('/'):
workspace_resource_id = '/' + workspace_resource_id

if workspace_resource_id.endswith('/'):
workspace_resource_id = workspace_resource_id.rstrip('/')

# extract subscription ID and resource group from workspace_resource_id URL
try:
subscription_id = workspace_resource_id.split('/')[2]
resource_group = workspace_resource_id.split('/')[4]
except IndexError:
raise CLIError(
'Could not locate resource group in workspace-resource-id URL.')

# region of workspace can be different from region of RG so find the location of the workspace_resource_id
resources = cf_resources(cmd.cli_ctx, subscription_id)
try:
resource = resources.get_by_id(
workspace_resource_id, '2015-11-01-preview')
location = resource.location
except CloudError as ex:
raise ex

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 _ensure_aks_acr(cmd,
assignee,
acr_name_or_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources):
# http_application_routing enabled
instance = mock.MagicMock()
instance.addon_profiles = None

instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000',
'clitest000001', 'clitest000001', 'http_application_routing', enable=True)
self.assertIn(CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, instance.addon_profiles)
Expand Down Expand Up @@ -780,18 +780,12 @@ def test_ensure_container_insights_for_monitoring(self, invoke_def, cf_resources
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: wsID
}
self.assertTrue(ensure_container_insights_for_monitoring(cmd, addon, subscription_id, rg_name, cluster_name, location))
args, kwargs = invoke_def.call_args
self.assertEqual(args[3]['resources'][0]['type'], "Microsoft.Resources/deployments")
self.assertEqual(args[4]['workspaceResourceId']['value'], wsID)

# when addon config key is lower cased
addon.config = {
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: wsID
}
self.assertTrue(ensure_container_insights_for_monitoring(cmd, addon, subscription_id, rg_name, cluster_name, location))
args, kwargs = invoke_def.call_args
self.assertEqual(args[3]['resources'][0]['type'], "Microsoft.Resources/deployments")
self.assertEqual(args[4]['workspaceResourceId']['value'], wsID)


@mock.patch('azure.cli.command_modules.acs.custom._urlretrieve')
@mock.patch('azure.cli.command_modules.acs.custom.logger')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def test_update_addons(self, rg_def, cf_resource_groups, cf_resources):
# http_application_routing enabled
instance = mock.MagicMock()
instance.addon_profiles = None

instance = _update_addons(MockCmd(self.cli), instance, '00000000-0000-0000-0000-000000000000',
'clitest000001', 'clitest000001', 'http_application_routing', enable=True)
self.assertIn(CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME, instance.addon_profiles)
Expand Down Expand Up @@ -780,18 +780,13 @@ def test_ensure_container_insights_for_monitoring(self, invoke_def, cf_resources
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: wsID
}
self.assertTrue(ensure_container_insights_for_monitoring(cmd, addon, subscription_id, rg_name, cluster_name, location))
args, kwargs = invoke_def.call_args
self.assertEqual(args[3]['resources'][0]['type'], "Microsoft.Resources/deployments")
self.assertEqual(args[4]['workspaceResourceId']['value'], wsID)

# when addon config key is lower cased
addon.config = {
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: wsID
}
self.assertTrue(ensure_container_insights_for_monitoring(cmd, addon, subscription_id, rg_name, cluster_name, location))
args, kwargs = invoke_def.call_args
self.assertEqual(args[3]['resources'][0]['type'], "Microsoft.Resources/deployments")
self.assertEqual(args[4]['workspaceResourceId']['value'], wsID)


@mock.patch('azure.cli.command_modules.acs.custom._urlretrieve')
@mock.patch('azure.cli.command_modules.acs.custom.logger')
Expand Down