Merge pull request #40890 from marun/e2e-use-kubeconfig-host

Automatic merge from submit-queue

e2e: Prefer kubeconfig host to default

Previously it was necessary to pass ``-host`` to ``e2e.test`` even if ``-kubeconfig`` was specified since otherwise a localhost default would be used.  This change ensures that the default is only used when kubeconfig is not set. 

cc: @jayunit100
This commit is contained in:
Kubernetes Submit Queue
2017-04-19 20:26:00 -07:00
committed by GitHub
2 changed files with 17 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ package framework
import ( import (
"flag" "flag"
"fmt"
"os" "os"
"time" "time"
@@ -28,6 +29,8 @@ import (
"k8s.io/kubernetes/pkg/cloudprovider" "k8s.io/kubernetes/pkg/cloudprovider"
) )
const defaultHost = "http://127.0.0.1:8080"
type TestContextType struct { type TestContextType struct {
KubeConfig string KubeConfig string
KubeContext string KubeContext string
@@ -164,7 +167,8 @@ func RegisterCommonFlags() {
flag.BoolVar(&TestContext.DeleteNamespace, "delete-namespace", true, "If true tests will delete namespace after completion. It is only designed to make debugging easier, DO NOT turn it off by default.") flag.BoolVar(&TestContext.DeleteNamespace, "delete-namespace", true, "If true tests will delete namespace after completion. It is only designed to make debugging easier, DO NOT turn it off by default.")
flag.BoolVar(&TestContext.DeleteNamespaceOnFailure, "delete-namespace-on-failure", true, "If true, framework will delete test namespace on failure. Used only during test debugging.") flag.BoolVar(&TestContext.DeleteNamespaceOnFailure, "delete-namespace-on-failure", true, "If true, framework will delete test namespace on failure. Used only during test debugging.")
flag.IntVar(&TestContext.AllowedNotReadyNodes, "allowed-not-ready-nodes", 0, "If non-zero, framework will allow for that many non-ready nodes when checking for all ready nodes.") flag.IntVar(&TestContext.AllowedNotReadyNodes, "allowed-not-ready-nodes", 0, "If non-zero, framework will allow for that many non-ready nodes when checking for all ready nodes.")
flag.StringVar(&TestContext.Host, "host", "http://127.0.0.1:8080", "The host, or apiserver, to connect to")
flag.StringVar(&TestContext.Host, "host", "", fmt.Sprintf("The host, or apiserver, to connect to. Will default to %s if this argument and --kubeconfig are not set", defaultHost))
flag.StringVar(&TestContext.ReportPrefix, "report-prefix", "", "Optional prefix for JUnit XML reports. Default is empty, which doesn't prepend anything to the default name.") flag.StringVar(&TestContext.ReportPrefix, "report-prefix", "", "Optional prefix for JUnit XML reports. Default is empty, which doesn't prepend anything to the default name.")
flag.StringVar(&TestContext.ReportDir, "report-dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.") flag.StringVar(&TestContext.ReportDir, "report-dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.")
flag.StringVar(&TestContext.FeatureGates, "feature-gates", "", "A set of key=value pairs that describe feature gates for alpha/experimental features.") flag.StringVar(&TestContext.FeatureGates, "feature-gates", "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
@@ -262,4 +266,15 @@ func ViperizeFlags() {
// TODO Consider wether or not we want to use overwriteFlagsWithViperConfig(). // TODO Consider wether or not we want to use overwriteFlagsWithViperConfig().
viper.Unmarshal(&TestContext) viper.Unmarshal(&TestContext)
AfterReadingAllFlags(&TestContext)
}
// AfterReadingAllFlags makes changes to the context after all flags
// have been read.
func AfterReadingAllFlags(t *TestContextType) {
// Only set a default host if one won't be supplied via kubeconfig
if len(t.Host) == 0 && len(t.KubeConfig) == 0 {
t.Host = defaultHost
}
} }

View File

@@ -70,6 +70,7 @@ func init() {
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
pflag.Parse() pflag.Parse()
framework.AfterReadingAllFlags(&framework.TestContext)
os.Exit(m.Run()) os.Exit(m.Run())
} }