mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Wait for only enough no. of RC replicas to be running in testutil
This commit is contained in:
parent
ebae09e741
commit
e5dc6c88eb
@ -2811,7 +2811,11 @@ func WaitForControlledPodsRunning(c clientset.Interface, ns, name string, kind s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = testutils.WaitForPodsWithLabelRunning(c, ns, selector)
|
replicas, err := getReplicasFromRuntimeObject(rtObject)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = testutils.WaitForEnoughPodsWithLabelRunning(c, ns, selector, int(replicas))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error while waiting for replication controller %s pods to be running: %v", name, err)
|
return fmt.Errorf("Error while waiting for replication controller %s pods to be running: %v", name, err)
|
||||||
}
|
}
|
||||||
|
@ -828,20 +828,29 @@ func StartPods(c clientset.Interface, replicas int, namespace string, podNamePre
|
|||||||
// Wait up to 10 minutes for all matching pods to become Running and at least one
|
// Wait up to 10 minutes for all matching pods to become Running and at least one
|
||||||
// matching pod exists.
|
// matching pod exists.
|
||||||
func WaitForPodsWithLabelRunning(c clientset.Interface, ns string, label labels.Selector) error {
|
func WaitForPodsWithLabelRunning(c clientset.Interface, ns string, label labels.Selector) error {
|
||||||
|
return WaitForEnoughPodsWithLabelRunning(c, ns, label, -1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait up to 10 minutes for at least 'replicas' many pods to be Running and at least
|
||||||
|
// one matching pod exists. If 'replicas' is < 0, wait for all matching pods running.
|
||||||
|
func WaitForEnoughPodsWithLabelRunning(c clientset.Interface, ns string, label labels.Selector, replicas int) error {
|
||||||
running := false
|
running := false
|
||||||
PodStore := NewPodStore(c, ns, label, fields.Everything())
|
PodStore := NewPodStore(c, ns, label, fields.Everything())
|
||||||
defer PodStore.Stop()
|
defer PodStore.Stop()
|
||||||
waitLoop:
|
|
||||||
for start := time.Now(); time.Since(start) < 10*time.Minute; time.Sleep(5 * time.Second) {
|
for start := time.Now(); time.Since(start) < 10*time.Minute; time.Sleep(5 * time.Second) {
|
||||||
pods := PodStore.List()
|
pods := PodStore.List()
|
||||||
if len(pods) == 0 {
|
if len(pods) == 0 {
|
||||||
continue waitLoop
|
continue
|
||||||
}
|
}
|
||||||
|
runningPodsCount := 0
|
||||||
for _, p := range pods {
|
for _, p := range pods {
|
||||||
if p.Status.Phase != v1.PodRunning {
|
if p.Status.Phase == v1.PodRunning {
|
||||||
continue waitLoop
|
runningPodsCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (replicas < 0 && runningPodsCount < len(pods)) || (runningPodsCount < replicas) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
running = true
|
running = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user