From 5ff7d6635bd374c3cba8b43ef745d71a776d08cc Mon Sep 17 00:00:00 2001 From: Long Wan Date: Tue, 18 Jul 2023 16:40:43 -0700 Subject: [PATCH] ContainerInsights extension - Extend dataCollectionSettings with containerlogv2 (#237) --- .../tests/latest/data/datacollectionsettings.json | 4 ++++ .../partner_extensions/ContainerInsights.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/aks-preview/azext_aks_preview/tests/latest/data/datacollectionsettings.json b/src/aks-preview/azext_aks_preview/tests/latest/data/datacollectionsettings.json index 822876f792f..080f0cda526 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/data/datacollectionsettings.json +++ b/src/aks-preview/azext_aks_preview/tests/latest/data/datacollectionsettings.json @@ -3,5 +3,9 @@ "namespaceFilteringMode": "Include", "namespaces": [ "kube-system" + ], + "enableContainerLogV2": true, + "streams": [ + "Microsoft-ContainerLogV2" ] } \ No newline at end of file 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 4735a5b5373..4225ea164aa 100644 --- a/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py +++ b/src/k8s-extension/azext_k8s_extension/partner_extensions/ContainerInsights.py @@ -456,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: @@ -472,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) @@ -496,6 +502,10 @@ 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: