Skip to content

Commit 5661274

Browse files
authored
[AKS] support NodeLabels and Tags (#20240)
* [AKS] support NodeLabels * [AKS] support Tags * rename input parameters to singular nouns * remove Install-AzAksKubectl.md
1 parent 8bf099e commit 5661274

19 files changed

+9277
-61
lines changed

src/Aks/Aks.Test/ScenarioTests/Common.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,29 @@ function Assert-Error
9999
Assert-True {$result}
100100

101101
$Error.Clear()
102+
}
103+
104+
function Assert-HashTableEquals {
105+
param([HashTable] $expected, [HashTable] $actual, [string] $message)
106+
107+
if (!$message) {
108+
$expectedStr = $expected | Out-String
109+
$actualStr = $actual | Out-String
110+
$message = "Assertion failed because '$expectedStr' does not match actual '$actualStr'"
111+
}
112+
113+
if ($expected.Count -ne $actual.Count) {
114+
throw $message
115+
}
116+
117+
foreach ($key in $expected.Keys) {
118+
if (-not $expected.ContainsKey($key)) {
119+
throw $message
120+
}
121+
if ($expected[$key] -ne $actual[$key]) {
122+
throw $message
123+
}
124+
}
125+
126+
return $true
102127
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,18 @@ public void TestManagedIdentity()
8080
TestRunner.RunTestScript("Test-ManagedIdentity");
8181
}
8282

83-
8483
[Fact]
8584
[Trait(Category.AcceptanceType, Category.CheckIn)]
8685
public void TestOsSku()
8786
{
8887
TestRunner.RunTestScript("Test-OSSku");
8988
}
89+
90+
[Fact]
91+
[Trait(Category.AcceptanceType, Category.CheckIn)]
92+
public void TestNodeLabelsAndTags()
93+
{
94+
TestRunner.RunTestScript("Test-NodeLabels-Tags");
95+
}
9096
}
9197
}

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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,98 @@ function Test-OSSku
393393
{
394394
Remove-AzResourceGroup -Name $resourceGroupName -Force
395395
}
396+
}
397+
398+
function Test-NodeLabels-Tags {
399+
# Setup
400+
$resourceGroupName = Get-RandomResourceGroupName
401+
$kubeClusterName = Get-RandomClusterName
402+
$location = 'eastus'
403+
$nodeVmSize = "Standard_D2_v2"
404+
405+
try {
406+
New-AzResourceGroup -Name $resourceGroupName -Location $location
407+
408+
# create aks cluster with default nodepool
409+
$labels1 = @{"someId" = 123; "app" = "test" }
410+
$tags1 = @{"dept"="IT"; "costcenter"=9999}
411+
New-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeVmSize $nodeVmSize -NodeCount 1 -NodePoolLabel $labels1 -NodePoolTag $tags1
412+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
413+
Assert-AreEqual 1 $cluster.AgentPoolProfiles.Count
414+
Assert-HashTableEquals $labels1 $cluster.AgentPoolProfiles[0].NodeLabels
415+
Assert-HashTableEquals $tags1 $cluster.AgentPoolProfiles[0].Tags
416+
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
417+
Assert-AreEqual 1 $pools.Count
418+
Assert-HashTableEquals $labels1 $pools[0].NodeLabels
419+
Assert-HashTableEquals $tags1 $pools[0].Tags
420+
421+
# update aks cluster default nodepool
422+
$labels2 = @{"someId" = 124; "app" = "test"; "environment" = "dev" }
423+
$tags2 = @{"dept"="Finance"; "costcenter"=8888}
424+
Set-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodePoolLabel $labels2 -NodePoolTag $tags2
425+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
426+
Assert-AreEqual 1 $cluster.AgentPoolProfiles.Count
427+
Assert-HashTableEquals $labels2 $cluster.AgentPoolProfiles[0].NodeLabels
428+
Assert-HashTableEquals $tags2 $cluster.AgentPoolProfiles[0].Tags
429+
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
430+
Assert-AreEqual 1 $pools.Count
431+
Assert-HashTableEquals $labels2 $pools[0].NodeLabels
432+
Assert-HashTableEquals $tags2 $pools[0].Tags
433+
434+
# create a 2nd nodepool
435+
$labels3 = @{"someId" = 125; "tier" = "frontend" }
436+
$tags3 = @{"dept"="Finance"; "costcenter"=8888; "Admin"="Alice"}
437+
New-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name "pool2" -Count 1 -NodeLabel $labels3 -Tag $tags3
438+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
439+
Assert-AreEqual 2 $cluster.AgentPoolProfiles.Count
440+
Assert-HashTableEquals $labels2 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).NodeLabels
441+
Assert-HashTableEquals $tags2 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Tags
442+
Assert-HashTableEquals $labels3 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).NodeLabels
443+
Assert-HashTableEquals $tags3 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Tags
444+
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
445+
Assert-AreEqual 2 $pools.Count
446+
Assert-HashTableEquals $labels2 ($pools | where {$_.Name -eq "default"}).NodeLabels
447+
Assert-HashTableEquals $tags2 ($pools | where {$_.Name -eq "default"}).Tags
448+
Assert-HashTableEquals $labels3 ($pools | where {$_.Name -eq "pool2"}).NodeLabels
449+
Assert-HashTableEquals $tags3 ($pools | where {$_.Name -eq "pool2"}).Tags
450+
451+
# update the 2nd nodepool
452+
$labels4 = @{"someId" = 126; "app" = "test"; "environment" = "qa" }
453+
$tags4 = @{"dept"="HR"; "costcenter"=6666; "Admin"="Bruce"}
454+
Set-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeName "pool2" -NodePoolLabel $labels4 -NodePoolTag $tags4
455+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
456+
Assert-AreEqual 2 $cluster.AgentPoolProfiles.Count
457+
Assert-HashTableEquals $labels2 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).NodeLabels
458+
Assert-HashTableEquals $tags2 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Tags
459+
Assert-HashTableEquals $labels4 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).NodeLabels
460+
Assert-HashTableEquals $tags4 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Tags
461+
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
462+
Assert-AreEqual 2 $pools.Count
463+
Assert-HashTableEquals $labels2 ($pools | where {$_.Name -eq "default"}).NodeLabels
464+
Assert-HashTableEquals $tags2 ($pools | where {$_.Name -eq "default"}).Tags
465+
Assert-HashTableEquals $labels4 ($pools | where {$_.Name -eq "pool2"}).NodeLabels
466+
Assert-HashTableEquals $tags4 ($pools | where {$_.Name -eq "pool2"}).Tags
467+
468+
# update the default nodepool
469+
$labels5 = @{"someId" = 127; "tier" = "frontend"; "environment" = "qa" }
470+
$tags5 = @{"dept"="MM"; "costcenter"=7777; "Admin"="Cindy"}
471+
Update-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name "default" -NodeLabel $labels5 -Tag $tags5
472+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
473+
Assert-AreEqual 2 $cluster.AgentPoolProfiles.Count
474+
Assert-HashTableEquals $labels5 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).NodeLabels
475+
Assert-HashTableEquals $tags5 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Tags
476+
Assert-HashTableEquals $labels4 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).NodeLabels
477+
Assert-HashTableEquals $tags4 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Tags
478+
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
479+
Assert-AreEqual 2 $pools.Count
480+
Assert-HashTableEquals $labels5 ($pools | where {$_.Name -eq "default"}).NodeLabels
481+
Assert-HashTableEquals $tags5 ($pools | where {$_.Name -eq "default"}).Tags
482+
Assert-HashTableEquals $labels4 ($pools | where {$_.Name -eq "pool2"}).NodeLabels
483+
Assert-HashTableEquals $tags4 ($pools | where {$_.Name -eq "pool2"}).Tags
484+
485+
$cluster | Remove-AzAksCluster -Force
486+
}
487+
finally {
488+
Remove-AzResourceGroup -Name $resourceGroupName -Force
489+
}
396490
}

0 commit comments

Comments
 (0)