mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07: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 {
|
||||
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 {
|
||||
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
|
||||
// matching pod exists.
|
||||
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
|
||||
PodStore := NewPodStore(c, ns, label, fields.Everything())
|
||||
defer PodStore.Stop()
|
||||
waitLoop:
|
||||
for start := time.Now(); time.Since(start) < 10*time.Minute; time.Sleep(5 * time.Second) {
|
||||
pods := PodStore.List()
|
||||
if len(pods) == 0 {
|
||||
continue waitLoop
|
||||
continue
|
||||
}
|
||||
runningPodsCount := 0
|
||||
for _, p := range pods {
|
||||
if p.Status.Phase != v1.PodRunning {
|
||||
continue waitLoop
|
||||
if p.Status.Phase == v1.PodRunning {
|
||||
runningPodsCount++
|
||||
}
|
||||
}
|
||||
if (replicas < 0 && runningPodsCount < len(pods)) || (runningPodsCount < replicas) {
|
||||
continue
|
||||
}
|
||||
running = true
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user