Skip to content

Commit 8196a99

Browse files
Fix bug: Get-AzAks doesn't get all clusters (#12319)
* Fix bug: Get-AzAks doesn't get all clusters * Update ChangeLog.md Co-authored-by: Yabo Hu <[email protected]>
1 parent 7247176 commit 8196a99

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

src/Aks/Aks/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed bug Get-AzAks doesn't get all clusters (#12296)
2122

2223
## Version 1.1.2
2324

src/Aks/Aks/Commands/GetAzureRmAks.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16-
using System.Collections.Generic;
1716
using System.Linq;
1817
using System.Management.Automation;
19-
using Microsoft.Azure.Management.ContainerService;
18+
2019
using Microsoft.Azure.Commands.Aks.Models;
2120
using Microsoft.Azure.Commands.Aks.Properties;
2221
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
22+
using Microsoft.Azure.Management.ContainerService;
2323
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
2424

2525
namespace Microsoft.Azure.Commands.Aks
@@ -86,10 +86,13 @@ public override void ExecuteCmdlet()
8686
WriteObject(PSMapper.Instance.Map<PSKubernetesCluster>(idCluster), true);
8787
break;
8888
case ResourceGroupParameterSet:
89-
var kubeClusters = string.IsNullOrEmpty(ResourceGroupName)
90-
? Client.ManagedClusters.List()
91-
: Client.ManagedClusters.ListByResourceGroup(ResourceGroupName);
92-
WriteObject(kubeClusters.Select(PSMapper.Instance.Map<PSKubernetesCluster>), true);
89+
var kubeClusterList = string.IsNullOrEmpty(ResourceGroupName)
90+
? ListPaged(() => Client.ManagedClusters.List(),
91+
nextPageLink => Client.ManagedClusters.ListNext(nextPageLink))
92+
: ListPaged(() => Client.ManagedClusters.ListByResourceGroup(ResourceGroupName),
93+
nextPageLink => Client.ManagedClusters.ListNext(nextPageLink));
94+
95+
WriteObject(kubeClusterList.Select(PSMapper.Instance.Map<PSKubernetesCluster>), true);
9396
break;
9497
default:
9598
throw new ArgumentException(Resources.ParameterSetError);

src/Aks/Aks/Commands/GetAzureRmAksNodePool.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
using System.Linq;
1616
using System.Management.Automation;
17+
1718
using Microsoft.Azure.Commands.Aks.Models;
1819
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1920
using Microsoft.Azure.Management.ContainerService;
2021
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
21-
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2222

2323
namespace Microsoft.Azure.Commands.Aks.Commands
2424
{
@@ -77,7 +77,8 @@ public override void ExecuteCmdlet()
7777
}
7878
if (string.IsNullOrEmpty(Name))
7979
{
80-
var pools = Client.AgentPools.List(ResourceGroupName, ClusterName);
80+
var pools = ListPaged(() => Client.AgentPools.List(ResourceGroupName, ClusterName),
81+
nextPageLink => Client.AgentPools.ListNext(nextPageLink));
8182
WriteObject(pools.Select(PSMapper.Instance.Map<PSNodePool>), true);
8283
}
8384
else

src/Aks/Aks/Commands/KubeCmdletBase.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Collections.Generic;
1617
using System.IO;
1718
using System.Management.Automation;
19+
1820
using Microsoft.Azure.Commands.Aks.Properties;
1921
using Microsoft.Azure.Commands.Common.Authentication;
2022
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
@@ -24,6 +26,7 @@
2426
using Microsoft.Azure.Management.ContainerService;
2527
using Microsoft.Azure.Management.Internal.Resources;
2628
using Microsoft.Rest;
29+
2730
using CloudException = Microsoft.Rest.Azure.CloudException;
2831

2932
namespace Microsoft.Azure.Commands.Aks
@@ -83,5 +86,23 @@ private T BuildClient<T>(string endpoint = null, Func<T, T> postBuild = null) wh
8386
".azure");
8487

8588
protected string AcsSpFilePath => Path.Combine(AzConfigDir, "acsServicePrincipal.json");
89+
90+
protected static IList<T> ListPaged<T>(
91+
Func<Rest.Azure.IPage<T>> listFirstPage,
92+
Func<string, Rest.Azure.IPage<T>> listNextPage)
93+
{
94+
var resultsList = new List<T>();
95+
96+
var pagedResponse = listFirstPage();
97+
resultsList.AddRange(pagedResponse);
98+
99+
while (!string.IsNullOrEmpty(pagedResponse.NextPageLink))
100+
{
101+
pagedResponse = listNextPage(pagedResponse.NextPageLink);
102+
resultsList.AddRange(pagedResponse);
103+
}
104+
105+
return resultsList;
106+
}
86107
}
87108
}

0 commit comments

Comments
 (0)