From 97396a34fadf93910c52a4f8d3f076b9be02f40c Mon Sep 17 00:00:00 2001 From: jayunit100 Date: Wed, 24 Aug 2016 21:39:50 -0400 Subject: [PATCH] Add viper support to core e2es rebase --- Godeps/Godeps.json | 12 ++++-------- test/e2e/e2e-example-config.json | 3 +++ test/e2e/e2e_test.go | 3 +-- test/e2e/framework/test_context.go | 30 +++++++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 test/e2e/e2e-example-config.json diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 0769a273e2..13fc979baf 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1403,10 +1403,6 @@ "ImportPath": "github.com/hashicorp/hcl/json/token", "Rev": "d8c773c4cba11b11539e3d45f93daeaa5dcf1fa1" }, - { - "ImportPath": "github.com/hashicorp/raft-boltdb", - "Rev": "d1e82c1ec3f15ee991f7cc7ffd5b67ff6f5bbaee" - }, { "ImportPath": "github.com/hawkular/hawkular-client-go/metrics", "Comment": "v0.5.1-1-g1d46ce7", @@ -2160,6 +2156,10 @@ "ImportPath": "github.com/spf13/pflag", "Rev": "1560c1005499d61b80f865c04d39ca7505bf7f0b" }, + { + "ImportPath": "github.com/spf13/viper", + "Rev": "7fb2782df3d83e0036cc89f461ed0422628776f4" + }, { "ImportPath": "github.com/square/go-jose", "Rev": "789a4c4bd4c118f7564954f441b29c153ccd6a96" @@ -2172,10 +2172,6 @@ "ImportPath": "github.com/square/go-jose/json", "Rev": "789a4c4bd4c118f7564954f441b29c153ccd6a96" }, - { - "ImportPath": "github.com/spf13/viper", - "Rev": "7fb2782df3d83e0036cc89f461ed0422628776f4" - }, { "ImportPath": "github.com/stretchr/objx", "Rev": "1a9d0bb9f541897e62256577b352fdbc1fb4fd94" diff --git a/test/e2e/e2e-example-config.json b/test/e2e/e2e-example-config.json new file mode 100644 index 0000000000..ce085466f6 --- /dev/null +++ b/test/e2e/e2e-example-config.json @@ -0,0 +1,3 @@ +{ + "provider":"local" +} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 30136f3015..c1d330b31f 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -23,8 +23,7 @@ import ( ) func init() { - framework.RegisterCommonFlags() - framework.RegisterClusterFlags() + framework.ViperizeFlags() } func TestE2E(t *testing.T) { diff --git a/test/e2e/framework/test_context.go b/test/e2e/framework/test_context.go index 91fb1134de..c49af1613d 100644 --- a/test/e2e/framework/test_context.go +++ b/test/e2e/framework/test_context.go @@ -21,7 +21,9 @@ import ( "os" "time" + glog "github.com/golang/glog" "github.com/onsi/ginkgo/config" + "github.com/spf13/viper" "k8s.io/kubernetes/pkg/client/unversioned/clientcmd" "k8s.io/kubernetes/pkg/cloudprovider" ) @@ -34,7 +36,8 @@ type TestContextType struct { CertDir string Host string // TODO: Deprecating this over time... instead just use gobindata_util.go , see #23987. - RepoRoot string + RepoRoot string + Provider string CloudConfig CloudConfig KubectlPath string @@ -181,3 +184,28 @@ func RegisterNodeFlags() { flag.StringVar(&TestContext.EvictionHard, "eviction-hard", "memory.available<250Mi,imagefs.available<10%", "The hard eviction thresholds. If set, pods get evicted when the specified resources drop below the thresholds.") flag.StringVar(&TestContext.ManifestPath, "manifest-path", "", "The path to the static pod manifest file.") } + +// Enable viper configuration management of flags. +func ViperizeFlags() { + // Add viper in a minimal way. + // Flag interop isnt possible, since 'go test' coupling to flag.Parse. + viper.SetConfigName("e2e") + viper.AddConfigPath(".") + viper.ReadInConfig() + + // TODO @jayunit100: Maybe a more elegant viper-flag integration for the future? + // For now, we layer it on top, because 'flag' deps of 'go test' make pflag wrappers + // fragile, seeming to force 'flag' to have deep awareness of pflag params. + RegisterCommonFlags() + RegisterClusterFlags() + flag.Parse() + + viperFlagSetter := func(f *flag.Flag) { + if viper.IsSet(f.Name) { + glog.V(4).Infof("[viper config] Overwriting, found a settting for %v %v", f.Name, f.Value) + f.Value.Set(viper.GetString(f.Name)) + } + } + // Each flag that we've declared can be set via viper. + flag.VisitAll(viperFlagSetter) +}