@@ -94,6 +94,11 @@ func TestSanitizedTemplateNodeInfoFromNodeGroup(t *testing.T) {
94
94
exampleNode .Spec .Taints = []apiv1.Taint {
95
95
{Key : taints .ToBeDeletedTaint , Value : "2312532423" , Effect : apiv1 .TaintEffectNoSchedule },
96
96
}
97
+ exampleNode .Labels = map [string ]string {
98
+ "custom" : "label" ,
99
+ apiv1 .LabelInstanceTypeStable : "some-instance" ,
100
+ apiv1 .LabelTopologyRegion : "some-region" ,
101
+ }
97
102
98
103
for _ , tc := range []struct {
99
104
testName string
@@ -156,7 +161,7 @@ func TestSanitizedTemplateNodeInfoFromNodeGroup(t *testing.T) {
156
161
// Pass empty string as nameSuffix so that it's auto-determined from the sanitized templateNodeInfo, because
157
162
// TemplateNodeInfoFromNodeGroupTemplate randomizes the suffix.
158
163
// Pass non-empty expectedPods to verify that the set of pods is changed as expected (e.g. DS pods added, non-DS/deleted pods removed).
159
- if err := verifyNodeInfoSanitization (tc .nodeGroup .templateNodeInfoResult , templateNodeInfo , tc .wantPods , "template-node-for-" + tc .nodeGroup .id , "" , nil ); err != nil {
164
+ if err := verifyNodeInfoSanitization (tc .nodeGroup .templateNodeInfoResult , templateNodeInfo , tc .wantPods , "template-node-for-" + tc .nodeGroup .id , "" , true , nil ); err != nil {
160
165
t .Fatalf ("TemplateNodeInfoFromExampleNodeInfo(): NodeInfo wasn't properly sanitized: %v" , err )
161
166
}
162
167
})
@@ -168,6 +173,11 @@ func TestSanitizedTemplateNodeInfoFromNodeInfo(t *testing.T) {
168
173
exampleNode .Spec .Taints = []apiv1.Taint {
169
174
{Key : taints .ToBeDeletedTaint , Value : "2312532423" , Effect : apiv1 .TaintEffectNoSchedule },
170
175
}
176
+ exampleNode .Labels = map [string ]string {
177
+ "custom" : "label" ,
178
+ apiv1 .LabelInstanceTypeStable : "some-instance" ,
179
+ apiv1 .LabelTopologyRegion : "some-region" ,
180
+ }
171
181
172
182
testCases := []struct {
173
183
name string
@@ -318,7 +328,7 @@ func TestSanitizedTemplateNodeInfoFromNodeInfo(t *testing.T) {
318
328
// Pass empty string as nameSuffix so that it's auto-determined from the sanitized templateNodeInfo, because
319
329
// TemplateNodeInfoFromExampleNodeInfo randomizes the suffix.
320
330
// Pass non-empty expectedPods to verify that the set of pods is changed as expected (e.g. DS pods added, non-DS/deleted pods removed).
321
- if err := verifyNodeInfoSanitization (exampleNodeInfo , templateNodeInfo , tc .wantPods , "template-node-for-" + nodeGroupId , "" , nil ); err != nil {
331
+ if err := verifyNodeInfoSanitization (exampleNodeInfo , templateNodeInfo , tc .wantPods , "template-node-for-" + nodeGroupId , "" , false , nil ); err != nil {
322
332
t .Fatalf ("TemplateNodeInfoFromExampleNodeInfo(): NodeInfo wasn't properly sanitized: %v" , err )
323
333
}
324
334
})
@@ -333,6 +343,12 @@ func TestSanitizedNodeInfo(t *testing.T) {
333
343
{Key : taints .ToBeDeletedTaint , Value : "2312532423" , Effect : apiv1 .TaintEffectNoSchedule },
334
344
{Key : "a" , Value : "b" , Effect : apiv1 .TaintEffectNoSchedule },
335
345
}
346
+ templateNode .Labels = map [string ]string {
347
+ "custom" : "label" ,
348
+ apiv1 .LabelInstanceTypeStable : "some-instance" ,
349
+ apiv1 .LabelTopologyRegion : "some-region" ,
350
+ }
351
+
336
352
pods := []* framework.PodInfo {
337
353
{Pod : BuildTestPod ("p1" , 80 , 0 , WithNodeName (nodeName ))},
338
354
{Pod : BuildTestPod ("p2" , 80 , 0 , WithNodeName (nodeName ))},
@@ -347,7 +363,7 @@ func TestSanitizedNodeInfo(t *testing.T) {
347
363
// Verify that the taints are not sanitized (they should be sanitized in the template already).
348
364
// Verify that the NodeInfo is sanitized using the template Node name as base.
349
365
initialTaints := templateNodeInfo .Node ().Spec .Taints
350
- if err := verifyNodeInfoSanitization (templateNodeInfo , freshNodeInfo , nil , templateNodeInfo .Node ().Name , suffix , initialTaints ); err != nil {
366
+ if err := verifyNodeInfoSanitization (templateNodeInfo , freshNodeInfo , nil , templateNodeInfo .Node ().Name , suffix , false , initialTaints ); err != nil {
351
367
t .Fatalf ("FreshNodeInfoFromTemplateNodeInfo(): NodeInfo wasn't properly sanitized: %v" , err )
352
368
}
353
369
}
@@ -358,9 +374,11 @@ func TestCreateSanitizedNodeInfo(t *testing.T) {
358
374
359
375
labelsNode := basicNode .DeepCopy ()
360
376
labelsNode .Labels = map [string ]string {
361
- apiv1 .LabelHostname : oldNodeName ,
362
- "a" : "b" ,
363
- "x" : "y" ,
377
+ apiv1 .LabelHostname : oldNodeName ,
378
+ "a" : "b" ,
379
+ "x" : "y" ,
380
+ apiv1 .LabelInstanceTypeStable : "some-instance" ,
381
+ apiv1 .LabelTopologyRegion : "some-region" ,
364
382
}
365
383
366
384
taintsNode := basicNode .DeepCopy ()
@@ -492,7 +510,7 @@ func TestCreateSanitizedNodeInfo(t *testing.T) {
492
510
if err != nil {
493
511
t .Fatalf ("sanitizeNodeInfo(): want nil error, got %v" , err )
494
512
}
495
- if err := verifyNodeInfoSanitization (tc .nodeInfo , nodeInfo , nil , newNameBase , suffix , tc .wantTaints ); err != nil {
513
+ if err := verifyNodeInfoSanitization (tc .nodeInfo , nodeInfo , nil , newNameBase , suffix , false , tc .wantTaints ); err != nil {
496
514
t .Fatalf ("sanitizeNodeInfo(): NodeInfo wasn't properly sanitized: %v" , err )
497
515
}
498
516
})
@@ -507,7 +525,7 @@ func TestCreateSanitizedNodeInfo(t *testing.T) {
507
525
//
508
526
// If expectedPods is nil, the set of pods is expected not to change between initialNodeInfo and sanitizedNodeInfo. If the sanitization is
509
527
// expected to change the set of pods, the expected set should be passed to expectedPods.
510
- func verifyNodeInfoSanitization (initialNodeInfo , sanitizedNodeInfo * framework.NodeInfo , expectedPods []* apiv1.Pod , nameBase , nameSuffix string , wantTaints []apiv1.Taint ) error {
528
+ func verifyNodeInfoSanitization (initialNodeInfo , sanitizedNodeInfo * framework.NodeInfo , expectedPods []* apiv1.Pod , nameBase , nameSuffix string , wantDeprecatedLabels bool , wantTaints []apiv1.Taint ) error {
511
529
if nameSuffix == "" {
512
530
// Determine the suffix from the provided sanitized NodeInfo - it should be the last part of a dash-separated name.
513
531
nameParts := strings .Split (sanitizedNodeInfo .Node ().Name , "-" )
@@ -527,7 +545,7 @@ func verifyNodeInfoSanitization(initialNodeInfo, sanitizedNodeInfo *framework.No
527
545
528
546
// Verification below assumes the same set of pods between initialNodeInfo and sanitizedNodeInfo.
529
547
wantNodeName := fmt .Sprintf ("%s-%s" , nameBase , nameSuffix )
530
- if err := verifySanitizedNode (initialNodeInfo .Node (), sanitizedNodeInfo .Node (), wantNodeName , wantTaints ); err != nil {
548
+ if err := verifySanitizedNode (initialNodeInfo .Node (), sanitizedNodeInfo .Node (), wantNodeName , wantDeprecatedLabels , wantTaints ); err != nil {
531
549
return err
532
550
}
533
551
if err := verifySanitizedNodeResourceSlices (initialNodeInfo .LocalResourceSlices , sanitizedNodeInfo .LocalResourceSlices , nameSuffix ); err != nil {
@@ -540,7 +558,7 @@ func verifyNodeInfoSanitization(initialNodeInfo, sanitizedNodeInfo *framework.No
540
558
return nil
541
559
}
542
560
543
- func verifySanitizedNode (initialNode , sanitizedNode * apiv1.Node , wantNodeName string , wantTaints []apiv1.Taint ) error {
561
+ func verifySanitizedNode (initialNode , sanitizedNode * apiv1.Node , wantNodeName string , wantDeprecatedLabels bool , wantTaints []apiv1.Taint ) error {
544
562
if gotName := sanitizedNode .Name ; gotName != wantNodeName {
545
563
return fmt .Errorf ("want sanitized Node name %q, got %q" , wantNodeName , gotName )
546
564
}
@@ -553,6 +571,9 @@ func verifySanitizedNode(initialNode, sanitizedNode *apiv1.Node, wantNodeName st
553
571
wantLabels [k ] = v
554
572
}
555
573
wantLabels [apiv1 .LabelHostname ] = wantNodeName
574
+ if wantDeprecatedLabels {
575
+ labels .UpdateDeprecatedLabels (wantLabels )
576
+ }
556
577
if diff := cmp .Diff (wantLabels , sanitizedNode .Labels ); diff != "" {
557
578
return fmt .Errorf ("sanitized Node labels unexpected, diff (-want +got): %s" , diff )
558
579
}
0 commit comments