Remove most of the time.Sleep from the e2e tests
This commit is contained in:
parent
c3ff76ae50
commit
62a80a39ad
30 changed files with 628 additions and 465 deletions
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package framework
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
|
|
@ -26,6 +27,7 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||
)
|
||||
|
||||
// EnsureSecret creates a Secret object or returns it if it already exists.
|
||||
|
|
@ -45,10 +47,19 @@ func (f *Framework) EnsureIngress(ingress *extensions.Ingress) (*extensions.Ingr
|
|||
s, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Update(ingress)
|
||||
if err != nil {
|
||||
if k8sErrors.IsNotFound(err) {
|
||||
return f.KubeClientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(ingress)
|
||||
s, err = f.KubeClientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(ingress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if s.Annotations == nil {
|
||||
s.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
|
@ -76,14 +87,9 @@ func (f *Framework) EnsureDeployment(deployment *extensions.Deployment) (*extens
|
|||
return d, nil
|
||||
}
|
||||
|
||||
// WaitForPodsReady waits for a given amount of time until a group of Pods is running in the framework's namespace.
|
||||
func (f *Framework) WaitForPodsReady(timeout time.Duration, expectedReplicas int, opts metav1.ListOptions) error {
|
||||
return WaitForPodsReady(f.KubeClientSet, timeout, expectedReplicas, f.Namespace.Name, opts)
|
||||
}
|
||||
|
||||
// WaitForPodsReady waits for a given amount of time until a group of Pods is running in the given namespace.
|
||||
func WaitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration, expectedReplicas int, namespace string, opts metav1.ListOptions) error {
|
||||
return wait.Poll(time.Second, timeout, func() (bool, error) {
|
||||
return wait.Poll(2*time.Second, timeout, func() (bool, error) {
|
||||
pl, err := kubeClientSet.CoreV1().Pods(namespace).List(opts)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
@ -91,10 +97,9 @@ func WaitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration,
|
|||
|
||||
r := 0
|
||||
for _, p := range pl.Items {
|
||||
if p.Status.Phase != core.PodRunning {
|
||||
continue
|
||||
if isRunning, _ := podRunningReady(&p); isRunning {
|
||||
r++
|
||||
}
|
||||
r++
|
||||
}
|
||||
|
||||
if r == expectedReplicas {
|
||||
|
|
@ -104,3 +109,19 @@ func WaitForPodsReady(kubeClientSet kubernetes.Interface, timeout time.Duration,
|
|||
return false, nil
|
||||
})
|
||||
}
|
||||
|
||||
// podRunningReady checks whether pod p's phase is running and it has a ready
|
||||
// condition of status true.
|
||||
func podRunningReady(p *core.Pod) (bool, error) {
|
||||
// Check the phase is running.
|
||||
if p.Status.Phase != core.PodRunning {
|
||||
return false, fmt.Errorf("want pod '%s' on '%s' to be '%v' but was '%v'",
|
||||
p.ObjectMeta.Name, p.Spec.NodeName, core.PodRunning, p.Status.Phase)
|
||||
}
|
||||
// Check the ready condition is true.
|
||||
if !podutil.IsPodReady(p) {
|
||||
return false, fmt.Errorf("pod '%s' on '%s' didn't have condition {%v %v}; conditions: %v",
|
||||
p.ObjectMeta.Name, p.Spec.NodeName, core.PodReady, core.ConditionTrue, p.Status.Conditions)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue