run_local.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package main
  14. import (
  15. "flag"
  16. "fmt"
  17. "os"
  18. "os/exec"
  19. "path/filepath"
  20. "strings"
  21. "k8s.io/kubernetes/test/e2e_node/builder"
  22. "k8s.io/kubernetes/test/e2e_node/system"
  23. "k8s.io/kubernetes/test/utils"
  24. "k8s.io/klog"
  25. )
  26. var buildDependencies = flag.Bool("build-dependencies", true, "If true, build all dependencies.")
  27. var ginkgoFlags = flag.String("ginkgo-flags", "", "Space-separated list of arguments to pass to Ginkgo test runner.")
  28. var testFlags = flag.String("test-flags", "", "Space-separated list of arguments to pass to node e2e test.")
  29. var systemSpecName = flag.String("system-spec-name", "", fmt.Sprintf("The name of the system spec used for validating the image in the node conformance test. The specs are at %s. If unspecified, the default built-in spec (system.DefaultSpec) will be used.", system.SystemSpecPath))
  30. var extraEnvs = flag.String("extra-envs", "", "The extra environment variables needed for node e2e tests. Format: a list of key=value pairs, e.g., env1=val1,env2=val2")
  31. func main() {
  32. klog.InitFlags(nil)
  33. flag.Parse()
  34. // Build dependencies - ginkgo, kubelet and apiserver.
  35. if *buildDependencies {
  36. if err := builder.BuildGo(); err != nil {
  37. klog.Fatalf("Failed to build the dependencies: %v", err)
  38. }
  39. }
  40. // Run node e2e test
  41. outputDir, err := utils.GetK8sBuildOutputDir()
  42. if err != nil {
  43. klog.Fatalf("Failed to get build output directory: %v", err)
  44. }
  45. klog.Infof("Got build output dir: %v", outputDir)
  46. ginkgo := filepath.Join(outputDir, "ginkgo")
  47. test := filepath.Join(outputDir, "e2e_node.test")
  48. args := []string{*ginkgoFlags, test, "--", *testFlags}
  49. if *systemSpecName != "" {
  50. rootDir, err := utils.GetK8sRootDir()
  51. if err != nil {
  52. klog.Fatalf("Failed to get k8s root directory: %v", err)
  53. }
  54. systemSpecFile := filepath.Join(rootDir, system.SystemSpecPath, *systemSpecName+".yaml")
  55. args = append(args, fmt.Sprintf("--system-spec-name=%s --system-spec-file=%s --extra-envs=%s", *systemSpecName, systemSpecFile, *extraEnvs))
  56. }
  57. if err := runCommand(ginkgo, args...); err != nil {
  58. klog.Exitf("Test failed: %v", err)
  59. }
  60. return
  61. }
  62. func runCommand(name string, args ...string) error {
  63. klog.Infof("Running command: %v %v", name, strings.Join(args, " "))
  64. cmd := exec.Command("sudo", "sh", "-c", strings.Join(append([]string{name}, args...), " "))
  65. cmd.Stdout = os.Stdout
  66. cmd.Stderr = os.Stderr
  67. return cmd.Run()
  68. }