k8s.io/kubernetes@v1.29.3/test/e2e_node/runner/local/run_local.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 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 // Build dependencies - ginkgo, kubelet, e2e_node.test, and mounter. 47 if *buildDependencies { 48 if err := builder.BuildGo(); err != nil { 49 klog.Fatalf("Failed to build the dependencies: %v", err) 50 } 51 } 52 53 // Run node e2e test 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 }