@@ -431,15 +431,15 @@ func RemoveTaintOffNode(cs clientset.Interface, nodeName string, taint v1.Taint)
431
431
432
432
// WaitForNodeTaints waits for a node to have the target taints and returns
433
433
// an error if it does not have taints within the given timeout.
434
- func WaitForNodeTaints (cs clientset.Interface , node * v1.Node , taints []v1.Taint ) error {
435
- return wait .Poll ( 100 * time .Millisecond , 30 * time .Second , NodeTainted (cs , node .Name , taints ))
434
+ func WaitForNodeTaints (ctx context. Context , cs clientset.Interface , node * v1.Node , taints []v1.Taint ) error {
435
+ return wait .PollUntilContextTimeout ( ctx , 100 * time .Millisecond , 30 * time .Second , false , NodeTainted (ctx , cs , node .Name , taints ))
436
436
}
437
437
438
438
// NodeTainted return a condition function that returns true if the given node contains
439
439
// the taints.
440
- func NodeTainted (cs clientset.Interface , nodeName string , taints []v1.Taint ) wait.ConditionFunc {
441
- return func () (bool , error ) {
442
- node , err := cs .CoreV1 ().Nodes ().Get (context . TODO () , nodeName , metav1.GetOptions {})
440
+ func NodeTainted (ctx context. Context , cs clientset.Interface , nodeName string , taints []v1.Taint ) wait.ConditionWithContextFunc {
441
+ return func (context. Context ) (bool , error ) {
442
+ node , err := cs .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
443
443
if err != nil {
444
444
return false , err
445
445
}
@@ -553,14 +553,14 @@ func InitTestAPIServer(t *testing.T, nsPrefix string, admission admission.Interf
553
553
}
554
554
555
555
// WaitForSchedulerCacheCleanup waits for cleanup of scheduler's cache to complete
556
- func WaitForSchedulerCacheCleanup (sched * scheduler.Scheduler , t * testing.T ) {
557
- schedulerCacheIsEmpty := func () (bool , error ) {
556
+ func WaitForSchedulerCacheCleanup (ctx context. Context , sched * scheduler.Scheduler , t * testing.T ) {
557
+ schedulerCacheIsEmpty := func (context. Context ) (bool , error ) {
558
558
dump := sched .Cache .Dump ()
559
559
560
560
return len (dump .Nodes ) == 0 && len (dump .AssumedPods ) == 0 , nil
561
561
}
562
562
563
- if err := wait .Poll ( time .Second , wait .ForeverTestTimeout , schedulerCacheIsEmpty ); err != nil {
563
+ if err := wait .PollUntilContextTimeout ( ctx , time .Second , wait .ForeverTestTimeout , false , schedulerCacheIsEmpty ); err != nil {
564
564
t .Errorf ("Failed to wait for scheduler cache cleanup: %v" , err )
565
565
}
566
566
}
@@ -726,10 +726,10 @@ func InitTestDisablePreemption(t *testing.T, nsPrefix string) *TestContext {
726
726
727
727
// WaitForReflection waits till the passFunc confirms that the object it expects
728
728
// to see is in the store. Used to observe reflected events.
729
- func WaitForReflection (t * testing.T , nodeLister corelisters.NodeLister , key string ,
729
+ func WaitForReflection (ctx context. Context , t * testing.T , nodeLister corelisters.NodeLister , key string ,
730
730
passFunc func (n interface {}) bool ) error {
731
731
var nodes []* v1.Node
732
- err := wait .Poll ( time .Millisecond * 100 , wait .ForeverTestTimeout , func () (bool , error ) {
732
+ err := wait .PollUntilContextTimeout ( ctx , time .Millisecond * 100 , wait .ForeverTestTimeout , false , func (context. Context ) (bool , error ) {
733
733
n , err := nodeLister .Get (key )
734
734
735
735
switch {
@@ -783,13 +783,13 @@ func CreateAndWaitForNodesInCache(testCtx *TestContext, prefix string, wrapper *
783
783
if err != nil {
784
784
return nodes , fmt .Errorf ("cannot create nodes: %v" , err )
785
785
}
786
- return nodes , WaitForNodesInCache (testCtx .Scheduler , numNodes + existingNodes )
786
+ return nodes , WaitForNodesInCache (testCtx .Ctx , testCtx . Scheduler , numNodes + existingNodes )
787
787
}
788
788
789
789
// WaitForNodesInCache ensures at least <nodeCount> nodes are present in scheduler cache
790
790
// within 30 seconds; otherwise returns false.
791
- func WaitForNodesInCache (sched * scheduler.Scheduler , nodeCount int ) error {
792
- err := wait .Poll ( 100 * time .Millisecond , wait .ForeverTestTimeout , func () (bool , error ) {
791
+ func WaitForNodesInCache (ctx context. Context , sched * scheduler.Scheduler , nodeCount int ) error {
792
+ err := wait .PollUntilContextTimeout ( ctx , 100 * time .Millisecond , wait .ForeverTestTimeout , false , func (context. Context ) (bool , error ) {
793
793
return sched .Cache .NodeCount () >= nodeCount , nil
794
794
})
795
795
if err != nil {
@@ -1018,9 +1018,9 @@ func PodSchedulingError(c clientset.Interface, podNamespace, podName string) wai
1018
1018
1019
1019
// PodSchedulingGated returns a condition function that returns true if the given pod
1020
1020
// gets unschedulable status of reason 'SchedulingGated'.
1021
- func PodSchedulingGated (c clientset.Interface , podNamespace , podName string ) wait.ConditionFunc {
1022
- return func () (bool , error ) {
1023
- pod , err := c .CoreV1 ().Pods (podNamespace ).Get (context . TODO () , podName , metav1.GetOptions {})
1021
+ func PodSchedulingGated (ctx context. Context , c clientset.Interface , podNamespace , podName string ) wait.ConditionWithContextFunc {
1022
+ return func (context. Context ) (bool , error ) {
1023
+ pod , err := c .CoreV1 ().Pods (podNamespace ).Get (ctx , podName , metav1.GetOptions {})
1024
1024
if err != nil {
1025
1025
// This could be a connection error so we want to retry.
1026
1026
return false , nil
@@ -1033,27 +1033,27 @@ func PodSchedulingGated(c clientset.Interface, podNamespace, podName string) wai
1033
1033
1034
1034
// WaitForPodUnschedulableWithTimeout waits for a pod to fail scheduling and returns
1035
1035
// an error if it does not become unschedulable within the given timeout.
1036
- func WaitForPodUnschedulableWithTimeout (cs clientset.Interface , pod * v1.Pod , timeout time.Duration ) error {
1037
- return wait .PollUntilContextTimeout (context . TODO () , 100 * time .Millisecond , timeout , false , PodUnschedulable (cs , pod .Namespace , pod .Name ))
1036
+ func WaitForPodUnschedulableWithTimeout (ctx context. Context , cs clientset.Interface , pod * v1.Pod , timeout time.Duration ) error {
1037
+ return wait .PollUntilContextTimeout (ctx , 100 * time .Millisecond , timeout , false , PodUnschedulable (cs , pod .Namespace , pod .Name ))
1038
1038
}
1039
1039
1040
1040
// WaitForPodUnschedulable waits for a pod to fail scheduling and returns
1041
1041
// an error if it does not become unschedulable within the timeout duration (30 seconds).
1042
- func WaitForPodUnschedulable (cs clientset.Interface , pod * v1.Pod ) error {
1043
- return WaitForPodUnschedulableWithTimeout (cs , pod , 30 * time .Second )
1042
+ func WaitForPodUnschedulable (ctx context. Context , cs clientset.Interface , pod * v1.Pod ) error {
1043
+ return WaitForPodUnschedulableWithTimeout (ctx , cs , pod , 30 * time .Second )
1044
1044
}
1045
1045
1046
1046
// WaitForPodSchedulingGated waits for a pod to be in scheduling gated state
1047
1047
// and returns an error if it does not fall into this state within the given timeout.
1048
- func WaitForPodSchedulingGated (cs clientset.Interface , pod * v1.Pod , timeout time.Duration ) error {
1049
- return wait .Poll ( 100 * time .Millisecond , timeout , PodSchedulingGated (cs , pod .Namespace , pod .Name ))
1048
+ func WaitForPodSchedulingGated (ctx context. Context , cs clientset.Interface , pod * v1.Pod , timeout time.Duration ) error {
1049
+ return wait .PollUntilContextTimeout ( ctx , 100 * time .Millisecond , timeout , false , PodSchedulingGated (ctx , cs , pod .Namespace , pod .Name ))
1050
1050
}
1051
1051
1052
1052
// WaitForPDBsStable waits for PDBs to have "CurrentHealthy" status equal to
1053
1053
// the expected values.
1054
1054
func WaitForPDBsStable (testCtx * TestContext , pdbs []* policy.PodDisruptionBudget , pdbPodNum []int32 ) error {
1055
- return wait .Poll ( time .Second , 60 * time .Second , func () (bool , error ) {
1056
- pdbList , err := testCtx .ClientSet .PolicyV1 ().PodDisruptionBudgets (testCtx .NS .Name ).List (context . TODO () , metav1.ListOptions {})
1055
+ return wait .PollUntilContextTimeout ( testCtx . Ctx , time .Second , 60 * time .Second , false , func (context. Context ) (bool , error ) {
1056
+ pdbList , err := testCtx .ClientSet .PolicyV1 ().PodDisruptionBudgets (testCtx .NS .Name ).List (testCtx . Ctx , metav1.ListOptions {})
1057
1057
if err != nil {
1058
1058
return false , err
1059
1059
}
@@ -1080,7 +1080,7 @@ func WaitForPDBsStable(testCtx *TestContext, pdbs []*policy.PodDisruptionBudget,
1080
1080
1081
1081
// WaitCachedPodsStable waits until scheduler cache has the given pods.
1082
1082
func WaitCachedPodsStable (testCtx * TestContext , pods []* v1.Pod ) error {
1083
- return wait .Poll ( time .Second , 30 * time .Second , func () (bool , error ) {
1083
+ return wait .PollUntilContextTimeout ( testCtx . Ctx , time .Second , 30 * time .Second , false , func (context. Context ) (bool , error ) {
1084
1084
cachedPods , err := testCtx .Scheduler .Cache .PodCount ()
1085
1085
if err != nil {
1086
1086
return false , err
@@ -1089,7 +1089,7 @@ func WaitCachedPodsStable(testCtx *TestContext, pods []*v1.Pod) error {
1089
1089
return false , nil
1090
1090
}
1091
1091
for _ , p := range pods {
1092
- actualPod , err1 := testCtx .ClientSet .CoreV1 ().Pods (p .Namespace ).Get (context . TODO () , p .Name , metav1.GetOptions {})
1092
+ actualPod , err1 := testCtx .ClientSet .CoreV1 ().Pods (p .Namespace ).Get (testCtx . Ctx , p .Name , metav1.GetOptions {})
1093
1093
if err1 != nil {
1094
1094
return false , err1
1095
1095
}
0 commit comments