Commit 430921ee authored by jayunit100's avatar jayunit100

Cleanup the commented code for overriding flags with viper. For now, leave that…

Cleanup the commented code for overriding flags with viper. For now, leave that functinoality unused with a TODO if we want to override flag values w/ viper visitor pattern
parent f15c12c3
......@@ -211,36 +211,32 @@ func RegisterNodeFlags() {
flag.StringVar(&TestContext.RuntimeIntegrationType, "runtime-integration-type", "", "Choose the integration path for the container runtime, mainly used for CRI validation.")
}
// Enable viper configuration management of flags.
// overwriteFlagsWithViperConfig finds and writes values to flags using viper as input.
func overwriteFlagsWithViperConfig() {
viperFlagSetter := func(f *flag.Flag) {
if viper.IsSet(f.Name) {
f.Value.Set(viper.GetString(f.Name))
}
}
flag.VisitAll(viperFlagSetter)
}
// ViperizeFlags sets up all flag and config processing. Future configuration info should be added to viper, not to flags.
func ViperizeFlags() {
// 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.
// Part 1: Set regular flags.
// TODO: Future, lets eliminate e2e 'flag' deps entirely in favor of viper only,
// since go test 'flag's are sort of incompatible w/ flag, glog, etc.
RegisterCommonFlags()
RegisterClusterFlags()
flag.Parse()
// Add viper in a minimal way.
// Flag interop isnt possible, since 'go test' coupling to flag.Parse.
// Part 2: Set Viper provided flags.
// This must be done after common flags are registered, since Viper is a flag option.
viper.SetConfigName(TestContext.Viper)
viper.AddConfigPath(".")
viper.ReadInConfig()
// TODO Consider wether or not we want to use overwriteFlagsWithViperConfig().
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.
* flag.VisitAll(viperFlagSetter)
*
*/
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment