Skip to content

Commit

Permalink
Merge branch 'k8s-extension/public' into user/amagraw/fix-bug/rename
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrcks authored Dec 30, 2022
2 parents e054268 + ee8a070 commit 4a6fcdb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import datetime
import json
import re

from ..utils import get_cluster_rp_api_version
from .. import consts
Expand Down Expand Up @@ -453,6 +454,7 @@ def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_r
subscription_id = get_subscription_id(cmd.cli_ctx)
workspace_resource_id = ''
useAADAuth = False
extensionSettings = {}

if configuration_settings is not None:
if 'loganalyticsworkspaceresourceid' in configuration_settings:
Expand All @@ -473,6 +475,26 @@ 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
if useAADAuth and ('dataCollectionSettings' in configuration_settings):
dataCollectionSettingsString = configuration_settings["dataCollectionSettings"]
logger.info("provided dataCollectionSettings is : %s", dataCollectionSettingsString)
dataCollectionSettings = json.loads(dataCollectionSettingsString)
if 'interval' in dataCollectionSettings.keys():
intervalValue = dataCollectionSettings["interval"]
if (bool(re.match(r'^[0-9]+[m]$', intervalValue))) is False:
raise InvalidArgumentValueError('interval format must be in <number>m')
intervalValue = int(intervalValue.rstrip("m"))
if intervalValue <= 0 or intervalValue > 30:
raise InvalidArgumentValueError('interval value MUST be in the range from 1m to 30m')
if 'namespaceFilteringMode' in dataCollectionSettings.keys():
namespaceFilteringModeValue = dataCollectionSettings["namespaceFilteringMode"].lower()
if namespaceFilteringModeValue not in ["off", "exclude", "include"]:
raise InvalidArgumentValueError('namespaceFilteringMode value MUST be either Off or Exclude or Include')
if 'namespaces' in dataCollectionSettings.keys():
namspaces = dataCollectionSettings["namespaces"]
if isinstance(namspaces, list) is False:
raise InvalidArgumentValueError('namespaces must be an array type')
extensionSettings["dataCollectionSettings"] = dataCollectionSettings

workspace_resource_id = workspace_resource_id.strip()

Expand Down Expand Up @@ -502,7 +524,7 @@ def _get_container_insights_settings(cmd, cluster_resource_group_name, cluster_r
if is_ci_extension_type:
if useAADAuth:
logger.info("creating data collection rule and association")
_ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_resource_group_name, cluster_rp, cluster_type, cluster_name, workspace_resource_id)
_ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_resource_group_name, cluster_rp, cluster_type, cluster_name, workspace_resource_id, extensionSettings)
elif not _is_container_insights_solution_exists(cmd, workspace_resource_id):
logger.info("Creating ContainerInsights solution resource, since it doesn't exist and it is using legacy authentication")
_ensure_container_insights_for_monitoring(cmd, workspace_resource_id).result()
Expand Down Expand Up @@ -571,7 +593,7 @@ def get_existing_container_insights_extension_dcr_tags(cmd, dcr_url):
return tags


def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_resource_group_name, cluster_rp, cluster_type, cluster_name, workspace_resource_id):
def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_resource_group_name, cluster_rp, cluster_type, cluster_name, workspace_resource_id, extensionSettings):
from azure.core.exceptions import HttpResponseError

cluster_region = ''
Expand Down Expand Up @@ -666,6 +688,7 @@ def _ensure_container_insights_dcr_for_monitoring(cmd, subscription_id, cluster_
"Microsoft-ContainerInsights-Group-Default"
],
"extensionName": "ContainerInsights",
"extensionSettings": extensionSettings
}
]
},
Expand Down
10 changes: 10 additions & 0 deletions src/k8s-extension/azext_k8s_extension/partner_extensions/Dapr.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,26 @@ def Update(self, cmd, resource_group_name: str, cluster_name: str, auto_upgrade_
configuration_settings = {}

# If we are downgrading the extension, then we need to disable the apply-CRDs hook.
# Additionally, if we are disabling auto-upgrades, we need to disable the apply-CRDs hook (as auto-upgrade is always on the latest version).
# This is because CRD updates while downgrading can cause issues.
# As CRDs are additive, skipping their removal while downgrading is safe.
original_version = original_extension.version
original_auto_upgrade = original_extension.auto_upgrade_minor_version
if self.APPLY_CRDS_HOOK_ENABLED_KEY in configuration_settings:
logger.debug("'%s' is set to '%s' in --configuration-settings, not overriding it.",
self.APPLY_CRDS_HOOK_ENABLED_KEY, configuration_settings[self.APPLY_CRDS_HOOK_ENABLED_KEY])
elif original_auto_upgrade and not auto_upgrade_minor_version:
logger.debug("Auto-upgrade is disabled and version is pinned to %s. Setting '%s' to false.",
version, self.APPLY_CRDS_HOOK_ENABLED_KEY)
configuration_settings[self.APPLY_CRDS_HOOK_ENABLED_KEY] = 'false'
elif original_version and version and version < original_version:
logger.debug("Downgrade detected from %s to %s. Setting %s to false.",
original_version, version, self.APPLY_CRDS_HOOK_ENABLED_KEY)
configuration_settings[self.APPLY_CRDS_HOOK_ENABLED_KEY] = 'false'
elif original_version and version and version == original_version:
logger.debug("Version unchanged at %s. Setting %s to false.",
version, self.APPLY_CRDS_HOOK_ENABLED_KEY)
configuration_settings[self.APPLY_CRDS_HOOK_ENABLED_KEY] = 'false'
else:
# If we are not downgrading, enable the apply-CRDs hook explicitly.
# This is because the value may have been set to false during a previous downgrade.
Expand Down
7 changes: 4 additions & 3 deletions testing/pipeline/k8s-custom-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ stages:
path: ./test/extensions/public/Flux.Tests.ps1
- job: BuildPublishExtension
pool:
vmImage: 'ubuntu-latest'
vmImage: 'ubuntu-20.04'
displayName: "Build and Publish the Extension Artifact"
variables:
CLI_REPO_PATH: $(Agent.BuildDirectory)/s
Expand Down Expand Up @@ -105,10 +105,11 @@ stages:
azdev verify license
- job: StaticAnalysis
displayName: "Static Analysis"
pool:
vmImage: 'ubuntu-latest'
vmImage: 'ubuntu-20.04'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
Expand Down Expand Up @@ -209,4 +210,4 @@ stages:
displayName: "CLI Linter on Modified Extension"
env:
ADO_PULL_REQUEST_LATEST_COMMIT: $(System.PullRequest.SourceCommitId)
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
ADO_PULL_REQUEST_TARGET_BRANCH: $(System.PullRequest.TargetBranch)
2 changes: 1 addition & 1 deletion testing/pipeline/templates/build-extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ steps:
azdev --version
azdev setup -c ../azure-cli -r ${{ parameters.CLI_REPO_PATH }} -e $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
azdev extension build $(EXTENSION_NAME)
4 changes: 2 additions & 2 deletions testing/pipeline/templates/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:
jobs:
- job: ${{ parameters.jobName}}
pool:
vmImage: 'ubuntu-latest'
vmImage: 'ubuntu-20.04'
variables:
${{ if eq(variables['IS_PRIVATE_BRANCH'], 'False') }}:
EXTENSION_NAME: "k8s-extension"
Expand Down Expand Up @@ -101,4 +101,4 @@ jobs:
inlineScript: |
.\Cleanup.ps1 -CI
workingDirectory: $(TEST_PATH)
condition: succeededOrFailed()
condition: succeededOrFailed()

0 comments on commit 4a6fcdb

Please sign in to comment.