-
Notifications
You must be signed in to change notification settings - Fork 467
Add AKS tool for listing nodepools #360
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
tools/Azure.Mcp.Tools.Aks/src/Commands/Nodepool/NodepoolListCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Core.Commands; | ||
| using Azure.Mcp.Tools.Aks.Options; | ||
| using Azure.Mcp.Tools.Aks.Options.Nodepool; | ||
| using Azure.Mcp.Tools.Aks.Services; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Azure.Mcp.Tools.Aks.Commands.Nodepool; | ||
|
|
||
| public sealed class NodepoolListCommand(ILogger<NodepoolListCommand> logger) : BaseAksCommand<NodepoolListOptions> | ||
| { | ||
| private const string CommandTitle = "List AKS Node Pools"; | ||
| private readonly ILogger<NodepoolListCommand> _logger = logger; | ||
|
|
||
| private readonly Option<string> _clusterNameOption = AksOptionDefinitions.Cluster; | ||
|
|
||
| public override string Name => "list"; | ||
|
|
||
| public override string Description => | ||
| """ | ||
| List all node pools for a specific Azure Kubernetes Service (AKS) cluster. | ||
| Returns key node pool details including sizing, count, OS type, mode, and autoscaling settings. | ||
| """; | ||
|
|
||
| public override string Title => CommandTitle; | ||
|
|
||
| public override ToolMetadata Metadata => new() { Destructive = false, ReadOnly = true }; | ||
|
|
||
| protected override void RegisterOptions(Command command) | ||
| { | ||
| base.RegisterOptions(command); | ||
| RequireResourceGroup(); | ||
| command.Options.Add(_clusterNameOption); | ||
| } | ||
|
|
||
| protected override NodepoolListOptions BindOptions(ParseResult parseResult) | ||
| { | ||
| var options = base.BindOptions(parseResult); | ||
| options.ClusterName = parseResult.GetValue(_clusterNameOption); | ||
| return options; | ||
| } | ||
|
|
||
| public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult) | ||
| { | ||
| if (!Validate(parseResult.CommandResult, context.Response).IsValid) | ||
| { | ||
| return context.Response; | ||
| } | ||
|
|
||
| var options = BindOptions(parseResult); | ||
|
|
||
| try | ||
| { | ||
| var aksService = context.GetService<IAksService>(); | ||
| var nodePools = await aksService.ListNodePools( | ||
| options.Subscription!, | ||
| options.ResourceGroup!, | ||
| options.ClusterName!, | ||
| options.Tenant, | ||
| options.RetryPolicy); | ||
|
|
||
| context.Response.Results = nodePools?.Count > 0 ? | ||
| ResponseResult.Create( | ||
| new NodepoolListCommandResult(nodePools), | ||
| AksJsonContext.Default.NodepoolListCommandResult) : | ||
| null; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, | ||
| "Error listing AKS node pools. Subscription: {Subscription}, ResourceGroup: {ResourceGroup}, ClusterName: {ClusterName}, Options: {@Options}", | ||
| options.Subscription, options.ResourceGroup, options.ClusterName, options); | ||
| HandleException(context, ex); | ||
| } | ||
|
|
||
| return context.Response; | ||
| } | ||
|
|
||
| protected override string GetErrorMessage(Exception ex) => ex switch | ||
| { | ||
| RequestFailedException reqEx when reqEx.Status == 404 => | ||
| "AKS cluster or node pools not found. Verify the cluster name, resource group, and subscription, and ensure you have access.", | ||
| RequestFailedException reqEx when reqEx.Status == 403 => | ||
| $"Authorization failed accessing AKS node pools. Details: {reqEx.Message}", | ||
| RequestFailedException reqEx => reqEx.Message, | ||
| _ => base.GetErrorMessage(ex) | ||
| }; | ||
|
|
||
| protected override int GetStatusCode(Exception ex) => ex switch | ||
| { | ||
| RequestFailedException reqEx => reqEx.Status, | ||
| _ => base.GetStatusCode(ex) | ||
| }; | ||
|
|
||
| internal record NodepoolListCommandResult(List<Models.NodePool> NodePools); | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Azure.Mcp.Tools.Aks.Models; | ||
|
|
||
| public class NodePool | ||
| { | ||
| /// <summary> Name of the node pool (agent pool). </summary> | ||
| public string? Name { get; set; } | ||
|
|
||
| /// <summary> Number of nodes in the pool. </summary> | ||
| public int? NodeCount { get; set; } | ||
|
|
||
| /// <summary> VM size of the agent nodes. </summary> | ||
| public string? NodeVmSize { get; set; } | ||
|
|
||
| /// <summary> OS type of the node pool. </summary> | ||
| public string? OsType { get; set; } | ||
|
|
||
| /// <summary> Pool mode (System/User). </summary> | ||
| public string? Mode { get; set; } | ||
|
|
||
| /// <summary> Kubernetes/orchestrator version for the pool. </summary> | ||
| public string? OrchestratorVersion { get; set; } | ||
|
|
||
| /// <summary> Whether cluster autoscaler is enabled for this pool. </summary> | ||
| public bool? EnableAutoScaling { get; set; } | ||
|
|
||
| /// <summary> Minimum node count when autoscaling is enabled. </summary> | ||
| public int? MinCount { get; set; } | ||
|
|
||
| /// <summary> Maximum node count when autoscaling is enabled. </summary> | ||
| public int? MaxCount { get; set; } | ||
|
|
||
| /// <summary> Provisioning state of the node pool resource. </summary> | ||
| public string? ProvisioningState { get; set; } | ||
| } | ||
|
|
13 changes: 13 additions & 0 deletions
13
tools/Azure.Mcp.Tools.Aks/src/Options/Nodepool/NodepoolListOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Azure.Mcp.Tools.Aks.Options.Nodepool; | ||
|
|
||
| public class NodepoolListOptions : BaseAksOptions | ||
| { | ||
| [JsonPropertyName(AksOptionDefinitions.ClusterName)] | ||
| public string? ClusterName { get; set; } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.