Skip to content

Commit

Permalink
[AKS] support parameter Mode in nodepool (Azure#20194)
Browse files Browse the repository at this point in the history
  • Loading branch information
YanaXu authored Nov 22, 2022
1 parent 517b636 commit 74f47f7
Show file tree
Hide file tree
Showing 10 changed files with 4,999 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/Aks/Aks.Test/ScenarioTests/NodePoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@ public void TestAksNodePool()
{
TestRunner.RunTestScript("Test-NewNodePool");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNodePoolMode()
{
TestRunner.RunTestScript("Test-NodePoolMode");
}
}
}
91 changes: 91 additions & 0 deletions src/Aks/Aks.Test/ScenarioTests/NodePoolTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,94 @@ function Test-NewNodePool
Remove-AzResourceGroup -Name $resourceGroupName -Force
}
}

function Test-NodePoolMode
{
# Setup
$resourceGroupName = Get-RandomResourceGroupName
$kubeClusterName = Get-RandomClusterName
$location = 'eastus'
$nodeVmSize = "Standard_D2_v2"

try
{
New-AzResourceGroup -Name $resourceGroupName -Location $location

# creat default pool, mode=system
New-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeVmSize $nodeVmSize -NodeCount 1

$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 1 $cluster.AgentPoolProfiles.Count
Assert-AreEqual "default" $cluster.AgentPoolProfiles[0].Name
Assert-AreEqual "System" $cluster.AgentPoolProfiles[0].Mode

$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual "default" $pools.Name
Assert-AreEqual "System" $pools.Mode


# create the 2nd nodepool, default mode, mode=User
New-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name "pool2" -Count 1

$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 2 $cluster.AgentPoolProfiles.Count
Assert-AreEqual "System" ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Mode
Assert-AreEqual "User" ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Mode

$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 2 $pools.Count
Assert-AreEqual "System" ($pools | where {$_.Name -eq "default"}).Mode
Assert-AreEqual "User" ($pools | where {$_.Name -eq "pool2"}).Mode

# create the 3rd nodepool, mode=System
New-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name "pool3" -Count 1 -Mode System

$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 3 $cluster.AgentPoolProfiles.Count
Assert-AreEqual "System" ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Mode
Assert-AreEqual "User" ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Mode
Assert-AreEqual "System" ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool3"}).Mode

$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 3 $pools.Count
Assert-AreEqual "System" ($pools | where {$_.Name -eq "default"}).Mode
Assert-AreEqual "User" ($pools | where {$_.Name -eq "pool2"}).Mode
Assert-AreEqual "System" ($pools | where {$_.Name -eq "pool3"}).Mode

# update the 3rd nodepool, mode=User
Update-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name "pool3" -Mode User

$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 3 $cluster.AgentPoolProfiles.Count
Assert-AreEqual "System" ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Mode
Assert-AreEqual "User" ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Mode
Assert-AreEqual "User" ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool3"}).Mode

$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 3 $pools.Count
Assert-AreEqual "System" ($pools | where {$_.Name -eq "default"}).Mode
Assert-AreEqual "User" ($pools | where {$_.Name -eq "pool2"}).Mode
Assert-AreEqual "User" ($pools | where {$_.Name -eq "pool3"}).Mode

# update the 2nd nodepool, mode=System
Set-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeName "pool2" -NodePoolMode System

$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 3 $cluster.AgentPoolProfiles.Count
Assert-AreEqual "System" ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Mode
Assert-AreEqual "System" ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Mode
Assert-AreEqual "User" ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool3"}).Mode

$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 3 $pools.Count
Assert-AreEqual "System" ($pools | where {$_.Name -eq "default"}).Mode
Assert-AreEqual "System" ($pools | where {$_.Name -eq "pool2"}).Mode
Assert-AreEqual "User" ($pools | where {$_.Name -eq "pool3"}).Mode

$cluster | Remove-AzAksCluster -Force
}
finally
{
Remove-AzResourceGroup -Name $resourceGroupName -Force
}
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Aks/Aks/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## Upcoming Release
* Bumped API version to 2022-09-01
* Added parameter `NodeOsSKU` for `New-AzAksCluster` and parameter `OsSKU` for `New-AzAksNodePool`
* Added parameter `Mode` for `New-AzAksNodePool` and `Update-AzAksNodePool`

## Version 5.0.1
* Upgraded AutoMapper to Microsoft.Azure.PowerShell.AutoMapper 6.2.2 with fix [#18721]
Expand Down
4 changes: 4 additions & 0 deletions src/Aks/Aks/Commands/NewAzureRmAksNodePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ private AgentPool GetAgentPool()
{
agentPool.EnableAutoScaling = EnableAutoScaling.ToBool();
}
if (this.IsParameterBound(c => c.Mode))
{
agentPool.Mode = Mode;
}
if (EnableNodePublicIp.IsPresent)
{
agentPool.EnableNodePublicIP = EnableNodePublicIp.ToBool();
Expand Down
8 changes: 8 additions & 0 deletions src/Aks/Aks/Commands/NewOrUpdateAgentPoolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Aks
Expand All @@ -30,5 +31,12 @@ public class NewOrUpdateAgentPoolBase : KubeCmdletBase

[Parameter(Mandatory = false, HelpMessage = "Whether to enable auto-scaler")]
public SwitchParameter EnableAutoScaling { get; set; }

/// <summary>
/// Gets or sets possible values include: 'System', 'User'
/// </summary>
[Parameter(Mandatory = false, HelpMessage = "The pool mode")]
[PSArgumentCompleter("System", "User")]
public string Mode { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Aks/Aks/Commands/UpdateAzureRmAksNodePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public override void ExecuteCmdlet()
{
pool.EnableAutoScaling = EnableAutoScaling.ToBool();
}
if (this.IsParameterBound(c => c.Mode))
{
pool.Mode = Mode;
}
if (this.IsParameterBound(c => c.NodeCount))
{
pool.Count = NodeCount;
Expand Down
5 changes: 5 additions & 0 deletions src/Aks/Aks/Models/PSNodePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ public partial class PSNodePool : PSSubResource

public bool? EnableAutoScaling { get; set; }

/// <summary>
/// Gets or sets mode for agent pool System or User
/// </summary>
public string Mode { get; set; }

/// <summary>
/// Gets or sets agentPoolType represents types of an node pool.
/// Possible values include: 'VirtualMachineScaleSets',
Expand Down
19 changes: 17 additions & 2 deletions src/Aks/Aks/help/New-AzAksNodePool.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ New-AzAksNodePool -ResourceGroupName <String> -ClusterName <String> -Name <Strin
[-OsDiskSize <Int32>] [-VmSize <String>] [-VnetSubnetID <String>] [-MaxPodCount <Int32>] [-OsType <String>]
[-OsSKU <String>] [-EnableNodePublicIp] [-NodePublicIPPrefixID <String>] [-ScaleSetPriority <String>]
[-ScaleSetEvictionPolicy <String>] [-VmSetType <String>] [-AvailabilityZone <String[]>] [-Force]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling] [-Mode <String>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
```
Expand All @@ -29,7 +29,7 @@ New-AzAksNodePool -Name <String> -ClusterObject <PSKubernetesCluster> [-Count <I
[-VmSize <String>] [-VnetSubnetID <String>] [-MaxPodCount <Int32>] [-OsType <String>] [-OsSKU <String>]
[-EnableNodePublicIp] [-NodePublicIPPrefixID <String>] [-ScaleSetPriority <String>]
[-ScaleSetEvictionPolicy <String>] [-VmSetType <String>] [-AvailabilityZone <String[]>] [-Force]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling] [-Mode <String>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
```
Expand Down Expand Up @@ -233,6 +233,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Mode
The pool mode
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Name
The name of the node pool.
Expand Down
23 changes: 19 additions & 4 deletions src/Aks/Aks/help/Update-AzAksNodePool.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ Update node pool in a managed cluster.
```
Update-AzAksNodePool -ResourceGroupName <String> -ClusterName <String> -Name <String> [-NodeCount <Int32>]
[-NodeImageOnly] [-AsJob] [-Force] [-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>]
[-EnableAutoScaling] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[-EnableAutoScaling] [-Mode <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[-SubscriptionId <String>] [<CommonParameters>]
```

### ParentObjectParameterSet
```
Update-AzAksNodePool -Name <String> -ClusterObject <PSKubernetesCluster> [-NodeCount <Int32>] [-NodeImageOnly]
[-AsJob] [-Force] [-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[-Mode <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
```

### InputObjectParameterSet
```
Update-AzAksNodePool -InputObject <PSNodePool> [-NodeCount <Int32>] [-NodeImageOnly] [-AsJob] [-Force]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling] [-Mode <String>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
```

### IdParameterSet
```
Update-AzAksNodePool -Id <String> [-NodeCount <Int32>] [-NodeImageOnly] [-AsJob] [-Force]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling]
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling] [-Mode <String>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
[<CommonParameters>]
```
Expand Down Expand Up @@ -221,6 +221,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Mode
The pool mode
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Name
The name of the node pool.
Expand Down

0 comments on commit 74f47f7

Please sign in to comment.