From 4295365bf404959545e233c156ae377b42c99050 Mon Sep 17 00:00:00 2001 From: David Eads Date: Thu, 29 Oct 2020 13:55:59 +0100 Subject: [PATCH] UPSTREAM: : adapt to the new flag 'structure' --- test/e2e/cloud/gcp/patch_flagaccess.go | 17 +++++++ test/e2e/e2e_test.go | 11 +--- test/e2e/patch_from_e2e_testfile.go | 69 ++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 test/e2e/cloud/gcp/patch_flagaccess.go create mode 100644 test/e2e/patch_from_e2e_testfile.go diff --git a/test/e2e/cloud/gcp/patch_flagaccess.go b/test/e2e/cloud/gcp/patch_flagaccess.go new file mode 100644 index 0000000000000..09dda3c316177 --- /dev/null +++ b/test/e2e/cloud/gcp/patch_flagaccess.go @@ -0,0 +1,17 @@ +package gcp + +func GetUpgradeTarget() string { + return *upgradeTarget +} + +func SetUpgradeTarget(val string) { + upgradeTarget = &val +} + +func GetUpgradeImage() string { + return *upgradeImage +} + +func SetUpgradeImage(val string) { + upgradeImage = &val +} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 61f7f61727e56..8651f507499c1 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -34,7 +34,6 @@ import ( "k8s.io/component-base/version" "k8s.io/kubernetes/test/e2e/framework" - "k8s.io/kubernetes/test/e2e/framework/config" "k8s.io/kubernetes/test/e2e/framework/testfiles" "k8s.io/kubernetes/test/e2e/generated" "k8s.io/kubernetes/test/utils/image" @@ -61,20 +60,12 @@ import ( var viperConfig = flag.String("viper-config", "", "The name of a viper config file (https://github.com/spf13/viper#what-is-viper). All e2e command line parameters can also be configured in such a file. May contain a path and may or may not contain the file suffix. The default is to look for an optional file with `e2e` as base name. If a file is specified explicitly, it must be present.") -// handleFlags sets up all flags and parses the command line. -func handleFlags() { - config.CopyFlags(config.Flags, flag.CommandLine) - framework.RegisterCommonFlags(flag.CommandLine) - framework.RegisterClusterFlags(flag.CommandLine) - flag.Parse() -} - func TestMain(m *testing.M) { var versionFlag bool flag.CommandLine.BoolVar(&versionFlag, "version", false, "Displays version information.") // Register test flags, then parse flags. - handleFlags() + HandleFlags() // Now that we know which Viper config (if any) was chosen, // parse it and update those options which weren't already set via command line flags diff --git a/test/e2e/patch_from_e2e_testfile.go b/test/e2e/patch_from_e2e_testfile.go new file mode 100644 index 0000000000000..c11289ff7893f --- /dev/null +++ b/test/e2e/patch_from_e2e_testfile.go @@ -0,0 +1,69 @@ +package e2e + +import ( + "flag" + "fmt" + "os" + + "k8s.io/kubernetes/test/e2e/framework/config" + + "k8s.io/kubernetes/test/e2e/framework" + "k8s.io/kubernetes/test/e2e/framework/testfiles" + "k8s.io/kubernetes/test/e2e/generated" + "k8s.io/kubernetes/test/utils/image" +) + +func HandleFlags() { + config.CopyFlags(config.Flags, flag.CommandLine) + framework.RegisterCommonFlags(flag.CommandLine) + framework.RegisterClusterFlags(flag.CommandLine) + flag.Parse() +} + +// this function matches the init block from e2e_test.go +func ViperizeFlags(viperConfig string) { + HandleFlags() + + // Register framework flags, then handle flags and Viper config. + if err := viperizeFlags(viperConfig, "e2e", flag.CommandLine); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + if framework.TestContext.ListImages { + for _, v := range image.GetImageConfigs() { + fmt.Println(v.GetE2EImage()) + } + os.Exit(0) + } + + framework.AfterReadingAllFlags(&framework.TestContext) + + // this came from the init block, but it breaks on openshift. Not really sure why. + // TODO: Deprecating repo-root over time... instead just use gobindata_util.go , see #23987. + // Right now it is still needed, for example by + // test/e2e/framework/ingress/ingress_utils.go + // for providing the optional secret.yaml file and by + // test/e2e/framework/util.go for cluster/log-dump. + //if framework.TestContext.RepoRoot != "" { + // testfiles.AddFileSource(testfiles.RootFileSource{Root: framework.TestContext.RepoRoot}) + //} + + // Enable bindata file lookup as fallback. + testfiles.AddFileSource(testfiles.BindataFileSource{ + Asset: generated.Asset, + AssetNames: generated.AssetNames, + }) + +} + +var localViperConfig = "" + +// we appear to set ours via env-var, not flag +func GetViperConfig() string { + return localViperConfig +} + +func SetViperConfig(val string) { + localViperConfig = val +}