Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aks-preview] Fix bug related to updating DCR when non monitoring add enabled through az aks enable-addons #8169

Merged
merged 19 commits into from
Oct 22, 2024
Merged
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ If there is no rush to release a new version, please just add a description of t

To release a new version, please select a new version number (usually plus 1 to last patch version, X.Y.Z -> Major.Minor.Patch, more details in `\doc <https://semver.org/>`_), and then add a new section named as the new version number in this file, the content should include the new modifications and everything from the *Pending* section. Finally, update the `VERSION` variable in `setup.py` with this new version number.

9.0.0b7
+++++++
* Fix bug related to updating the monitoring addon DCR when the non monitoring addon enabled through `az aks enable-addons`.

9.0.0b6
+++++++
* Print warning message when new node pool is created with SSH enabled, suggest to create SSH disabled node pool.
Expand Down
28 changes: 28 additions & 0 deletions src/aks-preview/azext_aks_preview/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
get_mc_snapshots_client,
get_nodepool_snapshots_client,
)

from azext_aks_preview._consts import (
ADDONS,
CONST_MONITORING_ADDON_NAME
)

from azure.cli.command_modules.acs._helpers import map_azure_error_to_cli_error
from azure.cli.command_modules.acs._validators import extract_comma_separated_string
from azure.cli.core.azclierror import (
Expand Down Expand Up @@ -346,3 +352,25 @@ def check_is_azure_cli_core_editable_installed():
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


def check_is_monitoring_addon_enabled(addons, instance):
is_monitoring_addon_enabled = False
is_monitoring_addon = False
try:
addon_args = addons.split(',')
for addon_arg in addon_args:
if addon_arg in ADDONS:
addon = ADDONS[addon_arg]
if addon == CONST_MONITORING_ADDON_NAME:
is_monitoring_addon = True
break
addon_profiles = instance.addon_profiles or {}
is_monitoring_addon_enabled = (
is_monitoring_addon
and CONST_MONITORING_ADDON_NAME in addon_profiles
and addon_profiles[CONST_MONITORING_ADDON_NAME].enabled
)
except Exception as ex: # pylint: disable=broad-except
logger.debug("failed to check monitoring addon enabled: %s", ex)
return is_monitoring_addon_enabled
11 changes: 7 additions & 4 deletions src/aks-preview/azext_aks_preview/addonconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
sanitize_loganalytics_ws_resource_id,
ensure_default_log_analytics_workspace_for_monitoring
)
from azext_aks_preview._helpers import (
check_is_monitoring_addon_enabled,
)

from azext_aks_preview._client_factory import CUSTOM_MGMT_AKS_PREVIEW
from azext_aks_preview._roleassignments import add_role_assignment
from azext_aks_preview._consts import (
Expand Down Expand Up @@ -108,8 +112,9 @@ def enable_addons(
dns_zone_resource_ids=dns_zone_resource_ids
)

if CONST_MONITORING_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[
CONST_MONITORING_ADDON_NAME].enabled:
monitoring_addon_enabled = check_is_monitoring_addon_enabled(addons, instance)

if monitoring_addon_enabled:
if CONST_MONITORING_USING_AAD_MSI_AUTH in instance.addon_profiles[CONST_MONITORING_ADDON_NAME].config and \
str(instance.addon_profiles[CONST_MONITORING_ADDON_NAME].config[
CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == 'true':
Expand Down Expand Up @@ -152,8 +157,6 @@ def enable_addons(
data_collection_settings=data_collection_settings
)

monitoring_addon_enabled = CONST_MONITORING_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[
CONST_MONITORING_ADDON_NAME].enabled
ingress_appgw_addon_enabled = CONST_INGRESS_APPGW_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[
CONST_INGRESS_APPGW_ADDON_NAME].enabled

Expand Down
14 changes: 9 additions & 5 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
get_nodepool_snapshot_by_snapshot_id,
print_or_merge_credentials,
process_message_for_run_command,
check_is_monitoring_addon_enabled,
)
from azext_aks_preview._podidentity import (
_ensure_managed_identity_operator_permission,
Expand Down Expand Up @@ -2146,9 +2147,10 @@ def aks_enable_addons(
dns_zone_resource_id=dns_zone_resource_id,
dns_zone_resource_ids=dns_zone_resource_ids,
)

is_monitoring_addon_enabled = check_is_monitoring_addon_enabled(addons, instance)
if (
CONST_MONITORING_ADDON_NAME in instance.addon_profiles and
instance.addon_profiles[CONST_MONITORING_ADDON_NAME].enabled
is_monitoring_addon_enabled
):
if (
CONST_MONITORING_USING_AAD_MSI_AUTH in
Expand Down Expand Up @@ -2201,8 +2203,6 @@ def aks_enable_addons(
aad_route=False,
)

monitoring = CONST_MONITORING_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[
CONST_MONITORING_ADDON_NAME].enabled
ingress_appgw_addon_enabled = CONST_INGRESS_APPGW_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[
CONST_INGRESS_APPGW_ADDON_NAME].enabled

Expand All @@ -2211,7 +2211,11 @@ def aks_enable_addons(
if CONST_VIRTUAL_NODE_ADDON_NAME + os_type in instance.addon_profiles:
enable_virtual_node = True

need_post_creation_role_assignment = monitoring or ingress_appgw_addon_enabled or enable_virtual_node
need_post_creation_role_assignment = (
is_monitoring_addon_enabled or
ingress_appgw_addon_enabled or
enable_virtual_node
)
if need_post_creation_role_assignment:
# adding a wait here since we rely on the result for role assignment
result = LongRunningOperation(cmd.cli_ctx)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4240,7 +4240,7 @@ def test_aks_gpu_driver_type(self, resource_group, resource_group_location):
"--node-vm-size Standard_NC4as_T4_v3 --driver-type GRID "
"-k {k8s_version} -o json"
)

self.cmd(
create_nodepool_cmd,
checks=[self.check("provisioningState", "Succeeded"),
Expand All @@ -4252,7 +4252,7 @@ def test_aks_gpu_driver_type(self, resource_group, resource_group_location):
"aks nodepool update --resource-group {resource_group} --cluster-name {name} "
"--name {nodepool_name} --tags team=industry -o json"
)

self.cmd(
update_cmd,
checks=[self.check("provisioningState", "Succeeded"),
Expand All @@ -4271,7 +4271,7 @@ def test_aks_gpu_driver_type(self, resource_group, resource_group_location):
"--node-vm-size Standard_NC4as_T4_v3 "
"-k {k8s_version} -o json"
)

self.cmd(
create_nodepool_cmd,
checks=[self.check("provisioningState", "Succeeded"),
Expand Down Expand Up @@ -5210,6 +5210,29 @@ def test_aks_create_with_monitoring_aad_auth_msi_with_datacollectionsettings(
data_collection_settings=_get_test_data_file("datacollectionsettings.json"),
)

@live_only()
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(
random_name_length=17, name_prefix="clitest", location="westus2"
)
def test_aks_create_with_monitoring_aad_auth_msi_with_datacollectionsettings_and_otheraddon(
self,
resource_group,
resource_group_location,
):
aks_name = self.create_random_name("cliakstest", 16)
self.create_new_cluster_with_monitoring_aad_auth(
resource_group,
resource_group_location,
aks_name,
user_assigned_identity=False,
syslog_enabled=False,
data_collection_settings=_get_test_data_file("datacollectionsettings.json"),
use_ampls=False,
highlogscale_mode_enabled=False,
enableOtherAddon=True
)

@live_only()
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(
Expand Down Expand Up @@ -5252,7 +5275,7 @@ def test_aks_create_with_private_cluster_with_monitoring_aad_auth_msi_with_ampls



def create_new_cluster_with_monitoring_aad_auth(self, resource_group, resource_group_location, aks_name, user_assigned_identity=False, syslog_enabled=False, data_collection_settings=None, use_ampls=False, highlogscale_mode_enabled=False):
def create_new_cluster_with_monitoring_aad_auth(self, resource_group, resource_group_location, aks_name, user_assigned_identity=False, syslog_enabled=False, data_collection_settings=None, use_ampls=False, highlogscale_mode_enabled=False, enableOtherAddon=False):
self.kwargs.update({
'resource_group': resource_group,
'name': aks_name,
Expand Down Expand Up @@ -5286,6 +5309,10 @@ def create_new_cluster_with_monitoring_aad_auth(self, resource_group, resource_g
create_cmd += f'--ampls-resource-id {ampls_resource_id} ' if use_ampls else ''
create_cmd += f'--enable-high-log-scale-mode ' if highlogscale_mode_enabled else ''

if enableOtherAddon:
# enable other addon such azure-policy to verify the monitoring addon and DCRs etc.. remainins intact.
self.cmd(f'aks enable-addons -a azure-policy -g={resource_group} -n={aks_name}')

response = self.cmd(create_cmd, checks=[
self.check('addonProfiles.omsagent.enabled', True),
self.check('addonProfiles.omsagent.config.useAADAuth', 'true')
Expand Down Expand Up @@ -14159,7 +14186,7 @@ def test_aks_create_with_app_routing_enabled(
self.check("ingressProfile.webAppRouting.nginx.defaultIngressControllerType", "AnnotationControlled")
],
)

@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(
random_name_length=17, name_prefix="clitest", location="centralus"
Expand Down Expand Up @@ -14311,7 +14338,7 @@ def test_aks_approuting_enable_disable(
delete_cmd = "aks delete --resource-group={resource_group} --name={aks_name} --yes --no-wait"
self.cmd(delete_cmd, checks=[self.is_empty()])


@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(
random_name_length=17,
Expand All @@ -14328,7 +14355,7 @@ def test_aks_approuting_enable_with_internal_nginx_then_disable(

# create cluster without app routing
aks_name = self.create_random_name("cliakstest", 16)

_, k8s_version = self._get_versions(resource_group_location)

self.kwargs.update(
Expand Down
2 changes: 1 addition & 1 deletion src/aks-preview/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from setuptools import setup, find_packages

VERSION = "9.0.0b6"
VERSION = "9.0.0b7"

CLASSIFIERS = [
"Development Status :: 4 - Beta",
Expand Down
Loading