mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
Poll for gc'd pods.
This commit is contained in:
parent
2e03822386
commit
543a0691f6
@ -17,13 +17,14 @@ limitations under the License.
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/wait"
|
||||
)
|
||||
|
||||
// This test requires that --terminated-pod-gc-threshold=100 be set on the controller manager
|
||||
@ -51,14 +52,30 @@ var _ = Describe("Garbage collector [Slow]", func() {
|
||||
}
|
||||
|
||||
Logf("created: %v", count)
|
||||
// This sleep has to be longer than the gcCheckPeriod defined
|
||||
// in pkg/controller/gc/gc_controller.go which is currently
|
||||
// 20 seconds.
|
||||
time.Sleep(30 * time.Second)
|
||||
|
||||
pods, err := f.Client.Pods(f.Namespace.Name).List(api.ListOptions{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(len(pods.Items)).To(BeNumerically("==", 100))
|
||||
// The gc controller polls every 30s and fires off a goroutine per
|
||||
// pod to terminate.
|
||||
var err error
|
||||
var pods *api.PodList
|
||||
timeout := 2 * time.Minute
|
||||
gcThreshold := 100
|
||||
|
||||
By(fmt.Sprintf("Waiting for gc controller to gc all but %d pods", gcThreshold))
|
||||
pollErr := wait.Poll(30*time.Second, timeout, func() (bool, error) {
|
||||
pods, err = f.Client.Pods(f.Namespace.Name).List(api.ListOptions{})
|
||||
if err != nil {
|
||||
Logf("Failed to list pod %v", err)
|
||||
return false, nil
|
||||
}
|
||||
if len(pods.Items) != gcThreshold {
|
||||
Logf("Number of observed pods %v, waiting for %v", len(pods.Items), gcThreshold)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
if pollErr != nil {
|
||||
Failf("Failed to GC pods within %v, %v pods remaining, error: %v", timeout, len(pods.Items), err)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user