From ad7e3c30536ebed029cc8f638c94dcef28825610 Mon Sep 17 00:00:00 2001 From: Random-Liu Date: Thu, 14 Jul 2016 18:45:19 -0700 Subject: [PATCH] Start namespace controller in node e2e test. --- test/e2e/framework/test_context.go | 4 +--- test/e2e_node/e2e_node_suite_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 422d36382eb..20c69864a29 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -103,14 +103,12 @@ func RegisterCommonFlags() { flag.BoolVar(&TestContext.GatherMetricsAfterTest, "gather-metrics-at-teardown", false, "If set to true framwork will gather metrics from all components after each test.") flag.StringVar(&TestContext.OutputPrintType, "output-print-type", "hr", "Comma separated list: 'hr' for human readable summaries 'json' for JSON ones.") flag.BoolVar(&TestContext.DumpLogsOnFailure, "dump-logs-on-failure", true, "If set to true test will dump data about the namespace in which test was running.") + flag.BoolVar(&TestContext.DeleteNamespace, "delete-namespace", true, "If true tests will delete namespace after completion. It is only designed to make debugging easier, DO NOT turn it off by default.") flag.StringVar(&TestContext.Host, "host", "http://127.0.0.1:8080", "The host, or apiserver, to connect to") } // Register flags specific to the cluster e2e test suite. func RegisterClusterFlags() { - // TODO: Move to common flags once namespace deletion is fixed for node e2e. - flag.BoolVar(&TestContext.DeleteNamespace, "delete-namespace", true, "If true tests will delete namespace after completion. It is only designed to make debugging easier, DO NOT turn it off by default.") - flag.BoolVar(&TestContext.VerifyServiceAccount, "e2e-verify-service-account", true, "If true tests will verify the service account before running.") flag.StringVar(&TestContext.KubeConfig, clientcmd.RecommendedConfigPathFlag, os.Getenv(clientcmd.RecommendedConfigPathEnvVar), "Path to kubeconfig containing embedded authinfo.") flag.StringVar(&TestContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'") diff --git a/test/e2e_node/e2e_node_suite_test.go b/test/e2e_node/e2e_node_suite_test.go index 1181fc84daa..f99b9f25b8d 100644 --- a/test/e2e_node/e2e_node_suite_test.go +++ b/test/e2e_node/e2e_node_suite_test.go @@ -31,6 +31,12 @@ import ( "testing" "time" + "k8s.io/kubernetes/pkg/api" + clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" + "k8s.io/kubernetes/pkg/client/restclient" + "k8s.io/kubernetes/pkg/client/typed/dynamic" + namespacecontroller "k8s.io/kubernetes/pkg/controller/namespace" + "k8s.io/kubernetes/pkg/util/wait" commontest "k8s.io/kubernetes/test/e2e/common" "k8s.io/kubernetes/test/e2e/framework" @@ -106,6 +112,9 @@ var _ = BeforeSuite(func() { glog.Infof("Running tests without starting services.") } + glog.Infof("Starting namespace controller") + startNamespaceController() + // Reference common test to make the import valid. commontest.CurrentSuite = commontest.NodeE2E }) @@ -135,3 +144,22 @@ func maskLocksmithdOnCoreos() { glog.Infof("Locksmithd is masked successfully") } } + +const ( + // ncResyncPeriod is resync period of the namespace controller + ncResyncPeriod = 5 * time.Minute + // ncConcurrency is concurrency of the namespace controller + ncConcurrency = 2 +) + +func startNamespaceController() { + // Use the default QPS + config := restclient.AddUserAgent(&restclient.Config{Host: framework.TestContext.Host}, "node-e2e-namespace-controller") + client, err := clientset.NewForConfig(config) + Expect(err).NotTo(HaveOccurred()) + clientPool := dynamic.NewClientPool(config, dynamic.LegacyAPIPathResolverFunc) + resources, err := client.Discovery().ServerPreferredNamespacedResources() + Expect(err).NotTo(HaveOccurred()) + nc := namespacecontroller.NewNamespaceController(client, clientPool, resources, ncResyncPeriod, api.FinalizerKubernetes) + go nc.Run(ncConcurrency, wait.NeverStop) +}