Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AKS] support NodeLabels and Tags #20240

Merged
merged 4 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Aks/Aks.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,29 @@ function Assert-Error
Assert-True {$result}

$Error.Clear()
}

function Assert-HashTableEquals {
param([HashTable] $expected, [HashTable] $actual, [string] $message)

if (!$message) {
$expectedStr = $expected | Out-String
$actualStr = $actual | Out-String
$message = "Assertion failed because '$expectedStr' does not match actual '$actualStr'"
}

if ($expected.Count -ne $actual.Count) {
throw $message
}

foreach ($key in $expected.Keys) {
if (-not $expected.ContainsKey($key)) {
throw $message
}
if ($expected[$key] -ne $actual[$key]) {
throw $message
}
}

return $true
}
8 changes: 7 additions & 1 deletion src/Aks/Aks.Test/ScenarioTests/KubernetesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ public void TestManagedIdentity()
TestRunner.RunTestScript("Test-ManagedIdentity");
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestOsSku()
{
TestRunner.RunTestScript("Test-OSSku");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNodeLabelsAndTags()
{
TestRunner.RunTestScript("Test-NodeLabels-Tags");
}
}
}
94 changes: 94 additions & 0 deletions src/Aks/Aks.Test/ScenarioTests/KubernetesTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,98 @@ function Test-OSSku
{
Remove-AzResourceGroup -Name $resourceGroupName -Force
}
}

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

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

# create aks cluster with default nodepool
$labels1 = @{"someId" = 123; "app" = "test" }
$tags1 = @{"dept"="IT"; "costcenter"=9999}
New-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeVmSize $nodeVmSize -NodeCount 1 -NodePoolLabel $labels1 -NodePoolTag $tags1
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 1 $cluster.AgentPoolProfiles.Count
Assert-HashTableEquals $labels1 $cluster.AgentPoolProfiles[0].NodeLabels
Assert-HashTableEquals $tags1 $cluster.AgentPoolProfiles[0].Tags
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 1 $pools.Count
Assert-HashTableEquals $labels1 $pools[0].NodeLabels
Assert-HashTableEquals $tags1 $pools[0].Tags

# update aks cluster default nodepool
$labels2 = @{"someId" = 124; "app" = "test"; "environment" = "dev" }
$tags2 = @{"dept"="Finance"; "costcenter"=8888}
Set-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodePoolLabel $labels2 -NodePoolTag $tags2
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 1 $cluster.AgentPoolProfiles.Count
Assert-HashTableEquals $labels2 $cluster.AgentPoolProfiles[0].NodeLabels
Assert-HashTableEquals $tags2 $cluster.AgentPoolProfiles[0].Tags
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 1 $pools.Count
Assert-HashTableEquals $labels2 $pools[0].NodeLabels
Assert-HashTableEquals $tags2 $pools[0].Tags

# create a 2nd nodepool
$labels3 = @{"someId" = 125; "tier" = "frontend" }
$tags3 = @{"dept"="Finance"; "costcenter"=8888; "Admin"="Alice"}
New-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name "pool2" -Count 1 -NodeLabel $labels3 -Tag $tags3
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 2 $cluster.AgentPoolProfiles.Count
Assert-HashTableEquals $labels2 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).NodeLabels
Assert-HashTableEquals $tags2 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Tags
Assert-HashTableEquals $labels3 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).NodeLabels
Assert-HashTableEquals $tags3 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Tags
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 2 $pools.Count
Assert-HashTableEquals $labels2 ($pools | where {$_.Name -eq "default"}).NodeLabels
Assert-HashTableEquals $tags2 ($pools | where {$_.Name -eq "default"}).Tags
Assert-HashTableEquals $labels3 ($pools | where {$_.Name -eq "pool2"}).NodeLabels
Assert-HashTableEquals $tags3 ($pools | where {$_.Name -eq "pool2"}).Tags

# update the 2nd nodepool
$labels4 = @{"someId" = 126; "app" = "test"; "environment" = "qa" }
$tags4 = @{"dept"="HR"; "costcenter"=6666; "Admin"="Bruce"}
Set-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeName "pool2" -NodePoolLabel $labels4 -NodePoolTag $tags4
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 2 $cluster.AgentPoolProfiles.Count
Assert-HashTableEquals $labels2 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).NodeLabels
Assert-HashTableEquals $tags2 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Tags
Assert-HashTableEquals $labels4 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).NodeLabels
Assert-HashTableEquals $tags4 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Tags
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 2 $pools.Count
Assert-HashTableEquals $labels2 ($pools | where {$_.Name -eq "default"}).NodeLabels
Assert-HashTableEquals $tags2 ($pools | where {$_.Name -eq "default"}).Tags
Assert-HashTableEquals $labels4 ($pools | where {$_.Name -eq "pool2"}).NodeLabels
Assert-HashTableEquals $tags4 ($pools | where {$_.Name -eq "pool2"}).Tags

# update the default nodepool
$labels5 = @{"someId" = 127; "tier" = "frontend"; "environment" = "qa" }
$tags5 = @{"dept"="MM"; "costcenter"=7777; "Admin"="Cindy"}
Update-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName -Name "default" -NodeLabel $labels5 -Tag $tags5
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
Assert-AreEqual 2 $cluster.AgentPoolProfiles.Count
Assert-HashTableEquals $labels5 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).NodeLabels
Assert-HashTableEquals $tags5 ($cluster.AgentPoolProfiles | where {$_.Name -eq "default"}).Tags
Assert-HashTableEquals $labels4 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).NodeLabels
Assert-HashTableEquals $tags4 ($cluster.AgentPoolProfiles | where {$_.Name -eq "pool2"}).Tags
$pools = Get-AzAksNodePool -ResourceGroupName $resourceGroupName -ClusterName $kubeClusterName
Assert-AreEqual 2 $pools.Count
Assert-HashTableEquals $labels5 ($pools | where {$_.Name -eq "default"}).NodeLabels
Assert-HashTableEquals $tags5 ($pools | where {$_.Name -eq "default"}).Tags
Assert-HashTableEquals $labels4 ($pools | where {$_.Name -eq "pool2"}).NodeLabels
Assert-HashTableEquals $tags4 ($pools | where {$_.Name -eq "pool2"}).Tags

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