Skip to content

Commit 0ecbc3c

Browse files
authored
[AKS] support HostGroupID (#20796)
* [AKS] support HostGroupID * add test asserts
1 parent 7750474 commit 0ecbc3c

File tree

8 files changed

+3960
-21
lines changed

8 files changed

+3960
-21
lines changed

src/Aks/Aks.Test/ScenarioTests/KubernetesTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,5 +184,12 @@ public void TestAadProfile()
184184
{
185185
TestRunner.RunTestScript("Test-AadProfile");
186186
}
187+
188+
[Fact]
189+
[Trait(Category.AcceptanceType, Category.CheckIn)]
190+
public void TestHostGroupID()
191+
{
192+
TestRunner.RunTestScript("Test-HostGroupID");
193+
}
187194
}
188195
}

src/Aks/Aks.Test/ScenarioTests/KubernetesTests.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,3 +1037,50 @@ function Test-AadProfile {
10371037
#Remove-AzADGroup -DisplayName $AdGroupName
10381038
}
10391039
}
1040+
1041+
function Test-HostGroupID {
1042+
# Setup
1043+
$resourceGroupName = Get-RandomResourceGroupName
1044+
$kubeClusterName = Get-RandomClusterName
1045+
$location = 'eastus'
1046+
1047+
try {
1048+
New-AzResourceGroup -Name $resourceGroupName -Location $location
1049+
1050+
#prepare a Dedicated Host and a user-assigned Identity
1051+
#$hostGroup = New-AzHostGroup -ResourceGroupName $resourceGroupName -Name $hostGroupName -Location $location -PlatformFaultDomain 1 -SupportAutomaticPlacement $true
1052+
#$hostSku = (Get-AzComputeResourceSku -Location $location | where ResourceType -eq "hostGroups/hosts")[0].Name
1053+
#New-AzHost -ResourceGroupName $resourceGroupName -HostGroupName $hostGroupName -Name $hostName -Location $location -Sku DSv3-Type1
1054+
#$azHost = Get-AzHost -ResourceGroupName $resourceGroupName -HostGroupName $hostGroupName -Name $hostName -InstanceView
1055+
#$nodeVmSize = ($azHost.InstanceView.AvailableCapacity.AllocatableVMs | Sort-Object -Property Count -Descending)[0].VmSize
1056+
1057+
#$identity = New-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $identityName -Location $location
1058+
#$roleAssignment = New-AzRoleAssignment -ObjectId $identity.PrincipalId -RoleDefinitionName Contributor -Scope $hostGroup.Id
1059+
1060+
#$hostGroupId = $hostGroup.Id
1061+
#$identityId = identity.Id
1062+
1063+
$hostGroupId = "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/AKS_TEST_RG/providers/Microsoft.Compute/hostGroups/aks_test_hostgroup"
1064+
$identityId = "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourcegroups/aks_test_rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/aks_test_mi"
1065+
$nodeVmSize = "Standard_D2s_v3"
1066+
1067+
# create aks cluster with default nodepool
1068+
New-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeVmSize $nodeVmSize -NodeCount 1 -NodeHostGroupID $hostGroupId -EnableManagedIdentity -AssignIdentity $identityId
1069+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
1070+
Assert-AreEqual $hostGroupId $cluster.AgentPoolProfiles[0].hostGroupID
1071+
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
1072+
Assert-AreEqual $hostGroupId $pools[0].hostGroupID
1073+
1074+
# create the 2nd nodepool
1075+
New-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name pool2 -VmSize $nodeVmSize -Count 1 -HostGroupID $hostGroupId
1076+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
1077+
Assert-AreEqual $hostGroupId $cluster.AgentPoolProfiles[0].hostGroupID
1078+
Assert-AreEqual $hostGroupId $cluster.AgentPoolProfiles[1].hostGroupID
1079+
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
1080+
Assert-AreEqual $hostGroupId $pools[0].hostGroupID
1081+
Assert-AreEqual $hostGroupId $pools[1].hostGroupID
1082+
}
1083+
finally {
1084+
Remove-AzResourceGroup -Name $resourceGroupName -Force
1085+
}
1086+
}

src/Aks/Aks.Test/SessionRecords/Commands.Aks.Test.ScenarioTests.KubernetesTests/TestHostGroupID.json

Lines changed: 3841 additions & 0 deletions
Large diffs are not rendered by default.

src/Aks/Aks/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Added parameter `-AadProfile` for `New-AzAksCluster` and `Set-AzAksCluster`
22+
* Added parameter `-NodeHostGroupID` for `New-AzAksCluster` and parameter `-HostGroupID` for `New-AzAksNodePool`
2223

2324
## Version 5.2.0
2425
* Added parameter `-EnableEncryptionAtHost` for `New-AzAksCluster` and `New-AzAksNodePool`

src/Aks/Aks/Commands/NewAzureRmAks.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ public class NewAzureRmAks : CreateOrUpdateKubeBase
173173
[Parameter(Mandatory = false, HelpMessage = "The name of the Edge Zone.")]
174174
public string EdgeZone { get; set; }
175175

176+
[Parameter(Mandatory = false, HelpMessage = "The fully qualified resource ID of the Dedicated Host Group to provision virtual machines from, used only in creation scenario and not allowed to changed once set.")]
177+
public string NodeHostGroupID { get; set; }
178+
176179
private AcsServicePrincipal acsServicePrincipal;
177180

178181
public override void ExecuteCmdlet()
@@ -569,6 +572,9 @@ private ManagedClusterAgentPoolProfile GetAgentPoolProfile()
569572
{
570573
defaultAgentPoolProfile.GpuInstanceProfile = GpuInstanceProfile;
571574
}
575+
if (this.IsParameterBound(c => c.NodeHostGroupID)) {
576+
defaultAgentPoolProfile.HostGroupID = NodeHostGroupID;
577+
}
572578

573579
defaultAgentPoolProfile.Mode = NodePoolMode;
574580

src/Aks/Aks/Commands/NewAzureRmAksNodePool.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ public class NewAzureRmAksNodePool : NewOrUpdateAgentPoolBase
128128
[PSArgumentCompleter("MIG1g", "MIG2g", "MIG3g", "MIG4g", "MIG7g")]
129129
public string GpuInstanceProfile { get; set; }
130130

131+
[Parameter(Mandatory = false, HelpMessage = "The fully qualified resource ID of the Dedicated Host Group to provision virtual machines from, used only in creation scenario and not allowed to changed once set.")]
132+
public string HostGroupID { get; set; }
133+
131134
public override void ExecuteCmdlet()
132135
{
133136
base.ExecuteCmdlet();
@@ -281,6 +284,10 @@ private AgentPool GetAgentPool()
281284
{
282285
agentPool.GpuInstanceProfile = GpuInstanceProfile;
283286
}
287+
if (this.IsParameterBound(c => c.HostGroupID))
288+
{
289+
agentPool.HostGroupID = HostGroupID;
290+
}
284291

285292
return agentPool;
286293
}

src/Aks/Aks/help/New-AzAksCluster.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ New-AzAksCluster [-NodeVmSetType <String>] [-NodeVnetSubnetID <String>] [-NodeMa
2727
[-AvailabilityZone <String[]>] [-NodeResourceGroup <String>] [-EnableEncryptionAtHost] [-EnableUltraSSD]
2828
[-NodeLinuxOSConfig <LinuxOSConfig>] [-NodeKubeletConfig <KubeletConfig>] [-NodeMaxSurge <String>]
2929
[-PPG <String>] [-EnableFIPS] [-AutoScalerProfile <ManagedClusterPropertiesAutoScalerProfile>]
30-
[-GpuInstanceProfile <String>] [-EnableUptimeSLA] [-EdgeZone <String>] [-ResourceGroupName] <String>
31-
[-Name] <String> [[-ServicePrincipalIdAndSecret] <PSCredential>] [-Location <String>]
32-
[-LinuxProfileAdminUserName <String>] [-DnsNamePrefix <String>] [-KubernetesVersion <String>]
33-
[-NodeName <String>] [-NodeMinCount <Int32>] [-NodeMaxCount <Int32>] [-EnableNodeAutoScaling]
34-
[-NodeCount <Int32>] [-NodeOsDiskSize <Int32>] [-NodeVmSize <String>] [-NodePoolLabel <Hashtable>]
35-
[-NodePoolTag <Hashtable>] [-SshKeyValue <String>] [-AcrNameToAttach <String>] [-AsJob] [-Tag <Hashtable>]
36-
[-LoadBalancerAllocatedOutboundPort <Int32>] [-LoadBalancerManagedOutboundIpCount <Int32>]
37-
[-LoadBalancerOutboundIp <String[]>] [-LoadBalancerOutboundIpPrefix <String[]>]
38-
[-LoadBalancerIdleTimeoutInMinute <Int32>] [-ApiServerAccessAuthorizedIpRange <String[]>]
39-
[-EnableApiServerAccessPrivateCluster] [-ApiServerAccessPrivateDnsZone <String>]
40-
[-EnableApiServerAccessPrivateClusterPublicFQDN] [-FqdnSubdomain <String>] [-EnableManagedIdentity]
41-
[-AssignIdentity <String>] [-AutoUpgradeChannel <String>] [-DiskEncryptionSetID <String>]
42-
[-DisableLocalAccount] [-HttpProxy <String>] [-HttpsProxy <String>]
30+
[-GpuInstanceProfile <String>] [-EnableUptimeSLA] [-EdgeZone <String>] [-NodeHostGroupID <String>]
31+
[-ResourceGroupName] <String> [-Name] <String> [[-ServicePrincipalIdAndSecret] <PSCredential>]
32+
[-Location <String>] [-LinuxProfileAdminUserName <String>] [-DnsNamePrefix <String>]
33+
[-KubernetesVersion <String>] [-NodeName <String>] [-NodeMinCount <Int32>] [-NodeMaxCount <Int32>]
34+
[-EnableNodeAutoScaling] [-NodeCount <Int32>] [-NodeOsDiskSize <Int32>] [-NodeVmSize <String>]
35+
[-NodePoolLabel <Hashtable>] [-NodePoolTag <Hashtable>] [-SshKeyValue <String>] [-AcrNameToAttach <String>]
36+
[-AsJob] [-Tag <Hashtable>] [-LoadBalancerAllocatedOutboundPort <Int32>]
37+
[-LoadBalancerManagedOutboundIpCount <Int32>] [-LoadBalancerOutboundIp <String[]>]
38+
[-LoadBalancerOutboundIpPrefix <String[]>] [-LoadBalancerIdleTimeoutInMinute <Int32>]
39+
[-ApiServerAccessAuthorizedIpRange <String[]>] [-EnableApiServerAccessPrivateCluster]
40+
[-ApiServerAccessPrivateDnsZone <String>] [-EnableApiServerAccessPrivateClusterPublicFQDN]
41+
[-FqdnSubdomain <String>] [-EnableManagedIdentity] [-AssignIdentity <String>] [-AutoUpgradeChannel <String>]
42+
[-DiskEncryptionSetID <String>] [-DisableLocalAccount] [-HttpProxy <String>] [-HttpsProxy <String>]
4343
[-HttpProxyConfigNoProxyEndpoint <String[]>] [-HttpProxyConfigTrustedCa <String>]
4444
[-AksCustomHeader <Hashtable>] [-AadProfile <ManagedClusterAADProfile>]
4545
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
@@ -862,6 +862,21 @@ Accept pipeline input: False
862862
Accept wildcard characters: False
863863
```
864864
865+
### -NodeHostGroupID
866+
The fully qualified resource ID of the Dedicated Host Group to provision virtual machines from, used only in creation scenario and not allowed to changed once set.
867+
868+
```yaml
869+
Type: System.String
870+
Parameter Sets: (All)
871+
Aliases:
872+
873+
Required: False
874+
Position: Named
875+
Default value: None
876+
Accept pipeline input: False
877+
Accept wildcard characters: False
878+
```
879+
865880
### -NodeKubeletConfig
866881
The Kubelet configuration on the agent pool nodes.
867882

src/Aks/Aks/help/New-AzAksNodePool.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ New-AzAksNodePool -ResourceGroupName <String> -ClusterName <String> -Name <Strin
2020
[-ScaleSetEvictionPolicy <String>] [-VmSetType <String>] [-AvailabilityZone <String[]>] [-Force]
2121
[-EnableEncryptionAtHost] [-EnableUltraSSD] [-LinuxOSConfig <LinuxOSConfig>] [-KubeletConfig <KubeletConfig>]
2222
[-MaxSurge <String>] [-PPG <String>] [-SpotMaxPrice <Double>] [-EnableFIPS] [-GpuInstanceProfile <String>]
23-
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling] [-Mode <String>]
24-
[-NodeLabel <Hashtable>] [-Tag <Hashtable>] [-NodeTaint <String[]>] [-AksCustomHeader <Hashtable>]
25-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
26-
[<CommonParameters>]
23+
[-HostGroupID <String>] [-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>]
24+
[-EnableAutoScaling] [-Mode <String>] [-NodeLabel <Hashtable>] [-Tag <Hashtable>] [-NodeTaint <String[]>]
25+
[-AksCustomHeader <Hashtable>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
26+
[-SubscriptionId <String>] [<CommonParameters>]
2727
```
2828

2929
### ParentObjectParameterSet
@@ -34,10 +34,10 @@ New-AzAksNodePool -Name <String> -ClusterObject <PSKubernetesCluster> [-Count <I
3434
[-ScaleSetEvictionPolicy <String>] [-VmSetType <String>] [-AvailabilityZone <String[]>] [-Force]
3535
[-EnableEncryptionAtHost] [-EnableUltraSSD] [-LinuxOSConfig <LinuxOSConfig>] [-KubeletConfig <KubeletConfig>]
3636
[-MaxSurge <String>] [-PPG <String>] [-SpotMaxPrice <Double>] [-EnableFIPS] [-GpuInstanceProfile <String>]
37-
[-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>] [-EnableAutoScaling] [-Mode <String>]
38-
[-NodeLabel <Hashtable>] [-Tag <Hashtable>] [-NodeTaint <String[]>] [-AksCustomHeader <Hashtable>]
39-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
40-
[<CommonParameters>]
37+
[-HostGroupID <String>] [-KubernetesVersion <String>] [-MinCount <Int32>] [-MaxCount <Int32>]
38+
[-EnableAutoScaling] [-Mode <String>] [-NodeLabel <Hashtable>] [-Tag <Hashtable>] [-NodeTaint <String[]>]
39+
[-AksCustomHeader <Hashtable>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
40+
[-SubscriptionId <String>] [<CommonParameters>]
4141
```
4242

4343
## DESCRIPTION
@@ -282,6 +282,21 @@ Accept pipeline input: False
282282
Accept wildcard characters: False
283283
```
284284
285+
### -HostGroupID
286+
The fully qualified resource ID of the Dedicated Host Group to provision virtual machines from, used only in creation scenario and not allowed to changed once set.
287+
288+
```yaml
289+
Type: System.String
290+
Parameter Sets: (All)
291+
Aliases:
292+
293+
Required: False
294+
Position: Named
295+
Default value: None
296+
Accept pipeline input: False
297+
Accept wildcard characters: False
298+
```
299+
285300
### -KubeletConfig
286301
The Kubelet configuration on the agent pool nodes.
287302

0 commit comments

Comments
 (0)