@@ -393,4 +393,98 @@ function Test-OSSku
393
393
{
394
394
Remove-AzResourceGroup - Name $resourceGroupName - Force
395
395
}
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
+ }
396
490
}
0 commit comments