From 96fc4114f40a79c4ab36b80e2774dcdfdf8e1840 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Wed, 23 Sep 2020 23:30:41 +0200 Subject: [PATCH] Use WaitForPodRunning instead of WaitForResourceReady on pods (#4093) * Use WaitForPodRunning instead of WaitForResourceReady on pods Signed-off-by: Pierangelo Di Pilato * Check if pod is running in isResourceReady Signed-off-by: Pierangelo Di Pilato * Revert "Use WaitForPodRunning instead of WaitForResourceReady on pods" This reverts commit 6d59fd271ea0267a97ce18f465b15395bd47ac0d. --- test/lib/duck/resource_checks.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/lib/duck/resource_checks.go b/test/lib/duck/resource_checks.go index 32a51cc56fd..43a8755b5b8 100644 --- a/test/lib/duck/resource_checks.go +++ b/test/lib/duck/resource_checks.go @@ -22,6 +22,7 @@ package duck import ( "time" + corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" @@ -60,7 +61,7 @@ func WaitForResourcesReady(dynamicClient dynamic.Interface, objList *resources.M }) } -// isResourceReady leverage duck-type to check if the given MetaResource is in ready state +// isResourceReady leverage duck-type to check if the given obj is in ready state func isResourceReady(obj runtime.Object, err error) (bool, error) { if k8serrors.IsNotFound(err) { // Return false as we are not done yet. @@ -72,7 +73,16 @@ func isResourceReady(obj runtime.Object, err error) (bool, error) { return false, err } + if pod, isPod := obj.(*corev1.Pod); isPod { + return isPodRunning(pod), nil + } + kr := obj.(*duckv1beta1.KResource) ready := kr.Status.GetCondition(apis.ConditionReady) return ready != nil && ready.IsTrue(), nil } + +// isPodRunning will check the status conditions of the pod and return true if it's Running or Succeeded. +func isPodRunning(pod *corev1.Pod) bool { + return pod.Status.Phase == corev1.PodRunning || pod.Status.Phase == corev1.PodSucceeded +}