@@ -511,6 +512,20 @@ breaking changes, it does *not* block the merge-queue, and thus should run in
some separate test suites owned by the feature owner(s)
(see [Continuous Integration](#continuous-integration) below).
### Viper configuration and hierarchichal test parameters.
The future of e2e test configuration idioms will be increasingly defined using viper, and decreasingly via flags.
Flags in general fall apart once tests become sufficiently complicated. So, even if we could use another flag library, it wouldn't be ideal.
To use viper, rather than flags, to configure your tests:
- Just add "e2e.json" to the current directory you are in, and define parameters in it... i.e. `"kubeconfig":"/tmp/x"`.
Note that advanced testing parameters, and hierarchichally defined parameters, are only defined in viper, to see what they are, you can dive into [TestContextType](../../test/e2e/framework/test_context.go).
In time, it is our intent to add or autogenerate a sample viper configuration that includes all e2e parameters, to ship with kubernetes.
### Conformance tests
Finally, `[Conformance]` tests represent a subset of the e2e-tests we expect to
// Viper-only parameters. These will in time replace all flags.
// Example: Create a file 'e2e.json' with the following:
// "Cadvisor":{
// "MaxRetries":"6"
// }
Viperstring
Cadvisorstruct{
MaxRetriesint
SleepDurationMSint
}
}
// NodeTestContextType is part of TestContextType, it is shared by all node e2e test.
...
...
@@ -134,6 +145,7 @@ func RegisterCommonFlags() {
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.FeatureGates,"feature-gates","","A set of key=value pairs that describe feature gates for alpha/experimental features.")
flag.StringVar(&TestContext.Viper,"viper-config","e2e","The name of the viper config i.e. 'e2e' will read values from 'e2e.json' locally. All e2e parameters are meant to be configurable by viper.")
}
// Register flags specific to the cluster e2e test suite.
...
...
@@ -190,25 +202,35 @@ func RegisterNodeFlags() {
// Enable viper configuration management of flags.
funcViperizeFlags(){
// 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){
ifviper.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)
// Add viper in a minimal way.
// Flag interop isnt possible, since 'go test' coupling to flag.Parse.
// This must be done after common flags are registered, since Viper is a flag option.
viper.SetConfigName(TestContext.Viper)
viper.AddConfigPath(".")
viper.ReadInConfig()
viper.Unmarshal(&TestContext)
/** This can be used to overwrite a flag value.
*
* 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)
* viper.Unmarshal(&TestContext)
* // f.Value.Set(viper.GetString(f.Name))
* }
* }
* // Each flag that we've declared can be set via viper.