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