mirror of https://github.com/k3s-io/k3s
Wait for terminating namespaces deletion
parent
4a6e7b5053
commit
47b6e6a84e
|
@ -86,6 +86,13 @@ var _ = Describe("Density", func() {
|
|||
expectNoError(err)
|
||||
minionCount = len(minions.Items)
|
||||
Expect(minionCount).NotTo(BeZero())
|
||||
|
||||
// Terminating a namespace (deleting the remaining objects from it - which
|
||||
// generally means events) can affect the current run. Thus we wait for all
|
||||
// terminating namespace to be finally deleted before starting this test.
|
||||
err = deleteTestingNS(c)
|
||||
expectNoError(err)
|
||||
|
||||
nsForTesting, err := createTestingNS("density", c)
|
||||
ns = nsForTesting.Name
|
||||
expectNoError(err)
|
||||
|
|
|
@ -63,6 +63,13 @@ var _ = Describe("Load capacity", func() {
|
|||
expectNoError(err)
|
||||
nodeCount = len(nodes.Items)
|
||||
Expect(nodeCount).NotTo(BeZero())
|
||||
|
||||
// Terminating a namespace (deleting the remaining objects from it - which
|
||||
// generally means events) can affect the current run. Thus we wait for all
|
||||
// terminating namespace to be finally deleted before starting this test.
|
||||
err = deleteTestingNS(c)
|
||||
expectNoError(err)
|
||||
|
||||
nsForTesting, err := createTestingNS("load", c)
|
||||
ns = nsForTesting.Name
|
||||
expectNoError(err)
|
||||
|
|
|
@ -376,6 +376,32 @@ func createTestingNS(baseName string, c *client.Client) (*api.Namespace, error)
|
|||
return got, nil
|
||||
}
|
||||
|
||||
// deleteTestingNS checks whether all e2e based existing namespaces are in the Terminating state
|
||||
// and waits until they are finally deleted.
|
||||
func deleteTestingNS(c *client.Client) error {
|
||||
Logf("Waiting for terminating namespaces to be deleted...")
|
||||
for start := time.Now(); time.Since(start) < 30*time.Minute; time.Sleep(15 * time.Second) {
|
||||
namespaces, err := c.Namespaces().List(labels.Everything(), fields.Everything())
|
||||
if err != nil {
|
||||
Logf("Listing namespaces failed: %v", err)
|
||||
continue
|
||||
}
|
||||
terminating := 0
|
||||
for _, ns := range namespaces.Items {
|
||||
if strings.HasPrefix(ns.ObjectMeta.Name, "e2e-tests-") {
|
||||
if ns.Status.Phase == api.NamespaceActive {
|
||||
return fmt.Errorf("Namespace %s is active", ns)
|
||||
}
|
||||
terminating++
|
||||
}
|
||||
}
|
||||
if terminating == 0 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("Waiting for terminating namespaces to be deleted timed out")
|
||||
}
|
||||
|
||||
func waitForPodRunningInNamespace(c *client.Client, podName string, namespace string) error {
|
||||
return waitForPodCondition(c, namespace, podName, "running", podStartTimeout, func(pod *api.Pod) (bool, error) {
|
||||
if pod.Status.Phase == api.PodRunning {
|
||||
|
|
Loading…
Reference in New Issue