mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer ps.Stop()
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
err = reaper.Stop(ns, name, 0, api.NewDeleteOptions(0))
|
err = reaper.Stop(ns, name, 0, api.NewDeleteOptions(0))
|
||||||
if apierrs.IsNotFound(err) {
|
if apierrs.IsNotFound(err) {
|
||||||
@ -3116,6 +3117,7 @@ func DeleteRCAndWaitForGC(c *client.Client, ns, name string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer ps.Stop()
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
falseVar := false
|
falseVar := false
|
||||||
deleteOption := &api.DeleteOptions{OrphanDependents: &falseVar}
|
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
|
// and DeleteRCAndWaitForGC, because the RC controller decreases status.replicas
|
||||||
// when the pod is inactvie.
|
// when the pod is inactvie.
|
||||||
func waitForPodsInactive(ps *PodStore, interval, timeout time.Duration) error {
|
func waitForPodsInactive(ps *PodStore, interval, timeout time.Duration) error {
|
||||||
defer ps.Stop()
|
|
||||||
return wait.PollImmediate(interval, timeout, func() (bool, error) {
|
return wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||||
pods := ps.List()
|
pods := ps.List()
|
||||||
for _, pod := range pods {
|
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.
|
// waitForPodsGone waits until there are no pods left in the PodStore.
|
||||||
func waitForPodsGone(ps *PodStore, interval, timeout time.Duration) error {
|
func waitForPodsGone(ps *PodStore, interval, timeout time.Duration) error {
|
||||||
defer ps.Stop()
|
|
||||||
return wait.PollImmediate(interval, timeout, func() (bool, error) {
|
return wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||||
if pods := ps.List(); len(pods) == 0 {
|
if pods := ps.List(); len(pods) == 0 {
|
||||||
return true, nil
|
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
|
// Delete a ReplicaSet and all pods it spawned
|
||||||
func DeleteReplicaSet(c *client.Client, ns, name string) error {
|
func DeleteReplicaSet(c *client.Client, ns, name string) error {
|
||||||
By(fmt.Sprintf("deleting ReplicaSet %s in namespace %s", name, ns))
|
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
|
return err
|
||||||
}
|
}
|
||||||
if replicas == 0 {
|
if replicas == 0 {
|
||||||
if err := waitForRCPodsGone(client, rc, nil); err != nil {
|
ps, err := podStoreForRC(client, rc)
|
||||||
|
if err != nil {
|
||||||
return err
|
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 {
|
} else {
|
||||||
if err := WaitForPodsWithLabelRunning(
|
if err := WaitForPodsWithLabelRunning(
|
||||||
client, ns, labels.SelectorFromSet(labels.Set(rc.Spec.Selector))); err != nil {
|
client, ns, labels.SelectorFromSet(labels.Set(rc.Spec.Selector))); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user