@@ -21,6 +21,7 @@ import (
2121 "strings"
2222 "testing"
2323
24+ "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v5"
2425 "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
2526 "github.com/Azure/go-autorest/autorest"
2627 "github.com/Azure/go-autorest/autorest/to"
@@ -137,6 +138,11 @@ func TestExtractTaintsFromSpecString(t *testing.T) {
137138 Value : "fizz" ,
138139 Effect : apiv1 .TaintEffectPreferNoSchedule ,
139140 },
141+ {
142+ Key : "dedicated" , // duplicate key, should be ignored
143+ Value : "foo" ,
144+ Effect : apiv1 .TaintEffectNoSchedule ,
145+ },
140146 }
141147
142148 taints := extractTaintsFromSpecString (strings .Join (taintsString , "," ))
@@ -222,6 +228,61 @@ func TestEmptyTopologyFromScaleSet(t *testing.T) {
222228 assert .True (t , ok )
223229 assert .Equal (t , expectedAzureDiskTopology , azureDiskTopology )
224230}
231+ func TestBuildNodeTemplateFromVMPool (t * testing.T ) {
232+ agentPoolName := "testpool"
233+ location := "eastus"
234+ skuName := "Standard_DS2_v2"
235+ labelKey := "foo"
236+ labelVal := "bar"
237+ taintStr := "dedicated=foo:NoSchedule,boo=fizz:PreferNoSchedule,group=bar:NoExecute"
238+
239+ osType := armcontainerservice .OSTypeLinux
240+ osDiskType := armcontainerservice .OSDiskTypeEphemeral
241+ zone1 := "1"
242+ zone2 := "2"
243+
244+ vmpool := armcontainerservice.AgentPool {
245+ Name : to .StringPtr (agentPoolName ),
246+ Properties : & armcontainerservice.ManagedClusterAgentPoolProfileProperties {
247+ NodeLabels : map [string ]* string {
248+ "existing" : to .StringPtr ("label" ),
249+ "department" : to .StringPtr ("engineering" ),
250+ },
251+ NodeTaints : []* string {to .StringPtr ("group=bar:NoExecute" )},
252+ OSType : & osType ,
253+ OSDiskType : & osDiskType ,
254+ AvailabilityZones : []* string {& zone1 , & zone2 },
255+ },
256+ }
257+
258+ labelsFromSpec := map [string ]string {labelKey : labelVal }
259+ taintsFromSpec := taintStr
260+
261+ template , err := buildNodeTemplateFromVMPool (vmpool , location , skuName , labelsFromSpec , taintsFromSpec )
262+ assert .NoError (t , err )
263+ assert .Equal (t , skuName , template .SkuName )
264+ assert .Equal (t , location , template .Location )
265+ assert .ElementsMatch (t , []string {zone1 , zone2 }, template .Zones )
266+ assert .Equal (t , "linux" , template .InstanceOS )
267+ assert .NotNil (t , template .VMPoolNodeTemplate )
268+ assert .Equal (t , agentPoolName , template .VMPoolNodeTemplate .AgentPoolName )
269+ assert .Equal (t , & osDiskType , template .VMPoolNodeTemplate .OSDiskType )
270+ // Labels: should include both from NodeLabels and labelsFromSpec
271+ assert .Contains (t , template .VMPoolNodeTemplate .Labels , "existing" )
272+ assert .Equal (t , "label" , * template .VMPoolNodeTemplate .Labels ["existing" ])
273+ assert .Contains (t , template .VMPoolNodeTemplate .Labels , "department" )
274+ assert .Equal (t , "engineering" , * template .VMPoolNodeTemplate .Labels ["department" ])
275+ assert .Contains (t , template .VMPoolNodeTemplate .Labels , labelKey )
276+ assert .Equal (t , labelVal , * template .VMPoolNodeTemplate .Labels [labelKey ])
277+ // Taints: should include both from NodeTaints and taintsFromSpec
278+ taintSet := makeTaintSet (template .VMPoolNodeTemplate .Taints )
279+ expectedTaints := []apiv1.Taint {
280+ {Key : "group" , Value : "bar" , Effect : apiv1 .TaintEffectNoExecute },
281+ {Key : "dedicated" , Value : "foo" , Effect : apiv1 .TaintEffectNoSchedule },
282+ {Key : "boo" , Value : "fizz" , Effect : apiv1 .TaintEffectPreferNoSchedule },
283+ }
284+ assert .Equal (t , makeTaintSet (expectedTaints ), taintSet )
285+ }
225286
226287func makeTaintSet (taints []apiv1.Taint ) map [apiv1.Taint ]bool {
227288 set := make (map [apiv1.Taint ]bool )
0 commit comments