k8s.io/kubernetes@v1.29.3/test/conformance/image/go-runner/cmd.go (about) 1 /* 2 Copyright 2019 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 "fmt" 21 "io" 22 "os/exec" 23 "strings" 24 ) 25 26 // getCmd uses the given environment to form the ginkgo command to run tests. It will 27 // set the stdout/stderr to the given writer. 28 func getCmd(env Getenver, w io.Writer) *exec.Cmd { 29 ginkgoArgs := []string{} 30 31 // The logic of the parallel env var impacting the skip value necessitates it 32 // being placed before the rest of the flag resolution. 33 skip := env.Getenv(skipEnvKey) 34 switch env.Getenv(parallelEnvKey) { 35 case "y", "Y", "true": 36 ginkgoArgs = append(ginkgoArgs, "--p") 37 if len(skip) == 0 { 38 skip = serialTestsRegexp 39 } 40 } 41 42 ginkgoArgs = append(ginkgoArgs, []string{ 43 "--focus=" + env.Getenv(focusEnvKey), 44 "--skip=" + skip, 45 "--no-color=true", 46 }...) 47 48 extraArgs := []string{ 49 "--disable-log-dump", 50 "--repo-root=/kubernetes", 51 "--provider=" + env.Getenv(providerEnvKey), 52 "--report-dir=" + env.Getenv(resultsDirEnvKey), 53 "--kubeconfig=" + env.Getenv(kubeconfigEnvKey), 54 } 55 56 // Extra args handling 57 sep := " " 58 if len(env.Getenv(extraArgsSeparaterEnvKey)) > 0 { 59 sep = env.Getenv(extraArgsSeparaterEnvKey) 60 } 61 62 if len(env.Getenv(extraGinkgoArgsEnvKey)) > 0 { 63 ginkgoArgs = append(ginkgoArgs, strings.Split(env.Getenv(extraGinkgoArgsEnvKey), sep)...) 64 } 65 66 if len(env.Getenv(extraArgsEnvKey)) > 0 { 67 fmt.Printf("sep is %q args are %q", sep, env.Getenv(extraArgsEnvKey)) 68 fmt.Println("split", strings.Split(env.Getenv(extraArgsEnvKey), sep)) 69 extraArgs = append(extraArgs, strings.Split(env.Getenv(extraArgsEnvKey), sep)...) 70 } 71 72 if len(env.Getenv(dryRunEnvKey)) > 0 { 73 ginkgoArgs = append(ginkgoArgs, "--dryRun=true") 74 } 75 // NOTE: Ginkgo's default timeout has been reduced from 24h to 1h in V2, set it as "24h" for backward compatibility 76 // if this is not set by env of extraGinkgoArgsEnvKey. 77 exists := func(args []string) bool { 78 for _, arg := range args { 79 if strings.Contains(arg, "--timeout") { 80 return true 81 } 82 } 83 return false 84 }(ginkgoArgs) 85 86 if !exists { 87 ginkgoArgs = append(ginkgoArgs, "--timeout=24h") 88 } 89 90 args := []string{} 91 args = append(args, ginkgoArgs...) 92 args = append(args, env.Getenv(testBinEnvKey)) 93 args = append(args, "--") 94 args = append(args, extraArgs...) 95 96 cmd := exec.Command(env.Getenv(ginkgoEnvKey), args...) 97 cmd.Stdout = w 98 cmd.Stderr = w 99 return cmd 100 } 101 102 // cmdInfo generates a useful look at what the command is for printing/debug. 103 func cmdInfo(cmd *exec.Cmd) string { 104 return fmt.Sprintf( 105 `Command env: %v 106 Run from directory: %v 107 Executable path: %v 108 Args (comma-delimited): %v`, cmd.Env, cmd.Dir, cmd.Path, strings.Join(cmd.Args, ","), 109 ) 110 }