Skip to content

Commit

Permalink
UPSTREAM: <carry>: adapt to the new flag 'structure'
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k authored and soltysh committed Sep 8, 2021
1 parent a808739 commit 4295365
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 10 deletions.
17 changes: 17 additions & 0 deletions test/e2e/cloud/gcp/patch_flagaccess.go
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 1 addition & 10 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
69 changes: 69 additions & 0 deletions test/e2e/patch_from_e2e_testfile.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4295365

Please sign in to comment.