Move "extra" namespaces into framework

Now an aborted test will delete namespaces.  Hopefully this means less GCE
leaks.
pull/6/head
Tim Hockin 2016-02-05 21:38:52 -08:00
parent 677d4d6dbc
commit ff3f9f6bcc
4 changed files with 33 additions and 47 deletions

View File

@ -75,15 +75,8 @@ var _ = Describe("ClusterDns [Feature:Example]", func() {
namespaces := []*api.Namespace{nil, nil}
for i := range namespaces {
var err error
namespaces[i], err = createTestingNS(fmt.Sprintf("dnsexample%d", i), c, nil)
if testContext.DeleteNamespace {
if namespaces[i] != nil {
defer deleteNS(c, namespaces[i].Name, 5*time.Minute /* namespace deletion timeout */)
}
Expect(err).NotTo(HaveOccurred())
} else {
Logf("Found DeleteNamespace=false, skipping namespace deletion!")
}
namespaces[i], err = framework.CreateNamespace(fmt.Sprintf("dnsexample%d", i), nil)
Expect(err).NotTo(HaveOccurred())
}
for _, ns := range namespaces {

View File

@ -43,9 +43,11 @@ const (
type Framework struct {
BaseName string
Namespace *api.Namespace
Client *client.Client
Clientset_1_2 *release_1_2.Clientset
Client *client.Client
Clientset_1_2 *release_1_2.Clientset
Namespace *api.Namespace // Every test has at least one namespace
namespacesToDelete []*api.Namespace // Some tests have more than one.
NamespaceDeletionTimeout time.Duration
gatherer containerResourceGatherer
@ -97,7 +99,7 @@ func (f *Framework) beforeEach() {
f.Clientset_1_2 = release_1_2.FromUnversionedClient(c)
By("Building a namespace api object")
namespace, err := createTestingNS(f.BaseName, f.Client, map[string]string{
namespace, err := f.CreateNamespace(f.BaseName, map[string]string{
"e2e-framework": f.BaseName,
})
Expect(err).NotTo(HaveOccurred())
@ -177,15 +179,18 @@ func (f *Framework) afterEach() {
}
if testContext.DeleteNamespace {
By(fmt.Sprintf("Destroying namespace %q for this suite.", f.Namespace.Name))
for _, ns := range f.namespacesToDelete {
By(fmt.Sprintf("Destroying namespace %q for this suite.", ns.Name))
timeout := 5 * time.Minute
if f.NamespaceDeletionTimeout != 0 {
timeout = f.NamespaceDeletionTimeout
}
if err := deleteNS(f.Client, f.Namespace.Name, timeout); err != nil {
Failf("Couldn't delete ns %q: %s", f.Namespace.Name, err)
timeout := 5 * time.Minute
if f.NamespaceDeletionTimeout != 0 {
timeout = f.NamespaceDeletionTimeout
}
if err := deleteNS(f.Client, ns.Name, timeout); err != nil {
Failf("Couldn't delete ns %q: %s", ns.Name, err)
}
}
f.namespacesToDelete = nil
} else {
Logf("Found DeleteNamespace=false, skipping namespace deletion!")
}
@ -220,6 +225,14 @@ func (f *Framework) afterEach() {
f.Client = nil
}
func (f *Framework) CreateNamespace(baseName string, labels map[string]string) (*api.Namespace, error) {
ns, err := createTestingNS(baseName, f.Client, labels)
if err == nil {
f.namespacesToDelete = append(f.namespacesToDelete, ns)
}
return ns, err
}
// WaitForPodTerminated waits for the pod to be terminated with the given reason.
func (f *Framework) WaitForPodTerminated(podName, reason string) error {
return waitForPodTerminatedInNamespace(f.Client, podName, reason, f.Namespace.Name)

View File

@ -23,14 +23,13 @@ import (
"time"
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util/wait"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func extinguish(c *client.Client, totalNS int, maxAllowedAfterDel int, maxSeconds int) {
func extinguish(f *Framework, totalNS int, maxAllowedAfterDel int, maxSeconds int) {
var err error
By("Creating testing namespaces")
@ -40,7 +39,7 @@ func extinguish(c *client.Client, totalNS int, maxAllowedAfterDel int, maxSecond
go func(n int) {
defer wg.Done()
defer GinkgoRecover()
_, err = createTestingNS(fmt.Sprintf("nslifetest-%v", n), c, nil)
_, err = f.CreateNamespace(fmt.Sprintf("nslifetest-%v", n), nil)
Expect(err).NotTo(HaveOccurred())
}(n)
}
@ -49,7 +48,7 @@ func extinguish(c *client.Client, totalNS int, maxAllowedAfterDel int, maxSecond
//Wait 10 seconds, then SEND delete requests for all the namespaces.
By("Waiting 10 seconds")
time.Sleep(time.Duration(10 * time.Second))
deleted, err := deleteNamespaces(c, []string{"nslifetest"}, nil /* skipFilter */)
deleted, err := deleteNamespaces(f.Client, []string{"nslifetest"}, nil /* skipFilter */)
Expect(err).NotTo(HaveOccurred())
Expect(len(deleted)).To(Equal(totalNS))
@ -58,7 +57,7 @@ func extinguish(c *client.Client, totalNS int, maxAllowedAfterDel int, maxSecond
expectNoError(wait.Poll(2*time.Second, time.Duration(maxSeconds)*time.Second,
func() (bool, error) {
var cnt = 0
nsList, err := c.Namespaces().List(api.ListOptions{})
nsList, err := f.Client.Namespaces().List(api.ListOptions{})
if err != nil {
return false, err
}
@ -108,9 +107,9 @@ var _ = Describe("Namespaces [Serial]", func() {
f := NewFramework("namespaces")
It("should delete fast enough (90 percent of 100 namespaces in 150 seconds)",
func() { extinguish(f.Client, 100, 10, 150) })
func() { extinguish(f, 100, 10, 150) })
// On hold until etcd3; see #7372
It("should always delete fast (ALL of 100 namespaces in 150 seconds) [Feature:ComprehensiveNamespaceDraining]",
func() { extinguish(f.Client, 100, 0, 150) })
func() { extinguish(f, 100, 0, 150) })
})

View File

@ -54,9 +54,6 @@ const loadBalancerLagTimeout = 2 * time.Minute
//TODO: once support ticket 21807001 is resolved, reduce this timeout back to something reasonable
const loadBalancerCreateTimeout = 20 * time.Minute
// How long to wait for a namespace to be deleted.
const namespaceDeleteTimeout = 5 * time.Minute
// This should match whatever the default/configured range is
var ServiceNodePortRange = utilnet.PortRange{Base: 30000, Size: 2768}
@ -64,7 +61,6 @@ var _ = Describe("Services", func() {
f := NewFramework("services")
var c *client.Client
var extraNamespaces []string
BeforeEach(func() {
var err error
@ -72,20 +68,6 @@ var _ = Describe("Services", func() {
Expect(err).NotTo(HaveOccurred())
})
AfterEach(func() {
if testContext.DeleteNamespace {
for _, ns := range extraNamespaces {
By(fmt.Sprintf("Destroying namespace %v", ns))
if err := deleteNS(c, ns, namespaceDeleteTimeout); err != nil {
Failf("Couldn't delete namespace %s: %s", ns, err)
}
}
extraNamespaces = nil
} else {
Logf("Found DeleteNamespace=false, skipping namespace deletion!")
}
})
// TODO: We get coverage of TCP/UDP and multi-port services through the DNS test. We should have a simpler test for multi-port TCP here.
It("should provide secure master service [Conformance]", func() {
@ -429,11 +411,10 @@ var _ = Describe("Services", func() {
Logf("namespace for TCP test: %s", ns1)
By("creating a second namespace")
namespacePtr, err := createTestingNS("services", c, nil)
namespacePtr, err := f.CreateNamespace("services", nil)
Expect(err).NotTo(HaveOccurred())
ns2 := namespacePtr.Name // LB2 in ns2 on UDP
Logf("namespace for UDP test: %s", ns2)
extraNamespaces = append(extraNamespaces, ns2)
jig := NewServiceTestJig(c, serviceName)
nodeIP := pickNodeIP(jig.Client) // for later