Allow Density to run on non-GCE/GKE provider, rename deleteTestingNS
function.
This commit is contained in:
		@@ -20,7 +20,6 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"math"
 | 
						"math"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"os/exec"
 | 
					 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
@@ -30,7 +29,7 @@ import (
 | 
				
			|||||||
	"k8s.io/kubernetes/pkg/api/unversioned"
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/client/cache"
 | 
						"k8s.io/kubernetes/pkg/client/cache"
 | 
				
			||||||
	client "k8s.io/kubernetes/pkg/client/unversioned"
 | 
						client "k8s.io/kubernetes/pkg/client/unversioned"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/controller/framework"
 | 
						controllerFramework "k8s.io/kubernetes/pkg/controller/framework"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/fields"
 | 
						"k8s.io/kubernetes/pkg/fields"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/labels"
 | 
						"k8s.io/kubernetes/pkg/labels"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/runtime"
 | 
						"k8s.io/kubernetes/pkg/runtime"
 | 
				
			||||||
@@ -72,20 +71,6 @@ func printLatencies(latencies []podLatencyData, header string) {
 | 
				
			|||||||
	Logf("perc50: %v, perc90: %v, perc99: %v", perc50, perc90, perc99)
 | 
						Logf("perc50: %v, perc90: %v, perc99: %v", perc50, perc90, perc99)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// List nodes via gcloud. We don't rely on the apiserver because we really want the node ips
 | 
					 | 
				
			||||||
// and sometimes the node controller is slow to populate them.
 | 
					 | 
				
			||||||
func gcloudListNodes() {
 | 
					 | 
				
			||||||
	Logf("Listing nodes via gcloud:")
 | 
					 | 
				
			||||||
	output, err := exec.Command("gcloud", "compute", "instances", "list",
 | 
					 | 
				
			||||||
		"--project="+testContext.CloudConfig.ProjectID, "--zone="+testContext.CloudConfig.Zone).CombinedOutput()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		Logf("Failed to list nodes: %v", err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	Logf(string(output))
 | 
					 | 
				
			||||||
	return
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// This test suite can take a long time to run, so by default it is added to
 | 
					// This test suite can take a long time to run, so by default it is added to
 | 
				
			||||||
// the ginkgo.skip list (see driver.go).
 | 
					// the ginkgo.skip list (see driver.go).
 | 
				
			||||||
// To run this suite you must explicitly ask for it by setting the
 | 
					// To run this suite you must explicitly ask for it by setting the
 | 
				
			||||||
@@ -97,11 +82,14 @@ var _ = Describe("Density", func() {
 | 
				
			|||||||
	var additionalPodsPrefix string
 | 
						var additionalPodsPrefix string
 | 
				
			||||||
	var ns string
 | 
						var ns string
 | 
				
			||||||
	var uuid string
 | 
						var uuid string
 | 
				
			||||||
 | 
						framework := Framework{BaseName: "density"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BeforeEach(func() {
 | 
						BeforeEach(func() {
 | 
				
			||||||
 | 
							framework.beforeEach()
 | 
				
			||||||
 | 
							c = framework.Client
 | 
				
			||||||
 | 
							ns = framework.Namespace.Name
 | 
				
			||||||
		var err error
 | 
							var err error
 | 
				
			||||||
		c, err = loadClient()
 | 
					
 | 
				
			||||||
		expectNoError(err)
 | 
					 | 
				
			||||||
		nodes, err := c.Nodes().List(labels.Everything(), fields.Everything())
 | 
							nodes, err := c.Nodes().List(labels.Everything(), fields.Everything())
 | 
				
			||||||
		expectNoError(err)
 | 
							expectNoError(err)
 | 
				
			||||||
		nodeCount = len(nodes.Items)
 | 
							nodeCount = len(nodes.Items)
 | 
				
			||||||
@@ -110,25 +98,31 @@ var _ = Describe("Density", func() {
 | 
				
			|||||||
		// Terminating a namespace (deleting the remaining objects from it - which
 | 
							// Terminating a namespace (deleting the remaining objects from it - which
 | 
				
			||||||
		// generally means events) can affect the current run. Thus we wait for all
 | 
							// generally means events) can affect the current run. Thus we wait for all
 | 
				
			||||||
		// terminating namespace to be finally deleted before starting this test.
 | 
							// terminating namespace to be finally deleted before starting this test.
 | 
				
			||||||
		err = deleteTestingNS(c)
 | 
							err = checkTestingNSDeletedExcept(c, ns)
 | 
				
			||||||
		expectNoError(err)
 | 
							expectNoError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		nsForTesting, err := createTestingNS("density", c)
 | 
					 | 
				
			||||||
		ns = nsForTesting.Name
 | 
					 | 
				
			||||||
		expectNoError(err)
 | 
					 | 
				
			||||||
		uuid = string(util.NewUUID())
 | 
							uuid = string(util.NewUUID())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		expectNoError(resetMetrics(c))
 | 
							expectNoError(resetMetrics(c))
 | 
				
			||||||
		expectNoError(os.Mkdir(fmt.Sprintf(testContext.OutputDir+"/%s", uuid), 0777))
 | 
							expectNoError(os.Mkdir(fmt.Sprintf(testContext.OutputDir+"/%s", uuid), 0777))
 | 
				
			||||||
		expectNoError(writePerfData(c, fmt.Sprintf(testContext.OutputDir+"/%s", uuid), "before"))
 | 
							expectNoError(writePerfData(c, fmt.Sprintf(testContext.OutputDir+"/%s", uuid), "before"))
 | 
				
			||||||
		gcloudListNodes()
 | 
					
 | 
				
			||||||
 | 
							Logf("Listing nodes for easy debugging:\n")
 | 
				
			||||||
 | 
							for _, node := range nodes.Items {
 | 
				
			||||||
 | 
								for _, address := range node.Status.Addresses {
 | 
				
			||||||
 | 
									if address.Type == api.NodeInternalIP {
 | 
				
			||||||
 | 
										Logf("Name: %v IP: %v", node.ObjectMeta.Name, address.Address)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AfterEach(func() {
 | 
						AfterEach(func() {
 | 
				
			||||||
		// Remove any remaining pods from this test if the
 | 
							// Remove any remaining pods from this test if the
 | 
				
			||||||
		// replication controller still exists and the replica count
 | 
							// replication controller still exists and the replica count
 | 
				
			||||||
		// isn't 0.  This means the controller wasn't cleaned up
 | 
							// isn't 0.  This means the controller wasn't cleaned up
 | 
				
			||||||
		// during the test so clean it up here
 | 
							// during the test so clean it up here. We want to do it separately
 | 
				
			||||||
 | 
							// to not cause a timeout on Namespace removal.
 | 
				
			||||||
		rc, err := c.ReplicationControllers(ns).Get(RCName)
 | 
							rc, err := c.ReplicationControllers(ns).Get(RCName)
 | 
				
			||||||
		if err == nil && rc.Spec.Replicas != 0 {
 | 
							if err == nil && rc.Spec.Replicas != 0 {
 | 
				
			||||||
			By("Cleaning up the replication controller")
 | 
								By("Cleaning up the replication controller")
 | 
				
			||||||
@@ -142,17 +136,14 @@ var _ = Describe("Density", func() {
 | 
				
			|||||||
			c.Pods(ns).Delete(name, nil)
 | 
								c.Pods(ns).Delete(name, nil)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		By(fmt.Sprintf("Destroying namespace for this suite %v", ns))
 | 
					 | 
				
			||||||
		if err := c.Namespaces().Delete(ns); err != nil {
 | 
					 | 
				
			||||||
			Failf("Couldn't delete ns %s", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		expectNoError(writePerfData(c, fmt.Sprintf(testContext.OutputDir+"/%s", uuid), "after"))
 | 
							expectNoError(writePerfData(c, fmt.Sprintf(testContext.OutputDir+"/%s", uuid), "after"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Verify latency metrics
 | 
							// Verify latency metrics
 | 
				
			||||||
		highLatencyRequests, err := HighLatencyRequests(c, 3*time.Second, sets.NewString("events"))
 | 
							highLatencyRequests, err := HighLatencyRequests(c, 3*time.Second, sets.NewString("events"))
 | 
				
			||||||
		expectNoError(err)
 | 
							expectNoError(err)
 | 
				
			||||||
		Expect(highLatencyRequests).NotTo(BeNumerically(">", 0), "There should be no high-latency requests")
 | 
							Expect(highLatencyRequests).NotTo(BeNumerically(">", 0), "There should be no high-latency requests")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							framework.afterEach()
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Tests with "Skipped" substring in their name will be skipped when running
 | 
						// Tests with "Skipped" substring in their name will be skipped when running
 | 
				
			||||||
@@ -206,7 +197,7 @@ var _ = Describe("Density", func() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			// Create a listener for events.
 | 
								// Create a listener for events.
 | 
				
			||||||
			events := make([](*api.Event), 0)
 | 
								events := make([](*api.Event), 0)
 | 
				
			||||||
			_, controller := framework.NewInformer(
 | 
								_, controller := controllerFramework.NewInformer(
 | 
				
			||||||
				&cache.ListWatch{
 | 
									&cache.ListWatch{
 | 
				
			||||||
					ListFunc: func() (runtime.Object, error) {
 | 
										ListFunc: func() (runtime.Object, error) {
 | 
				
			||||||
						return c.Events(ns).List(labels.Everything(), fields.Everything())
 | 
											return c.Events(ns).List(labels.Everything(), fields.Everything())
 | 
				
			||||||
@@ -217,7 +208,7 @@ var _ = Describe("Density", func() {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
				&api.Event{},
 | 
									&api.Event{},
 | 
				
			||||||
				0,
 | 
									0,
 | 
				
			||||||
				framework.ResourceEventHandlerFuncs{
 | 
									controllerFramework.ResourceEventHandlerFuncs{
 | 
				
			||||||
					AddFunc: func(obj interface{}) {
 | 
										AddFunc: func(obj interface{}) {
 | 
				
			||||||
						events = append(events, obj.(*api.Event))
 | 
											events = append(events, obj.(*api.Event))
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
@@ -289,7 +280,7 @@ var _ = Describe("Density", func() {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				additionalPodsPrefix = "density-latency-pod-" + string(util.NewUUID())
 | 
									additionalPodsPrefix = "density-latency-pod-" + string(util.NewUUID())
 | 
				
			||||||
				_, controller := framework.NewInformer(
 | 
									_, controller := controllerFramework.NewInformer(
 | 
				
			||||||
					&cache.ListWatch{
 | 
										&cache.ListWatch{
 | 
				
			||||||
						ListFunc: func() (runtime.Object, error) {
 | 
											ListFunc: func() (runtime.Object, error) {
 | 
				
			||||||
							return c.Pods(ns).List(labels.SelectorFromSet(labels.Set{"name": additionalPodsPrefix}), fields.Everything())
 | 
												return c.Pods(ns).List(labels.SelectorFromSet(labels.Set{"name": additionalPodsPrefix}), fields.Everything())
 | 
				
			||||||
@@ -300,7 +291,7 @@ var _ = Describe("Density", func() {
 | 
				
			|||||||
					},
 | 
										},
 | 
				
			||||||
					&api.Pod{},
 | 
										&api.Pod{},
 | 
				
			||||||
					0,
 | 
										0,
 | 
				
			||||||
					framework.ResourceEventHandlerFuncs{
 | 
										controllerFramework.ResourceEventHandlerFuncs{
 | 
				
			||||||
						AddFunc: func(obj interface{}) {
 | 
											AddFunc: func(obj interface{}) {
 | 
				
			||||||
							p, ok := obj.(*api.Pod)
 | 
												p, ok := obj.(*api.Pod)
 | 
				
			||||||
							Expect(ok).To(Equal(true))
 | 
												Expect(ok).To(Equal(true))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,11 +53,12 @@ var _ = Describe("Load capacity", func() {
 | 
				
			|||||||
	var nodeCount int
 | 
						var nodeCount int
 | 
				
			||||||
	var ns string
 | 
						var ns string
 | 
				
			||||||
	var configs []*RCConfig
 | 
						var configs []*RCConfig
 | 
				
			||||||
 | 
						framework := Framework{BaseName: "density"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BeforeEach(func() {
 | 
						BeforeEach(func() {
 | 
				
			||||||
		var err error
 | 
							framework.beforeEach()
 | 
				
			||||||
		c, err = loadClient()
 | 
							c = framework.Client
 | 
				
			||||||
		expectNoError(err)
 | 
							ns = framework.Namespace.Name
 | 
				
			||||||
		nodes, err := c.Nodes().List(labels.Everything(), fields.Everything())
 | 
							nodes, err := c.Nodes().List(labels.Everything(), fields.Everything())
 | 
				
			||||||
		expectNoError(err)
 | 
							expectNoError(err)
 | 
				
			||||||
		nodeCount = len(nodes.Items)
 | 
							nodeCount = len(nodes.Items)
 | 
				
			||||||
@@ -66,11 +67,7 @@ var _ = Describe("Load capacity", func() {
 | 
				
			|||||||
		// Terminating a namespace (deleting the remaining objects from it - which
 | 
							// Terminating a namespace (deleting the remaining objects from it - which
 | 
				
			||||||
		// generally means events) can affect the current run. Thus we wait for all
 | 
							// generally means events) can affect the current run. Thus we wait for all
 | 
				
			||||||
		// terminating namespace to be finally deleted before starting this test.
 | 
							// terminating namespace to be finally deleted before starting this test.
 | 
				
			||||||
		err = deleteTestingNS(c)
 | 
							err = checkTestingNSDeletedExcept(c, ns)
 | 
				
			||||||
		expectNoError(err)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		nsForTesting, err := createTestingNS("load", c)
 | 
					 | 
				
			||||||
		ns = nsForTesting.Name
 | 
					 | 
				
			||||||
		expectNoError(err)
 | 
							expectNoError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		expectNoError(resetMetrics(c))
 | 
							expectNoError(resetMetrics(c))
 | 
				
			||||||
@@ -80,11 +77,7 @@ var _ = Describe("Load capacity", func() {
 | 
				
			|||||||
	AfterEach(func() {
 | 
						AfterEach(func() {
 | 
				
			||||||
		deleteAllRC(configs)
 | 
							deleteAllRC(configs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		By(fmt.Sprintf("Destroying namespace for this suite %v", ns))
 | 
							framework.afterEach()
 | 
				
			||||||
		if err := c.Namespaces().Delete(ns); err != nil {
 | 
					 | 
				
			||||||
			Failf("Couldn't delete ns %s", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Verify latency metrics
 | 
							// Verify latency metrics
 | 
				
			||||||
		highLatencyRequests, err := HighLatencyRequests(c, 3*time.Second, sets.NewString("events"))
 | 
							highLatencyRequests, err := HighLatencyRequests(c, 3*time.Second, sets.NewString("events"))
 | 
				
			||||||
		expectNoError(err, "Too many instances metrics above the threshold")
 | 
							expectNoError(err, "Too many instances metrics above the threshold")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -405,7 +405,7 @@ var _ = Describe("Nodes", func() {
 | 
				
			|||||||
		if err := deleteNS(c, ns); err != nil {
 | 
							if err := deleteNS(c, ns); err != nil {
 | 
				
			||||||
			Failf("Couldn't delete namespace '%s', %v", ns, err)
 | 
								Failf("Couldn't delete namespace '%s', %v", ns, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err := deleteTestingNS(c); err != nil {
 | 
							if err := checkTestingNSDeletedExcept(c, ""); err != nil {
 | 
				
			||||||
			Failf("Couldn't delete testing namespaces '%s', %v", ns, err)
 | 
								Failf("Couldn't delete testing namespaces '%s', %v", ns, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -153,7 +153,7 @@ var _ = Describe("SchedulerPredicates", func() {
 | 
				
			|||||||
		nodeCount = len(nodeList.Items)
 | 
							nodeCount = len(nodeList.Items)
 | 
				
			||||||
		Expect(nodeCount).NotTo(BeZero())
 | 
							Expect(nodeCount).NotTo(BeZero())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		err = deleteTestingNS(c)
 | 
							err = checkTestingNSDeletedExcept(c, "")
 | 
				
			||||||
		expectNoError(err)
 | 
							expectNoError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		nsForTesting, err := createTestingNS("sched-pred", c)
 | 
							nsForTesting, err := createTestingNS("sched-pred", c)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -490,9 +490,9 @@ func createTestingNS(baseName string, c *client.Client) (*api.Namespace, error)
 | 
				
			|||||||
	return got, nil
 | 
						return got, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// deleteTestingNS checks whether all e2e based existing namespaces are in the Terminating state
 | 
					// checkTestingNSDeletedExcept checks whether all e2e based existing namespaces are in the Terminating state
 | 
				
			||||||
// and waits until they are finally deleted.
 | 
					// and waits until they are finally deleted. It ignores namespace skip.
 | 
				
			||||||
func deleteTestingNS(c *client.Client) error {
 | 
					func checkTestingNSDeletedExcept(c *client.Client, skip string) error {
 | 
				
			||||||
	// TODO: Since we don't have support for bulk resource deletion in the API,
 | 
						// TODO: Since we don't have support for bulk resource deletion in the API,
 | 
				
			||||||
	// while deleting a namespace we are deleting all objects from that namespace
 | 
						// while deleting a namespace we are deleting all objects from that namespace
 | 
				
			||||||
	// one by one (one deletion == one API call). This basically exposes us to
 | 
						// one by one (one deletion == one API call). This basically exposes us to
 | 
				
			||||||
@@ -515,7 +515,7 @@ func deleteTestingNS(c *client.Client) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		terminating := 0
 | 
							terminating := 0
 | 
				
			||||||
		for _, ns := range namespaces.Items {
 | 
							for _, ns := range namespaces.Items {
 | 
				
			||||||
			if strings.HasPrefix(ns.ObjectMeta.Name, "e2e-tests-") {
 | 
								if strings.HasPrefix(ns.ObjectMeta.Name, "e2e-tests-") && ns.ObjectMeta.Name != skip {
 | 
				
			||||||
				if ns.Status.Phase == api.NamespaceActive {
 | 
									if ns.Status.Phase == api.NamespaceActive {
 | 
				
			||||||
					return fmt.Errorf("Namespace %s is active", ns.ObjectMeta.Name)
 | 
										return fmt.Errorf("Namespace %s is active", ns.ObjectMeta.Name)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user