-
Notifications
You must be signed in to change notification settings - Fork 1.5k
{AKS}: bump aks-agent and upgrade helm charts automatically #9606
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Comment on lines
+771
to
+804
|
||
|
|
||
| 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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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.", | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+592
to
+599
|
||||||||||||||||||||||||||||||||||
| "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.", | |
| "Continuing with the current version. Run 'az aks agent-init' 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-init' to manually upgrade.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in changelog entry: "stablized" should be "stabilized".