@@ -17,8 +17,11 @@ limitations under the License.
17
17
package utils
18
18
19
19
import (
20
+ "fmt"
20
21
"testing"
22
+ "time"
21
23
24
+ api_v1 "k8s.io/api/core/v1"
22
25
extensions "k8s.io/api/extensions/v1beta1"
23
26
"k8s.io/apimachinery/pkg/types"
24
27
"k8s.io/apimachinery/pkg/util/intstr"
@@ -452,6 +455,69 @@ func TestTraverseIngressBackends(t *testing.T) {
452
455
}
453
456
}
454
457
458
+ func TestGetNodeConditionPredicate (t * testing.T ) {
459
+ tests := []struct {
460
+ node api_v1.Node
461
+ expectAccept bool
462
+ name string
463
+ }{
464
+ {
465
+ node : api_v1.Node {},
466
+ expectAccept : false ,
467
+ name : "empty" ,
468
+ },
469
+ {
470
+ node : api_v1.Node {
471
+ Status : api_v1.NodeStatus {
472
+ Conditions : []api_v1.NodeCondition {
473
+ {Type : api_v1 .NodeReady , Status : api_v1 .ConditionTrue },
474
+ },
475
+ },
476
+ },
477
+ expectAccept : true ,
478
+ name : "basic" ,
479
+ },
480
+ {
481
+ node : api_v1.Node {
482
+ Spec : api_v1.NodeSpec {Unschedulable : true },
483
+ Status : api_v1.NodeStatus {
484
+ Conditions : []api_v1.NodeCondition {
485
+ {Type : api_v1 .NodeReady , Status : api_v1 .ConditionTrue },
486
+ },
487
+ },
488
+ },
489
+ expectAccept : false ,
490
+ name : "unschedulable" ,
491
+ }, {
492
+ node : api_v1.Node {
493
+ Spec : api_v1.NodeSpec {
494
+ Taints : []api_v1.Taint {
495
+ api_v1.Taint {
496
+ Key : ToBeDeletedTaint ,
497
+ Value : fmt .Sprint (time .Now ().Unix ()),
498
+ Effect : api_v1 .TaintEffectNoSchedule ,
499
+ },
500
+ },
501
+ },
502
+ Status : api_v1.NodeStatus {
503
+ Conditions : []api_v1.NodeCondition {
504
+ {Type : api_v1 .NodeReady , Status : api_v1 .ConditionTrue },
505
+ },
506
+ },
507
+ },
508
+ expectAccept : false ,
509
+ name : "ToBeDeletedByClusterAutoscaler-taint" ,
510
+ },
511
+ }
512
+ pred := GetNodeConditionPredicate ()
513
+ for _ , test := range tests {
514
+ accept := pred (& test .node )
515
+ if accept != test .expectAccept {
516
+ t .Errorf ("Test failed for %s, expected %v, saw %v" , test .name , test .expectAccept , accept )
517
+ }
518
+ }
519
+ }
520
+
455
521
func getTestIngress () {
456
522
return
457
523
}
0 commit comments