diff --git a/src/k8s-extension/HISTORY.rst b/src/k8s-extension/HISTORY.rst index b973a4fe888..76783368e59 100644 --- a/src/k8s-extension/HISTORY.rst +++ b/src/k8s-extension/HISTORY.rst @@ -3,6 +3,11 @@ Release History =============== +1.4.3 +++++++++++++++++++ +* microsoft.azuremonitor.containers: Extend ContainerInsights Extension dataCollectionSettings with streams and containerlogv2 field. Also, add a kind tag in DCR creation for the ContainerInsights extension. +* microsoft.dapr: Use semver instead of packaging + 1.4.2 ++++++++++++++++++ * microsoft.azuremonitor.containers: ContainerInsights Extension Managed Identity Auth Enabled by default diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py index a943d88584c..119f29421e9 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py @@ -31,6 +31,7 @@ cf_resources, cf_resource_groups, cf_log_analytics) logger = get_logger(__name__) +DCR_API_VERSION = "2022-06-01" class ContainerInsights(DefaultExtension): @@ -100,7 +101,7 @@ def Delete(self, cmd, client, resource_group_name, cluster_name, name, cluster_t if (isinstance(useAADAuthSetting, str) and str(useAADAuthSetting).lower() == "true") or (isinstance(useAADAuthSetting, bool) and useAADAuthSetting): useAADAuth = True if useAADAuth: - association_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension?api-version=2021-04-01" + association_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension?api-version={DCR_API_VERSION}" for _ in range(3): try: send_raw_request(cmd.cli_ctx, "GET", association_url,) @@ -114,7 +115,7 @@ def Delete(self, cmd, client, resource_group_name, cluster_name, name, cluster_t pass # its OK to ignore the exception since MSI auth in preview if isDCRAExists: - association_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension?api-version=2021-04-01" + association_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension?api-version={DCR_API_VERSION}" for _ in range(3): try: send_raw_request(cmd.cli_ctx, "DELETE", association_url,) @@ -455,6 +456,8 @@ def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_r subscription_id = get_subscription_id(cmd.cli_ctx) workspace_resource_id = '' useAADAuth = True + if 'amalogs.useAADAuth' not in configuration_settings: + configuration_settings['amalogs.useAADAuth'] = "true" extensionSettings = {} if configuration_settings is not None: @@ -471,11 +474,15 @@ def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_r logger.info("provided useAADAuth flag is : %s", useAADAuthSetting) if (isinstance(useAADAuthSetting, str) and str(useAADAuthSetting).lower() == "true") or (isinstance(useAADAuthSetting, bool) and useAADAuthSetting): useAADAuth = True + else: + useAADAuth = False elif 'amalogs.useAADAuth' in configuration_settings: useAADAuthSetting = configuration_settings['amalogs.useAADAuth'] logger.info("provided useAADAuth flag is : %s", useAADAuthSetting) if (isinstance(useAADAuthSetting, str) and str(useAADAuthSetting).lower() == "true") or (isinstance(useAADAuthSetting, bool) and useAADAuthSetting): useAADAuth = True + else: + useAADAuth = False if useAADAuth and ('dataCollectionSettings' in configuration_settings): dataCollectionSettingsString = configuration_settings["dataCollectionSettings"] logger.info("provided dataCollectionSettings is : %s", dataCollectionSettingsString) @@ -495,6 +502,14 @@ def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_r namspaces = dataCollectionSettings["namespaces"] if isinstance(namspaces, list) is False: raise InvalidArgumentValueError('namespaces must be an array type') + if 'enableContainerLogV2' in dataCollectionSettings.keys(): + enableContainerLogV2Value = dataCollectionSettings["enableContainerLogV2"] + if not isinstance(enableContainerLogV2Value, bool): + raise InvalidArgumentValueError('enableContainerLogV2Value value MUST be either true or false') + if 'streams' in dataCollectionSettings.keys(): + streams = dataCollectionSettings["streams"] + if isinstance(streams, list) is False: + raise InvalidArgumentValueError('streams must be an array type') extensionSettings["dataCollectionSettings"] = dataCollectionSettings workspace_resource_id = workspace_resource_id.strip() @@ -673,23 +688,27 @@ def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_ if (cluster_region not in region_ids): raise ClientRequestError(f"Data Collection Rule Associations are not supported for cluster region {cluster_region}") - dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{dcr_resource_id}?api-version=2021-04-01" + dcr_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{dcr_resource_id}?api-version={DCR_API_VERSION}" # get existing tags on the container insights extension DCR if the customer added any existing_tags = get_existing_container_insights_extension_dcr_tags(cmd, dcr_url) + streams = ["Microsoft-ContainerInsights-Group-Default"] + if extensionSettings is not None and 'dataCollectionSettings' in extensionSettings.keys(): + dataCollectionSettings = extensionSettings["dataCollectionSettings"] + if dataCollectionSettings is not None and 'streams' in dataCollectionSettings.keys(): + streams = dataCollectionSettings["streams"] # create the DCR dcr_creation_body = json.dumps( { "location": workspace_region, "tags": existing_tags, + "kind": "Linux", "properties": { "dataSources": { "extensions": [ { "name": "ContainerInsightsExtension", - "streams": [ - "Microsoft-ContainerInsights-Group-Default" - ], + "streams": streams, "extensionName": "ContainerInsights", "extensionSettings": extensionSettings } @@ -697,10 +716,7 @@ def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_ }, "dataFlows": [ { - "streams": [ - "Microsoft-ContainerInsights-Group-Default" - - ], + "streams": streams, "destinations": ["la-workspace"], } ], @@ -735,7 +751,7 @@ def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_ }, } ) - association_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension?api-version=2021-04-01" + association_url = cmd.cli_ctx.cloud.endpoints.resource_manager + f"{cluster_resource_id}/providers/Microsoft.Insights/dataCollectionRuleAssociations/ContainerInsightsExtension?api-version={DCR_API_VERSION}" for _ in range(3): try: send_raw_request(cmd.cli_ctx, "PUT", association_url, body=association_body,) diff --git a/src/k8s-extension/azext_k8s_extension/partner_extensions/Dapr.py b/src/k8s-extension/azext_k8s_extension/partner_extensions/Dapr.py index 752e6c39587..46520c69a7a 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/Dapr.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/Dapr.py @@ -13,7 +13,7 @@ from copy import deepcopy from knack.log import get_logger from knack.prompting import prompt, prompt_y_n -from packaging import version as packaging_version +from semver import VersionInfo from ..vendored_sdks.models import Extension, PatchExtension, Scope, ScopeCluster from .DefaultExtension import DefaultExtension @@ -204,7 +204,7 @@ def _is_downgrade(v1: str, v2: str) -> bool: Returns True if version v1 is less than version v2. """ try: - return packaging_version.Version(v1) < packaging_version.Version(v2) - except packaging_version.InvalidVersion: + return VersionInfo.parse(v1) < VersionInfo.parse(v2) + except ValueError: logger.debug("Warning: Unable to compare versions %s and %s.", v1, v2) return True # This will cause the apply-CRDs hook to be disabled, which is safe. diff --git a/src/k8s-extension/setup.py b/src/k8s-extension/setup.py index beda2d80308..f2e6e28f7be 100644 --- a/src/k8s-extension/setup.py +++ b/src/k8s-extension/setup.py @@ -33,7 +33,7 @@ # TODO: Add any additional SDK dependencies here DEPENDENCIES = [] -VERSION = "1.4.2" +VERSION = "1.4.3" with open("README.rst", "r", encoding="utf-8") as f: README = f.read()