mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
fix test failure and address comment
This commit is contained in:
parent
a12dc2e412
commit
3bb159e8f6
@ -3075,6 +3075,7 @@ func DeleteRCAndPods(c *client.Client, ns, name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ps.Stop()
|
||||
startTime := time.Now()
|
||||
err = reaper.Stop(ns, name, 0, api.NewDeleteOptions(0))
|
||||
if apierrs.IsNotFound(err) {
|
||||
@ -3116,6 +3117,7 @@ func DeleteRCAndWaitForGC(c *client.Client, ns, name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ps.Stop()
|
||||
startTime := time.Now()
|
||||
falseVar := false
|
||||
deleteOption := &api.DeleteOptions{OrphanDependents: &falseVar}
|
||||
@ -3161,7 +3163,6 @@ func podStoreForRC(c *client.Client, rc *api.ReplicationController) (*PodStore,
|
||||
// and DeleteRCAndWaitForGC, because the RC controller decreases status.replicas
|
||||
// when the pod is inactvie.
|
||||
func waitForPodsInactive(ps *PodStore, interval, timeout time.Duration) error {
|
||||
defer ps.Stop()
|
||||
return wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
pods := ps.List()
|
||||
for _, pod := range pods {
|
||||
@ -3175,7 +3176,6 @@ func waitForPodsInactive(ps *PodStore, interval, timeout time.Duration) error {
|
||||
|
||||
// waitForPodsGone waits until there are no pods left in the PodStore.
|
||||
func waitForPodsGone(ps *PodStore, interval, timeout time.Duration) error {
|
||||
defer ps.Stop()
|
||||
return wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
if pods := ps.List(); len(pods) == 0 {
|
||||
return true, nil
|
||||
@ -3184,25 +3184,6 @@ func waitForPodsGone(ps *PodStore, interval, timeout time.Duration) error {
|
||||
})
|
||||
}
|
||||
|
||||
// waitForRCPodsGone waits until there are no pods reported under an RC's selector (because the pods
|
||||
// have completed termination).
|
||||
func waitForRCPodsGone(c *client.Client, rc *api.ReplicationController, timeout *time.Duration) error {
|
||||
if timeout == nil {
|
||||
defaultTimeout := 2 * time.Minute
|
||||
timeout = &defaultTimeout
|
||||
}
|
||||
labels := labels.SelectorFromSet(rc.Spec.Selector)
|
||||
PodStore := NewPodStore(c, rc.Namespace, labels, fields.Everything())
|
||||
defer PodStore.Stop()
|
||||
|
||||
return wait.PollImmediate(Poll, *timeout, func() (bool, error) {
|
||||
if pods := PodStore.List(); len(pods) == 0 {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
})
|
||||
}
|
||||
|
||||
// Delete a ReplicaSet and all pods it spawned
|
||||
func DeleteReplicaSet(c *client.Client, ns, name string) error {
|
||||
By(fmt.Sprintf("deleting ReplicaSet %s in namespace %s", name, ns))
|
||||
@ -4346,9 +4327,14 @@ func ScaleRCByLabels(client *client.Client, ns string, l map[string]string, repl
|
||||
return err
|
||||
}
|
||||
if replicas == 0 {
|
||||
if err := waitForRCPodsGone(client, rc, nil); err != nil {
|
||||
ps, err := podStoreForRC(client, rc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ps.Stop()
|
||||
if err = waitForPodsGone(ps, 10*time.Second, 10*time.Minute); err != nil {
|
||||
return fmt.Errorf("error while waiting for pods gone %s: %v", name, err)
|
||||
}
|
||||
} else {
|
||||
if err := WaitForPodsWithLabelRunning(
|
||||
client, ns, labels.SelectorFromSet(labels.Set(rc.Spec.Selector))); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user