Skip to content

Commit

Permalink
add --ampls-resource-id and --enable-high-log-scale-mode options (#7754)
Browse files Browse the repository at this point in the history
  • Loading branch information
ganga1980 authored Jul 31, 2024
1 parent 7cf3a61 commit a297133
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 129 deletions.
7 changes: 6 additions & 1 deletion src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

7.0.0b3
++++++++
* Add option `--enable-high-log-scale-mode` to `az aks create --enable-addons monitoring` and `az aks enable-addons -a monitoring` .
* Add option `--ampls-resource-id` to `az aks create --enable-addons monitoring` and `az aks enable-addons -a monitoring` .

7.0.0b2
++++++++
* Update the minimum required cli core version to `2.61.0`.
* Add option `--enable-imds-restriction --disable-imds-restriction` to `az aks create` and `az aks update`.
* Add option `--enable-imds-restriction --disable-imds-restriction` to `az aks create` and `az aks update`.
* Introduce valdations to `az aks create` and `az aks update` while using PremiumV2 disk during enabling Azure Container Storage.
* Delete the Azure Container Storage installation after failure to prevent retries.

Expand Down
24 changes: 24 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@
- name: --data-collection-settings
type: string
short-summary: Path to JSON file containing data collection settings for Monitoring addon.
- name: --enable-high-log-scale-mode
type: bool
short-summary: Enable High Log Scale Mode for Container Logs.
- name: --ampls-resource-id
type: string
short-summary: Resource ID of Azure Monitor Private Link scope for Monitoring Addon.
- name: --enable-cluster-autoscaler
type: bool
short-summary: Enable cluster autoscaler, default value is false.
Expand Down Expand Up @@ -2307,6 +2313,12 @@
- name: --data-collection-settings
type: string
short-summary: Path to JSON file containing data collection settings for Monitoring addon.
- name: --enable-high-log-scale-mode
type: bool
short-summary: Enable High Log Scale Mode for Container Logs.
- name: --ampls-resource-id
type: string
short-summary: Resource ID of Azure Monitor Private Link scope for Monitoring Addon.
- name: --subnet-name -s
type: string
short-summary: The subnet name for the virtual node to use.
Expand Down Expand Up @@ -2374,6 +2386,12 @@
- name: --data-collection-settings
type: string
short-summary: Path to JSON file containing data collection settings for Monitoring addon.
- name: --enable-high-log-scale-mode
type: bool
short-summary: Enable High Log Scale Mode for Container Logs.
- name: --ampls-resource-id
type: string
short-summary: Resource ID of Azure Monitor Private Link scope for Monitoring Addon.
- name: --subnet-name -s
type: string
short-summary: The subnet name for the virtual node to use.
Expand Down Expand Up @@ -2455,6 +2473,12 @@
- name: --data-collection-settings
type: string
short-summary: Path to JSON file containing data collection settings for Monitoring addon.
- name: --enable-high-log-scale-mode
type: bool
short-summary: Enable High Log Scale Mode for Container Logs.
- name: --ampls-resource-id
type: string
short-summary: Resource ID of Azure Monitor Private Link scope for Monitoring Addon.
- name: --subnet-name -s
type: string
short-summary: The subnet name for the virtual node to use.
Expand Down
16 changes: 16 additions & 0 deletions src/aks-preview/azext_aks_preview/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import platform
import re
import stat
import sys
import tempfile
from typing import TypeVar

Expand Down Expand Up @@ -330,3 +331,18 @@ def process_message_for_run_command(message):

for line in result[2:len(result) - 2]:
print(line)


def check_is_azure_cli_core_editable_installed():
try:
editable = os.getenv("AZURE_CLI_CORE_EDITABLE", "false").lower() == "true"
if editable:
return True
for path_item in sys.path:
egg_link = os.path.join(path_item, 'azure-cli-core.egg-link')
if os.path.isfile(egg_link):
os.environ["AZURE_CLI_CORE_EDITABLE"] = "true"
return True
except Exception as ex: # pylint: disable=broad-except
logger.debug("failed to check if azure-cli-core is installed as editable: %s", ex)
return False
8 changes: 8 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ def load_arguments(self, _):
)
c.argument("enable_syslog", arg_type=get_three_state_flag(), is_preview=True)
c.argument("data_collection_settings", is_preview=True)
c.argument("enable_high_log_scale_mode", arg_type=get_three_state_flag(), is_preview=True)
c.argument("ampls_resource_id", is_preview=True)
c.argument("aci_subnet_name")
c.argument("appgw_name", arg_group="Application Gateway")
c.argument("appgw_subnet_cidr", arg_group="Application Gateway")
Expand Down Expand Up @@ -1856,6 +1858,8 @@ def load_arguments(self, _):
)
c.argument("enable_syslog", arg_type=get_three_state_flag(), is_preview=True)
c.argument("data_collection_settings", is_preview=True)
c.argument("enable_high_log_scale_mode", arg_type=get_three_state_flag(), is_preview=True)
c.argument("ampls_resource_id", is_preview=True)
c.argument(
"dns_zone_resource_id",
deprecate_info=c.deprecate(
Expand Down Expand Up @@ -1911,6 +1915,8 @@ def load_arguments(self, _):
)
c.argument("enable_syslog", arg_type=get_three_state_flag(), is_preview=True)
c.argument("data_collection_settings", is_preview=True)
c.argument("enable_high_log_scale_mode", arg_type=get_three_state_flag(), is_preview=True)
c.argument("ampls_resource_id", is_preview=True)
c.argument(
"dns_zone_resource_id",
deprecate_info=c.deprecate(
Expand Down Expand Up @@ -1949,6 +1955,8 @@ def load_arguments(self, _):
)
c.argument("enable_syslog", arg_type=get_three_state_flag(), is_preview=True)
c.argument("data_collection_settings", is_preview=True)
c.argument("enable_high_log_scale_mode", arg_type=get_three_state_flag(), is_preview=True)
c.argument("ampls_resource_id", is_preview=True)
c.argument(
"dns_zone_resource_id",
deprecate_info=c.deprecate(
Expand Down
15 changes: 8 additions & 7 deletions src/aks-preview/azext_aks_preview/addonconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def enable_addons(
dns_zone_resource_ids=None,
enable_msi_auth_for_monitoring=True,
enable_syslog=False,
data_collection_settings=None
data_collection_settings=None,
ampls_resource_id=None,
enable_high_log_scale_mode=False,
):
instance = client.get(resource_group_name, name)
# this is overwritten by _update_addons(), so the value needs to be recorded here
Expand Down Expand Up @@ -99,9 +101,7 @@ def enable_addons(
rotation_poll_interval=rotation_poll_interval,
no_wait=no_wait,
dns_zone_resource_id=dns_zone_resource_id,
dns_zone_resource_ids=dns_zone_resource_ids,
enable_syslog=enable_syslog,
data_collection_settings=data_collection_settings,
dns_zone_resource_ids=dns_zone_resource_ids
)

if CONST_MONITORING_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[
Expand All @@ -124,7 +124,9 @@ def enable_addons(
create_dcr=True,
create_dcra=True,
enable_syslog=enable_syslog,
data_collection_settings=data_collection_settings
data_collection_settings=data_collection_settings,
ampls_resource_id=ampls_resource_id,
enable_high_log_scale_mode=enable_high_log_scale_mode
)
else:
# monitoring addon will use legacy path
Expand Down Expand Up @@ -204,8 +206,6 @@ def update_addons(
dns_zone_resource_id=None,
dns_zone_resource_ids=None,
no_wait=False, # pylint: disable=unused-argument
enable_syslog=False, # pylint: disable=unused-argument
data_collection_settings=None, # pylint: disable=unused-argument
):
# parse the comma-separated addons argument
addon_args = addons.split(',')
Expand Down Expand Up @@ -398,6 +398,7 @@ def add_ingress_appgw_addon_role_assignment(result, cmd):
service_principal_msi_id = None
# Check if service principal exists, if it does, assign permissions to service principal
# Else, provide permissions to MSI
is_service_principal = False
if (
hasattr(result, 'service_principal_profile') and
hasattr(result.service_principal_profile, 'client_id') and
Expand Down
30 changes: 24 additions & 6 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ def aks_create(
enable_msi_auth_for_monitoring=True,
enable_syslog=False,
data_collection_settings=None,
ampls_resource_id=None,
enable_high_log_scale_mode=False,
aci_subnet_name=None,
appgw_name=None,
appgw_subnet_cidr=None,
Expand Down Expand Up @@ -2014,6 +2016,8 @@ def aks_addon_enable(
dns_zone_resource_ids=None,
enable_syslog=False,
data_collection_settings=None,
ampls_resource_id=None,
enable_high_log_scale_mode=False
):
return enable_addons(
cmd,
Expand All @@ -2038,6 +2042,8 @@ def aks_addon_enable(
dns_zone_resource_ids=dns_zone_resource_ids,
enable_syslog=enable_syslog,
data_collection_settings=data_collection_settings,
ampls_resource_id=ampls_resource_id,
enable_high_log_scale_mode=enable_high_log_scale_mode
)


Expand Down Expand Up @@ -2068,6 +2074,8 @@ def aks_addon_update(
dns_zone_resource_ids=None,
enable_syslog=False,
data_collection_settings=None,
ampls_resource_id=None,
enable_high_log_scale_mode=False
):
instance = client.get(resource_group_name, name)
addon_profiles = instance.addon_profiles
Expand Down Expand Up @@ -2117,6 +2125,8 @@ def aks_addon_update(
dns_zone_resource_ids=dns_zone_resource_ids,
enable_syslog=enable_syslog,
data_collection_settings=data_collection_settings,
ampls_resource_id=ampls_resource_id,
enable_high_log_scale_mode=enable_high_log_scale_mode
)


Expand Down Expand Up @@ -2151,6 +2161,8 @@ def aks_disable_addons(cmd, client, resource_group_name, name, addons, no_wait=F
create_dcra=True,
enable_syslog=False,
data_collection_settings=None,
ampls_resource_id=None,
enable_high_log_scale_mode=False
)
except TypeError:
pass
Expand Down Expand Up @@ -2193,6 +2205,8 @@ def aks_enable_addons(
dns_zone_resource_ids=None,
enable_syslog=False,
data_collection_settings=None,
ampls_resource_id=None,
enable_high_log_scale_mode=False,
aks_custom_headers=None,
):
headers = get_aks_custom_headers(aks_custom_headers)
Expand Down Expand Up @@ -2228,8 +2242,6 @@ def aks_enable_addons(
no_wait=no_wait,
dns_zone_resource_id=dns_zone_resource_id,
dns_zone_resource_ids=dns_zone_resource_ids,
enable_syslog=enable_syslog,
data_collection_settings=data_collection_settings,
)
if (
CONST_MONITORING_ADDON_NAME in instance.addon_profiles and
Expand Down Expand Up @@ -2260,14 +2272,21 @@ def aks_enable_addons(
create_dcra=True,
enable_syslog=enable_syslog,
data_collection_settings=data_collection_settings,
ampls_resource_id=ampls_resource_id,
enable_high_log_scale_mode=enable_high_log_scale_mode
)
else:
# monitoring addon will use legacy path
if enable_syslog:
raise ArgumentUsageError(
"--enable-syslog can not be used without MSI auth.")
if enable_high_log_scale_mode:
raise ArgumentUsageError(
"--enable-high-log-scale-mode can not be used without MSI auth.")
if data_collection_settings is not None:
raise ArgumentUsageError("--data-collection-settings can not be used without MSI auth.")
if ampls_resource_id is not None:
raise ArgumentUsageError("--ampls-resource-id can not be used without MSI auth.")
ensure_container_insights_for_monitoring(
cmd,
instance.addon_profiles[CONST_MONITORING_ADDON_NAME],
Expand Down Expand Up @@ -2316,7 +2335,7 @@ def aks_rotate_certs(cmd, client, resource_group_name, name, no_wait=True):
return sdk_no_wait(no_wait, client.begin_rotate_cluster_certificates, resource_group_name, name)


def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements,
instance,
subscription_id,
resource_group_name,
Expand All @@ -2338,9 +2357,8 @@ def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
rotation_poll_interval=None,
dns_zone_resource_id=None,
dns_zone_resource_ids=None,
no_wait=False, # pylint: disable=unused-argument
enable_syslog=False,
data_collection_settings=None):
no_wait=False,): # pylint: disable=unused-argument

ManagedClusterAddonProfile = cmd.get_models(
"ManagedClusterAddonProfile",
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
Expand Down
38 changes: 38 additions & 0 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
)
from azext_aks_preview._helpers import (
check_is_apiserver_vnet_integration_cluster,
check_is_azure_cli_core_editable_installed,
check_is_private_cluster,
get_cluster_snapshot_by_snapshot_id,
setup_common_safeguards_profile,
Expand Down Expand Up @@ -3733,10 +3734,43 @@ def construct_mc_profile_preview(self, bypass_restore_defaults: bool = False) ->
# set up imds restriction(a property in network profile)
mc = self.set_up_imds_restriction(mc)

# validate the azure cli core version
self.verify_cli_core_version()

# DO NOT MOVE: keep this at the bottom, restore defaults
mc = self._restore_defaults_in_mc(mc)
return mc

def verify_cli_core_version(self):
from azure.cli.core import __version__ as core_version
monitor_options_specified = False
# in case in a super old version, the options are not available
try:
monitor_options_specified = any(
(
self.context.get_ampls_resource_id(),
self.context.get_enable_high_log_scale_mode(),
)
)
except Exception as ex: # pylint: disable=broad-except
logger.debug("failed to get the value of monitor_options: %s", ex)
monitor_options_specified = any(
(
self.__raw_parameters.get("ampls_resource_id"),
self.__raw_parameters.get("enable_high_log_scale_mode"),
)
)
finally:
if monitor_options_specified and (
core_version < "2.63.0" and
not check_is_azure_cli_core_editable_installed()
):
raise ArgumentUsageError(
f"The --ampls-resource-id and --enable-high-log-scale-mode options are only available in Azure CLI "
f"version 2.63.0 and later. Your current Azure CLI version is {core_version}. Please upgrade your "
"Azure CLI."
)

def check_is_postprocessing_required(self, mc: ManagedCluster) -> bool:
"""Helper function to check if postprocessing is required after sending a PUT request to create the cluster.
Expand Down Expand Up @@ -3842,6 +3876,10 @@ def postprocessing_after_mc_created(self, cluster: ManagedCluster) -> None:
create_dcr=False,
create_dcra=True,
enable_syslog=self.context.get_enable_syslog(),
data_collection_settings=self.context.get_data_collection_settings(),
is_private_cluster=self.context.get_enable_private_cluster(),
ampls_resource_id=self.context.get_ampls_resource_id(),
enable_high_log_scale_mode=self.context.get_enable_high_log_scale_mode(),
)

# ingress appgw addon
Expand Down
Loading

0 comments on commit a297133

Please sign in to comment.