@@ -773,27 +773,46 @@ func TestIsNodeStillStarting(t *testing.T) {
773
773
desc string
774
774
condition apiv1.NodeConditionType
775
775
status apiv1.ConditionStatus
776
+ taintKey string
776
777
expectedResult bool
777
778
}{
778
- {"unready" , apiv1 .NodeReady , apiv1 .ConditionFalse , true },
779
- {"readiness unknown" , apiv1 .NodeReady , apiv1 .ConditionUnknown , true },
780
- {"out of disk" , apiv1 .NodeDiskPressure , apiv1 .ConditionTrue , true },
781
- {"network unavailable" , apiv1 .NodeNetworkUnavailable , apiv1 .ConditionTrue , true },
782
- {"started" , apiv1 .NodeReady , apiv1 .ConditionTrue , false },
779
+ {"unready" , apiv1 .NodeReady , apiv1 .ConditionFalse , "" , true },
780
+ {"readiness unknown" , apiv1 .NodeReady , apiv1 .ConditionUnknown , "" , true },
781
+ {"out of disk" , apiv1 .NodeDiskPressure , apiv1 .ConditionTrue , "" , true },
782
+ {"network unavailable" , apiv1 .NodeNetworkUnavailable , apiv1 .ConditionTrue , "" , true },
783
+ {"started" , apiv1 .NodeReady , apiv1 .ConditionTrue , "" , false },
784
+ {"unready and unready taint" , apiv1 .NodeReady , apiv1 .ConditionFalse , apiv1 .TaintNodeNotReady , true },
785
+ {"readiness unknown and unready taint" , apiv1 .NodeReady , apiv1 .ConditionUnknown , apiv1 .TaintNodeNotReady , true },
786
+ {"disk pressure and disk pressure taint" , apiv1 .NodeDiskPressure , apiv1 .ConditionTrue , apiv1 .TaintNodeDiskPressure , true },
787
+ {"network unavailable and network unavailable taint" , apiv1 .NodeNetworkUnavailable , apiv1 .ConditionTrue , apiv1 .TaintNodeNetworkUnavailable , true },
788
+ {"ready but unready taint" , apiv1 .NodeReady , apiv1 .ConditionTrue , apiv1 .TaintNodeNotReady , true },
789
+ {"no disk pressure but disk pressure taint" , apiv1 .NodeDiskPressure , apiv1 .ConditionFalse , apiv1 .TaintNodeDiskPressure , true },
790
+ {"network available but network unavailable taint" , apiv1 .NodeNetworkUnavailable , apiv1 .ConditionFalse , apiv1 .TaintNodeNetworkUnavailable , true },
783
791
}
784
-
785
- now := time .Now ()
786
792
for _ , tc := range testCases {
787
- t . Run ( "recent " + tc . desc , func (t * testing. T ) {
793
+ createTestNode := func (timeSinceCreation time. Duration ) * apiv1. Node {
788
794
node := BuildTestNode ("n1" , 1000 , 1000 )
789
- node .CreationTimestamp .Time = now
790
- SetNodeCondition (node , tc .condition , tc .status , now .Add (1 * time .Minute ))
795
+ node .CreationTimestamp .Time = time.Time {}
796
+ testedTime := node .CreationTimestamp .Time .Add (timeSinceCreation )
797
+
798
+ SetNodeCondition (node , tc .condition , tc .status , testedTime )
799
+
800
+ if tc .taintKey != "" {
801
+ node .Spec .Taints = []apiv1.Taint {{
802
+ Key : tc .taintKey ,
803
+ Effect : apiv1 .TaintEffectNoSchedule ,
804
+ TimeAdded : & metav1.Time {Time : testedTime },
805
+ }}
806
+ }
807
+
808
+ return node
809
+ }
810
+ t .Run ("recent " + tc .desc , func (t * testing.T ) {
811
+ node := createTestNode (1 * time .Minute )
791
812
assert .Equal (t , tc .expectedResult , isNodeStillStarting (node ))
792
813
})
793
814
t .Run ("long " + tc .desc , func (t * testing.T ) {
794
- node := BuildTestNode ("n1" , 1000 , 1000 )
795
- node .CreationTimestamp .Time = now
796
- SetNodeCondition (node , tc .condition , tc .status , now .Add (30 * time .Minute ))
815
+ node := createTestNode (30 * time .Minute )
797
816
// No matter what are the node's conditions, stop considering it not started after long enough.
798
817
assert .False (t , isNodeStillStarting (node ))
799
818
})
0 commit comments