From b7ec229e2cee9916436ea532f861a6605940e177 Mon Sep 17 00:00:00 2001 From: Random-Liu Date: Fri, 2 Dec 2016 00:32:38 -0800 Subject: [PATCH] Add run kubelet mode. --- hack/verify-flags/known-flags.txt | 1 + test/e2e_node/e2e_node_suite_test.go | 6 ++++ test/e2e_node/services/internal_services.go | 10 +----- test/e2e_node/services/kubelet.go | 16 ++++++++++ test/e2e_node/services/util.go | 34 +++++++++++++++++++++ 5 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 test/e2e_node/services/util.go diff --git a/hack/verify-flags/known-flags.txt b/hack/verify-flags/known-flags.txt index 1a838958b4a..fc32dfcdfca 100644 --- a/hack/verify-flags/known-flags.txt +++ b/hack/verify-flags/known-flags.txt @@ -525,6 +525,7 @@ rkt-stage1-image root-ca-file root-dir route-reconciliation-period +run-kubelet-mode run-proxy run-services-mode runtime-cgroups diff --git a/test/e2e_node/e2e_node_suite_test.go b/test/e2e_node/e2e_node_suite_test.go index 8f8715e6b60..a1d3b7978f6 100644 --- a/test/e2e_node/e2e_node_suite_test.go +++ b/test/e2e_node/e2e_node_suite_test.go @@ -51,6 +51,7 @@ var e2es *services.E2EServices // TODO(random-liu): Change the following modes to sub-command. var runServicesMode = flag.Bool("run-services-mode", false, "If true, only run services (etcd, apiserver) in current process, and not run test.") +var runKubeletMode = flag.Bool("run-kubelet-mode", false, "If true, only start kubelet, and not run test.") var systemValidateMode = flag.Bool("system-validate-mode", false, "If true, only run system validation in current process, and not run test.") func init() { @@ -81,6 +82,11 @@ func TestE2eNode(t *testing.T) { services.RunE2EServices() return } + if *runKubeletMode { + // If run-kubelet-mode is specified, only start kubelet. + services.RunKubelet() + return + } if *systemValidateMode { // If system-validate-mode is specified, only run system validation in current process. if framework.TestContext.NodeConformance { diff --git a/test/e2e_node/services/internal_services.go b/test/e2e_node/services/internal_services.go index a38163ddd93..344883b2088 100644 --- a/test/e2e_node/services/internal_services.go +++ b/test/e2e_node/services/internal_services.go @@ -19,8 +19,6 @@ package services import ( "io/ioutil" "os" - "os/signal" - "syscall" "github.com/golang/glog" ) @@ -38,10 +36,6 @@ func newE2EServices() *e2eServices { return &e2eServices{} } -// terminationSignals are signals that cause the program to exit in the -// supported platforms (linux, darwin, windows). -var terminationSignals = []os.Signal{syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT} - // run starts all e2e services and wait for the termination signal. Once receives the // termination signal, it will stop the e2e services gracefully. func (es *e2eServices) run() error { @@ -50,9 +44,7 @@ func (es *e2eServices) run() error { return err } // Wait until receiving a termination signal. - sig := make(chan os.Signal, 1) - signal.Notify(sig, terminationSignals...) - <-sig + waitForTerminationSignal() return nil } diff --git a/test/e2e_node/services/kubelet.go b/test/e2e_node/services/kubelet.go index 5ea5b633243..0be6a0e8dbe 100644 --- a/test/e2e_node/services/kubelet.go +++ b/test/e2e_node/services/kubelet.go @@ -63,6 +63,22 @@ func init() { flag.Var(&kubeletArgs, "kubelet-flags", "Kubelet flags passed to kubelet, this will override default kubelet flags in the test. Flags specified in multiple kubelet-flags will be concatenate.") } +// RunKubelet starts kubelet and waits for termination signal. Once receives the +// termination signal, it will stop the kubelet gracefully. +func RunKubelet() { + var err error + // Enable monitorParent to make sure kubelet will receive termination signal + // when test process exits. + e := NewE2EServices(true /* monitorParent */) + defer e.Stop() + e.kubelet, err = e.startKubelet() + if err != nil { + glog.Fatalf("Failed to start kubelet: %v", err) + } + // Wait until receiving a termination signal. + waitForTerminationSignal() +} + const ( // Ports of different e2e services. kubeletPort = "10250" diff --git a/test/e2e_node/services/util.go b/test/e2e_node/services/util.go new file mode 100644 index 00000000000..558be7d52d7 --- /dev/null +++ b/test/e2e_node/services/util.go @@ -0,0 +1,34 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package services + +import ( + "os" + "os/signal" + "syscall" +) + +// terminationSignals are signals that cause the program to exit in the +// supported platforms (linux, darwin, windows). +var terminationSignals = []os.Signal{syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT} + +// waitForTerminationSignal waits for termination signal. +func waitForTerminationSignal() { + sig := make(chan os.Signal, 1) + signal.Notify(sig, terminationSignals...) + <-sig +}