prevent initializing the same flag more than once

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2023-03-13 12:49:07 -04:00
parent be42dcfd73
commit a889cc7f79
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59
2 changed files with 24 additions and 13 deletions

View File

@ -28,8 +28,6 @@ import (
"sync"
"time"
"k8s.io/kubernetes/test/e2e_node/system"
"k8s.io/klog/v2"
)
@ -45,10 +43,6 @@ var deleteInstances = flag.Bool("delete-instances", true, "If true, delete any i
var buildOnly = flag.Bool("build-only", false, "If true, build e2e_node_test.tar.gz and exit.")
var gubernator = flag.Bool("gubernator", false, "If true, output Gubernator link to view logs")
var ginkgoFlags = flag.String("ginkgo-flags", "", "Passed to ginkgo to specify additional flags such as --skip=.")
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))
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")
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")
var kubeletConfigFile = flag.String("kubelet-config-file", "", "The KubeletConfiguration file that should be applied to the kubelet")
var (
arc Archive
)
@ -60,6 +54,14 @@ type Archive struct {
err error
}
func getFlag(name string) string {
lookup := flag.Lookup(name)
if lookup == nil {
return ""
}
return lookup.Value.String()
}
func RunRemoteTestSuite(testSuite TestSuite) {
// Listen for SIGINT and ignore the first one. In case SIGINT is sent to this
// process and all its children, we ignore it here, while our children ssh connections
@ -78,7 +80,9 @@ func RunRemoteTestSuite(testSuite TestSuite) {
rand.Seed(time.Now().UnixNano())
if *buildOnly {
// Build the archive and exit
CreateTestArchive(testSuite, *systemSpecName, *kubeletConfigFile)
CreateTestArchive(testSuite,
getFlag("system-spec-name"),
getFlag("kubelet-config-file"))
return
}
@ -97,9 +101,9 @@ func RunRemoteTestSuite(testSuite TestSuite) {
DeleteInstances: *deleteInstances,
Cleanup: *cleanup,
TestArgs: *testArgs,
ExtraEnvs: *extraEnvs,
RuntimeConfig: *runtimeConfig,
SystemSpecName: *systemSpecName,
ExtraEnvs: getFlag("extra-envs"),
RuntimeConfig: getFlag("runtime-config"),
SystemSpecName: getFlag("system-spec-name"),
}
var sshRunner Runner
@ -197,7 +201,11 @@ func callGubernator(gubernator bool) {
}
func (a *Archive) getArchive(suite TestSuite) (string, error) {
a.Do(func() { a.path, a.err = CreateTestArchive(suite, *systemSpecName, *kubeletConfigFile) })
a.Do(func() {
a.path, a.err = CreateTestArchive(suite,
getFlag("system-spec-name"),
getFlag("kubelet-config-file"))
})
return a.path, a.err
}

View File

@ -63,11 +63,9 @@ func (a *args) Set(value string) error {
// kubeletArgs is the override kubelet args specified by the test runner.
var kubeletArgs args
var kubeletConfigFile string
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. Deprecated, see: --kubelet-config-file.")
flag.StringVar(&kubeletConfigFile, "kubelet-config-file", "./kubeletconfig.yaml", "The base KubeletConfiguration to use when setting up the kubelet. This configuration will then be minimially modified to support requirements from the test suite.")
}
// RunKubelet starts kubelet and waits for termination signal. Once receives the
@ -176,6 +174,11 @@ func (e *E2EServices) startKubelet(featureGates map[string]bool) (*server, error
return nil, err
}
kubeletConfigFile := "./kubeletconfig.yaml"
lookup := flag.Lookup("kubelet-config-file")
if lookup != nil {
kubeletConfigFile = lookup.Value.String()
}
kc, err := baseKubeConfiguration(kubeletConfigFile)
if err != nil {
return nil, fmt.Errorf("failed to load base kubelet configuration: %w", err)