Skip to content

aksd: fix: return full cluster list for AKS cluster registration#296

Open
tejhan wants to merge 1 commit intoAzure:mainfrom
tejhan:fix/paginate-aks-clusters
Open

aksd: fix: return full cluster list for AKS cluster registration#296
tejhan wants to merge 1 commit intoAzure:mainfrom
tejhan:fix/paginate-aks-clusters

Conversation

@tejhan
Copy link
Collaborator

@tejhan tejhan commented Feb 24, 2026

Description

When using the "Register AKS Cluster" feature, subscriptions with more than 100 AKS clusters would return only the first 100 clusters (alphabetically). Any cluster that alphabetically proceeded these isn't returned or searchable.

The root of issue is that getClustersViaGraph called az graph query without specifying the --first flag, which defaults to 100 results & also didn't paginate excess results with the skip-tokens.

Type of Change

  • [x ] Bug fix (non-breaking change which fixes an issue)
  • [ x] Code refactoring

Related Issues

Closes #295
Related to #274

Changes Made

Created a fetchGraphPage helper that calls az graph query with --first 1000 (max) and returns the result data and the skip_token pagination cursor.
Updated getClustersViaGraph to paginate through all results using skip_token, so all clusters are successfully fetched.

Testing

Since my largest subscriptions were in the hundreds but not thousands, pagination was validated by temporarily lowering the page size to 100 to confirm multi-page fetching works correctly. Verified all clusters appear when cluster amount exceeds page amount, which indicates pagination works.

Notes:

This is related to the umbrella issue of pagination for az-cli commands throughout. Currently looking into implementing this logic for other resource types so we can share utility.

@tejhan tejhan self-assigned this Feb 24, 2026
Copilot AI review requested due to automatic review settings February 24, 2026 13:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug where the "Register AKS Cluster" feature only returned the first 100 AKS clusters (alphabetically) when a subscription contained more than 100 clusters. The root cause was that the Azure Resource Graph query didn't specify the --first flag (which defaults to 100) and didn't handle pagination using --skip-token.

Changes:

  • Created a new fetchGraphPage helper function that executes Azure Resource Graph queries with pagination support (using --first 1000 and --skip-token)
  • Refactored getClustersViaGraph to use the new helper function and loop through all pages to fetch the complete list of clusters
  • Added proper error handling for authentication and query failures in the pagination logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix.

Can you please address the copilot comments?

@illume illume marked this pull request as draft February 25, 2026 10:40
@tejhan tejhan force-pushed the fix/paginate-aks-clusters branch 2 times, most recently from d436b13 to fd06a4a Compare February 26, 2026 19:01
@tejhan tejhan marked this pull request as ready for review February 26, 2026 19:03
Copilot AI review requested due to automatic review settings February 26, 2026 19:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@illume illume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Nice improvement.

I left a note and a couple of questions.

* skip token if applicable to handle pagination to fetch all clusters in larger subscriptions.
*/
async function fetchGraphPage(
query: string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add param docs?

// Fetch remaining pages if the subscription has more clusters than one page holds
const MAX_PAGES = 100; // 100,000 cluster limit.
let pageCount = 1;
while (page.skipToken && pageCount < MAX_PAGES) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this always go through 100 pages?

I don't understand how it knows to stop when there are no more pages to go through?

Copy link
Collaborator Author

@tejhan tejhan Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't, since the graph query response object contains a skipToken only if more pages exist, otherwise it returns a null skipToken, (thus checking for existence of the skipToken here halts the loop on the final 'page' response object which won't have a skipToken present.

throw error;
const query = `
Resources
| where type =~ 'microsoft.containerservice/managedclusters'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this affect working with non-automatic clusters?

cc @gambtho

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The microsoft.containerservice/managedclusters resource type is used for both Standard & Automatic SKU's. Upon testing both types are returned by the graph query.

@illume illume added p-none No priority was assigned bug Something isn't working labels Feb 27, 2026
@tejhan tejhan force-pushed the fix/paginate-aks-clusters branch from f03a99d to 4e4a09c Compare February 28, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p-none No priority was assigned

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Register AKS Cluster feature truncates cluster list at 100 in large subscriptions

3 participants