Update waitForDelete to use PollUntilContextTimeout
Signed-off-by: Omer Aplatony <omerap12@gmail.com> Kubernetes-commit: bba055067e6283f94ee05cedeb33dacafe4a1094
This commit is contained in:
parent
3aac470db0
commit
c329ccff7c
|
@ -413,7 +413,10 @@ func (d *Helper) deletePods(pods []corev1.Pod, getPodFn func(namespace, name str
|
||||||
|
|
||||||
func waitForDelete(params waitForDeleteParams) ([]corev1.Pod, error) {
|
func waitForDelete(params waitForDeleteParams) ([]corev1.Pod, error) {
|
||||||
pods := params.pods
|
pods := params.pods
|
||||||
err := wait.PollImmediate(params.interval, params.timeout, func() (bool, error) {
|
if params.ctx == nil {
|
||||||
|
params.ctx = context.Background()
|
||||||
|
}
|
||||||
|
err := wait.PollUntilContextTimeout(params.ctx, params.interval, params.timeout, true, func(ctx context.Context) (done bool, err error) {
|
||||||
pendingPods := []corev1.Pod{}
|
pendingPods := []corev1.Pod{}
|
||||||
for i, pod := range pods {
|
for i, pod := range pods {
|
||||||
p, err := params.getPodFn(pod.Namespace, pod.Name)
|
p, err := params.getPodFn(pod.Namespace, pod.Name)
|
||||||
|
@ -440,15 +443,7 @@ func waitForDelete(params waitForDeleteParams) ([]corev1.Pod, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pods = pendingPods
|
pods = pendingPods
|
||||||
if len(pendingPods) > 0 {
|
return len(pods) == 0, nil
|
||||||
select {
|
|
||||||
case <-params.ctx.Done():
|
|
||||||
return false, fmt.Errorf("global timeout reached: %v", params.globalTimeout)
|
|
||||||
default:
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
})
|
})
|
||||||
return pods, err
|
return pods, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
"k8s.io/client-go/kubernetes/fake"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
ktest "k8s.io/client-go/testing"
|
ktest "k8s.io/client-go/testing"
|
||||||
)
|
)
|
||||||
|
@ -101,7 +100,7 @@ func TestDeletePods(t *testing.T) {
|
||||||
timeout: 3 * time.Second,
|
timeout: 3 * time.Second,
|
||||||
expectPendingPods: true,
|
expectPendingPods: true,
|
||||||
expectError: true,
|
expectError: true,
|
||||||
expectedError: &wait.ErrWaitTimeout,
|
expectedError: &context.DeadlineExceeded,
|
||||||
getPodFn: func(namespace, name string) (*corev1.Pod, error) {
|
getPodFn: func(namespace, name string) (*corev1.Pod, error) {
|
||||||
oldPodMap, _ := createPods(false)
|
oldPodMap, _ := createPods(false)
|
||||||
if oldPod, found := oldPodMap[name]; found {
|
if oldPod, found := oldPodMap[name]; found {
|
||||||
|
@ -117,7 +116,7 @@ func TestDeletePods(t *testing.T) {
|
||||||
ctxTimeoutEarly: true,
|
ctxTimeoutEarly: true,
|
||||||
expectPendingPods: true,
|
expectPendingPods: true,
|
||||||
expectError: true,
|
expectError: true,
|
||||||
expectedError: &wait.ErrWaitTimeout,
|
expectedError: &context.Canceled,
|
||||||
getPodFn: func(namespace, name string) (*corev1.Pod, error) {
|
getPodFn: func(namespace, name string) (*corev1.Pod, error) {
|
||||||
oldPodMap, _ := createPods(false)
|
oldPodMap, _ := createPods(false)
|
||||||
if oldPod, found := oldPodMap[name]; found {
|
if oldPod, found := oldPodMap[name]; found {
|
||||||
|
|
Loading…
Reference in New Issue