diff --git a/src/aks-agent/HISTORY.rst b/src/aks-agent/HISTORY.rst index 8f23ba77195..ead24e10f02 100644 --- a/src/aks-agent/HISTORY.rst +++ b/src/aks-agent/HISTORY.rst @@ -12,9 +12,17 @@ To release a new version, please select a new version number (usually plus 1 to Pending +++++++ +1.0.0b18 +++++++++ +* Bump aks-agent to v0.3.0 + * chore: use aks mcp streamable-http mode + * Remove runbook toolset until it's stablized + * Several CEV fixes +* Upgrade helm chart automatically during `az aks agent` when there's an update in helm chart + 1.0.0b17 ++++++++ -* Fix: remove the prompt to user about managed identity client id during `az aks agent-init`` +* Fix: remove the prompt to user about managed identity client id during `az aks agent-init` 1.0.0b16 ++++++++ diff --git a/src/aks-agent/azext_aks_agent/agent/k8s/aks_agent_manager.py b/src/aks-agent/azext_aks_agent/agent/k8s/aks_agent_manager.py index 217ecea129e..8698dfdeaec 100644 --- a/src/aks-agent/azext_aks_agent/agent/k8s/aks_agent_manager.py +++ b/src/aks-agent/azext_aks_agent/agent/k8s/aks_agent_manager.py @@ -128,7 +128,7 @@ def __init__(self, resource_group_name: str, cluster_name: str, self.subscription_id: str = subscription_id self.chart_repo = "oci://mcr.microsoft.com/aks/aks-agent-chart/aks-agent" - self.chart_version = "0.2.0" + self.chart_version = "0.3.0" # credentials for aks-mcp # Default empty customized cluster role name means using default cluster role @@ -584,10 +584,14 @@ def get_agent_status(self) -> Dict: # pylint: disable=too-many-locals if list_success: try: releases = json.loads(list_output) - release_exists = any( - release.get("name") == self.helm_release_name - for release in releases - ) + for release in releases: + if release.get("name") == self.helm_release_name: + release_exists = True + # Extract chart version from chart field (e.g., "aks-agent-0.2.0") + chart_field = release.get("chart", "") + if "-" in chart_field: + status["chart_version"] = chart_field.rsplit("-", 1)[-1] + break except json.JSONDecodeError: logger.warning("Failed to parse helm list output") @@ -764,6 +768,41 @@ def uninstall_agent(self, delete_secret: bool = True) -> bool: return True raise AzCLIError(f"Failed to uninstall AKS agent: {output}") + def check_upgrade_needed(self) -> Tuple[bool, Optional[str], Optional[str]]: + """ + Check if the deployed helm chart version differs from the expected version. + + Returns: + Tuple[bool, Optional[str], Optional[str]]: + - needs_upgrade: True if upgrade is needed, False otherwise + - deployed_version: The currently deployed version (or None if unknown) + - expected_version: The expected version to upgrade to (or None if no upgrade needed) + """ + agent_status = self.get_agent_status() + helm_status = agent_status.get("helm_status", "not_found") + + if helm_status not in ["deployed", "superseded"]: + logger.debug("Agent not deployed or in unexpected state: %s", helm_status) + return False, None, None + + deployed_version = agent_status.get("chart_version") + expected_version = self.chart_version + + if not deployed_version: + logger.warning("Could not determine deployed chart version") + return False, None, None + + if deployed_version == expected_version: + logger.debug("Chart version is up to date: %s", deployed_version) + return False, deployed_version, None + + logger.info( + "Chart version mismatch detected. Deployed: %s, Expected: %s", + deployed_version, expected_version + ) + + return True, deployed_version, expected_version + def exec_aks_agent(self, command_flags: str = "") -> bool: """ Execute commands on the AKS agent pod using PodExecManager. @@ -973,7 +1012,7 @@ def __init__(self, resource_group_name: str, cluster_name: str, self.config_dir = self.base_config_dir / subscription_id / resource_group_name / cluster_name # Docker image for client mode execution - self.docker_image = "mcr.microsoft.com/aks/aks-agent:v0.2.0-client" + self.docker_image = "mcr.microsoft.com/aks/aks-agent:v0.3.0-client" self.llm_config_manager = LLMConfigManagerLocal( subscription_id=subscription_id, diff --git a/src/aks-agent/azext_aks_agent/custom.py b/src/aks-agent/azext_aks_agent/custom.py index f7e15e9b7ad..30180cb66da 100644 --- a/src/aks-agent/azext_aks_agent/custom.py +++ b/src/aks-agent/azext_aks_agent/custom.py @@ -566,6 +566,39 @@ def aks_agent( error_msg += f"The AKS agent may not be deployed. Run 'az aks agent-init {cmd_flags}' to initialize the deployment." raise CLIError(error_msg) + # Check if helm chart version needs upgrade and upgrade automatically if needed + console = get_console() + needs_upgrade, deployed_version, expected_version = agent_manager.check_upgrade_needed() + if needs_upgrade: + console.print( + f"\n📦 Upgrading AKS agent from version {deployed_version} to {expected_version}...", + style="bold cyan" + ) + console.print( + "This may take a minute or two. Please wait...", + style="cyan" + ) + try: + success, error_msg = agent_manager.deploy_agent() + if success: + console.print( + "✅ AKS agent has been automatically upgraded to the latest version.", + style=SUCCESS_COLOR) + else: + console.print( + f"⚠️ Warning: Failed to auto-upgrade agent: {error_msg}", + style=WARNING_COLOR) + console.print( + "Continuing with the current version. Run 'az aks agent-upgrade' to manually upgrade.", + style=INFO_COLOR) + except AzCLIError as e: + console.print( + f"⚠️ Warning: Failed to auto-upgrade agent: {e}", + style=WARNING_COLOR) + console.print( + "Continuing with the current version. Run 'az aks agent-upgrade' to manually upgrade.", + style=INFO_COLOR) + # prepare CLI flags # user quoted prompt to not break the command line parsing diff --git a/src/aks-agent/setup.py b/src/aks-agent/setup.py index 2200b60c655..95895c11493 100644 --- a/src/aks-agent/setup.py +++ b/src/aks-agent/setup.py @@ -9,7 +9,7 @@ from setuptools import find_packages, setup -VERSION = "1.0.0b17" +VERSION = "1.0.0b18" CLASSIFIERS = [ "Development Status :: 4 - Beta",