1
16
17 package main
18
19 import (
20 "flag"
21 "fmt"
22 "os"
23 "os/exec"
24 "path/filepath"
25 "strings"
26
27 "k8s.io/kubernetes/test/e2e_node/builder"
28 "k8s.io/kubernetes/test/e2e_node/system"
29 "k8s.io/kubernetes/test/utils"
30
31 "k8s.io/klog/v2"
32 )
33
34 var buildDependencies = flag.Bool("build-dependencies", true, "If true, build all dependencies.")
35 var ginkgoFlags = flag.String("ginkgo-flags", "", "Space-separated list of arguments to pass to Ginkgo test runner.")
36 var testFlags = flag.String("test-flags", "", "Space-separated list of arguments to pass to node e2e test.")
37 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))
38 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")
39 var runtimeConfig = flag.String("runtime-config", "", "The runtime configuration for the API server on the node e2e tests. Format: a list of key=value pairs, e.g., env1=val1,env2=val2")
40 var kubeletConfigFile = flag.String("kubelet-config-file", "", "The KubeletConfiguration file that should be applied to the kubelet")
41
42 func main() {
43 klog.InitFlags(nil)
44 flag.Parse()
45
46
47 if *buildDependencies {
48 if err := builder.BuildGo(); err != nil {
49 klog.Fatalf("Failed to build the dependencies: %v", err)
50 }
51 }
52
53
54 outputDir, err := utils.GetK8sBuildOutputDir(builder.IsDockerizedBuild(), builder.GetTargetBuildArch())
55 if err != nil {
56 klog.Fatalf("Failed to get build output directory: %v", err)
57 }
58 klog.Infof("Got build output dir: %v", outputDir)
59 ginkgo := filepath.Join(outputDir, "ginkgo")
60 test := filepath.Join(outputDir, "e2e_node.test")
61
62 args := []string{*ginkgoFlags, test, "--", *testFlags, fmt.Sprintf("--runtime-config=%s", *runtimeConfig)}
63 if *systemSpecName != "" {
64 rootDir, err := utils.GetK8sRootDir()
65 if err != nil {
66 klog.Fatalf("Failed to get k8s root directory: %v", err)
67 }
68 systemSpecFile := filepath.Join(rootDir, system.SystemSpecPath, *systemSpecName+".yaml")
69 args = append(args, fmt.Sprintf("--system-spec-name=%s --system-spec-file=%s --extra-envs=%s", *systemSpecName, systemSpecFile, *extraEnvs))
70 }
71 if *kubeletConfigFile != "" {
72 args = append(args, fmt.Sprintf("--kubelet-config-file=\"%s\"", *kubeletConfigFile))
73 }
74 if err := runCommand(ginkgo, args...); err != nil {
75 klog.Exitf("Test failed: %v", err)
76 }
77 return
78 }
79
80 func runCommand(name string, args ...string) error {
81 klog.Infof("Running command: %v %v", name, strings.Join(args, " "))
82 cmd := exec.Command("sudo", "sh", "-c", strings.Join(append([]string{name}, args...), " "))
83 cmd.Stdout = os.Stdout
84 cmd.Stderr = os.Stderr
85 return cmd.Run()
86 }
87
View as plain text