@@ -1640,6 +1640,52 @@ func TestNodeAffinityDaemonLaunchesPods(t *testing.T) {
1640
1640
}
1641
1641
}
1642
1642
1643
+ // RequiredDuringSchedulingIgnoredDuringExecution means that if the node labels change after Kubernetes schedules the Pod, the Pod continues to run.
1644
+ func TestNodeAffinityAndChangeNodeLabels (t * testing.T ) {
1645
+ logger , _ := ktesting .NewTestContext (t )
1646
+ for _ , strategy := range updateStrategies () {
1647
+ daemon := newDaemonSet ("foo" )
1648
+ daemon .Spec .UpdateStrategy = * strategy
1649
+ daemon .Spec .Template .Spec .Affinity = & v1.Affinity {
1650
+ NodeAffinity : & v1.NodeAffinity {
1651
+ RequiredDuringSchedulingIgnoredDuringExecution : & v1.NodeSelector {
1652
+ NodeSelectorTerms : []v1.NodeSelectorTerm {
1653
+ {
1654
+ MatchExpressions : []v1.NodeSelectorRequirement {
1655
+ {
1656
+ Key : "color" ,
1657
+ Operator : v1 .NodeSelectorOpIn ,
1658
+ Values : []string {simpleNodeLabel ["color" ]},
1659
+ },
1660
+ },
1661
+ },
1662
+ },
1663
+ },
1664
+ },
1665
+ }
1666
+ _ , ctx := ktesting .NewTestContext (t )
1667
+
1668
+ manager , podControl , _ , err := newTestController (ctx , daemon )
1669
+ if err != nil {
1670
+ t .Fatalf ("error creating DaemonSetsController: %v" , err )
1671
+ }
1672
+ node1 := newNode ("node-1" , simpleNodeLabel )
1673
+ node2 := newNode ("node-2" , simpleNodeLabel )
1674
+ manager .nodeStore .Add (node1 )
1675
+ manager .nodeStore .Add (node2 )
1676
+ err = manager .dsStore .Add (daemon )
1677
+ if err != nil {
1678
+ t .Fatal (err )
1679
+ }
1680
+ expectSyncDaemonSets (t , manager , daemon , podControl , 2 , 0 , 0 )
1681
+ oldNode := node1 .DeepCopy ()
1682
+ node1 .Labels = nil
1683
+ manager .updateNode (logger , oldNode , node1 )
1684
+ manager .nodeStore .Add (newNode ("node-3" , nil ))
1685
+ expectSyncDaemonSets (t , manager , daemon , podControl , 2 , 0 , 0 )
1686
+ }
1687
+ }
1688
+
1643
1689
func TestNumberReadyStatus (t * testing.T ) {
1644
1690
for _ , strategy := range updateStrategies () {
1645
1691
ds := newDaemonSet ("foo" )
@@ -2284,7 +2330,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
2284
2330
shouldContinueRunning : true ,
2285
2331
},
2286
2332
{
2287
- predicateName : "ErrPodAffinityNotMatch " ,
2333
+ predicateName : "PodAffinityNotMatchDuringExecution " ,
2288
2334
ds : & apps.DaemonSet {
2289
2335
Spec : apps.DaemonSetSpec {
2290
2336
Selector : & metav1.LabelSelector {MatchLabels : simpleDaemonSetLabel },
@@ -2315,7 +2361,7 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
2315
2361
},
2316
2362
},
2317
2363
shouldRun : false ,
2318
- shouldContinueRunning : false ,
2364
+ shouldContinueRunning : true ,
2319
2365
},
2320
2366
{
2321
2367
predicateName : "ShouldRunDaemonPod" ,
@@ -2476,6 +2522,36 @@ func TestUpdateNode(t *testing.T) {
2476
2522
return 1
2477
2523
},
2478
2524
},
2525
+ {
2526
+ test : "Node labels changed, ds with NodeAffinity " ,
2527
+ oldNode : newNode ("node1" , simpleNodeLabel ),
2528
+ newNode : newNode ("node1" , simpleNodeLabel2 ),
2529
+ ds : func () * apps.DaemonSet {
2530
+ ds := newDaemonSet ("ds" )
2531
+ ds .Spec .Template .Spec .Affinity = & v1.Affinity {
2532
+ NodeAffinity : & v1.NodeAffinity {
2533
+ RequiredDuringSchedulingIgnoredDuringExecution : & v1.NodeSelector {
2534
+ NodeSelectorTerms : []v1.NodeSelectorTerm {
2535
+ {
2536
+ MatchExpressions : []v1.NodeSelectorRequirement {
2537
+ {
2538
+ Key : "color" ,
2539
+ Operator : v1 .NodeSelectorOpIn ,
2540
+ Values : []string {"blue" },
2541
+ },
2542
+ },
2543
+ },
2544
+ },
2545
+ },
2546
+ },
2547
+ }
2548
+ return ds
2549
+ }(),
2550
+ shouldEnqueue : true ,
2551
+ expectedCreates : func () int {
2552
+ return 1
2553
+ },
2554
+ },
2479
2555
}
2480
2556
for _ , c := range cases {
2481
2557
for _ , strategy := range updateStrategies () {
0 commit comments