Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Release History
* Fix issue #11658: `az group export` command does not support `--query` and `--output` parameters
* Fix issue #10279: The exit code of `az group deployment validate` is 0 when the verification fails

**Azure Red Hat OpenShift**

* Add `monitor` subgroup to manage Log Analytics monitoring in Azure Red Hat OpensShift cluster

**IoT**

* Deprecated 'IoT hub Job' commands.
Expand Down
23 changes: 23 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,26 @@
text: |-
az openshift wait -g MyResourceGroup -n MyManagedCluster --updated --interval 60 --timeout 1800
"""

helps['openshift monitor'] = """
type: group
short-summary: Commands to manage Log Analytics monitoring. Requires "--workspace-id".
"""

helps['openshift monitor enable'] = """
Copy link
Contributor

Choose a reason for hiding this comment

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

Is openshift log enable better? Monitor is a quite big scope. Will you support other monitor-related feature later? or it can be a command like openshift enable-log instead of openshift monitor enable.

Copy link
Author

Choose a reason for hiding this comment

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

I don't think log is a better name. Log Analytics is only part of Azure Monitor and this is what this PR is intended for.
This PR creates a subgroup monitor, so it is extensible and can in future support more features.

Copy link
Author

Choose a reason for hiding this comment

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

It is also more in line with how AKS achieves the same thing

type: command
short-summary: Enable Log Analytics monitoring. Requires "--workspace-id".
examples:
- name: Enable Log Analytics in a managed OpenShift cluster.
text: |-
az openshift monitor enable -g MyResourceGroup -n MyManagedCluster --workspace-id "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/{workspace-id}"
"""

helps['openshift monitor disable'] = """
type: command
short-summary: Disable Log Analytics monitoring.
examples:
- name: Disable Log Analytics monitoring.
text: |-
az openshift monitor disable -g MyResourceGroup -n MyManagedCluster
"""
3 changes: 3 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ def load_arguments(self, _):
c.argument('customer_admin_group_id', options_list=['--customer-admin-group-id'])
c.argument('workspace_id')

with self.argument_context('openshift monitor enable') as c:
c.argument('workspace_id', help='The resource ID of an existing Log Analytics Workspace to use for storing monitoring data.')


def _get_default_install_location(exe_name):
system = platform.system()
Expand Down
6 changes: 6 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,9 @@ def load_command_table(self, _):
g.custom_show_command('show', 'openshift_show')
g.custom_command('list', 'osa_list', table_transformer=osa_list_table_format)
g.wait_command('wait')

# OSA monitor subgroup
with self.command_group('openshift monitor', openshift_managed_clusters_sdk,
client_factory=cf_openshift_managed_clusters) as g:
g.custom_command('enable', 'openshift_monitor_enable', supports_no_wait=True)
g.custom_command('disable', 'openshift_monitor_disable', supports_no_wait=True)
31 changes: 26 additions & 5 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3113,6 +3113,15 @@ def osa_list(cmd, client, resource_group_name=None):
return _remove_osa_nulls(list(managed_clusters))


def _format_workspace_id(workspace_id):
workspace_id = workspace_id.strip()
if not workspace_id.startswith('/'):
workspace_id = '/' + workspace_id
if workspace_id.endswith('/'):
workspace_id = workspace_id.rstrip('/')
return workspace_id


def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=too-many-locals
location=None,
compute_vm_size="Standard_D4s_v3",
Expand Down Expand Up @@ -3197,11 +3206,7 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=
name=vnet_peer
)
if workspace_id is not None:
workspace_id = workspace_id.strip()
if not workspace_id.startswith('/'):
workspace_id = '/' + workspace_id
if workspace_id.endswith('/'):
workspace_id = workspace_id.rstrip('/')
workspace_id = _format_workspace_id(workspace_id)
monitor_profile = OpenShiftManagedClusterMonitorProfile(enabled=True, workspace_resource_id=workspace_id) # pylint: disable=line-too-long
else:
monitor_profile = None
Expand Down Expand Up @@ -3259,6 +3264,22 @@ def openshift_scale(cmd, client, resource_group_name, name, compute_count, no_wa
return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance)


def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_id, no_wait=False):
instance = client.get(resource_group_name, name)
workspace_id = _format_workspace_id(workspace_id)
monitor_profile = OpenShiftManagedClusterMonitorProfile(enabled=True, workspace_resource_id=workspace_id) # pylint: disable=line-too-long
instance.monitor_profile = monitor_profile

return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance)


def openshift_monitor_disable(cmd, client, resource_group_name, name, no_wait=False):
instance = client.get(resource_group_name, name)
monitor_profile = OpenShiftManagedClusterMonitorProfile(enabled=False, workspace_resource_id=None) # pylint: disable=line-too-long
instance.monitor_profile = monitor_profile
return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance)


def _get_load_balancer_outbound_ips(load_balancer_outbound_ips):
"""parse load balancer profile outbound IP ids and return an array of references to the outbound IP resources"""
load_balancer_outbound_ip_resources = None
Expand Down
Loading