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
This commit is contained in:
		@@ -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.")
 | 
						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() {
 | 
					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
 | 
						// Part 1: Set regular flags.
 | 
				
			||||||
	// fragile, seeming to force 'flag' to have deep awareness of pflag params.
 | 
						// 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()
 | 
						RegisterCommonFlags()
 | 
				
			||||||
	RegisterClusterFlags()
 | 
						RegisterClusterFlags()
 | 
				
			||||||
 | 
					 | 
				
			||||||
	flag.Parse()
 | 
						flag.Parse()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Add viper in a minimal way.
 | 
						// Part 2: Set Viper provided flags.
 | 
				
			||||||
	// 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.
 | 
						// This must be done after common flags are registered, since Viper is a flag option.
 | 
				
			||||||
	viper.SetConfigName(TestContext.Viper)
 | 
						viper.SetConfigName(TestContext.Viper)
 | 
				
			||||||
	viper.AddConfigPath(".")
 | 
						viper.AddConfigPath(".")
 | 
				
			||||||
	viper.ReadInConfig()
 | 
						viper.ReadInConfig()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// TODO Consider wether or not we want to use overwriteFlagsWithViperConfig().
 | 
				
			||||||
	viper.Unmarshal(&TestContext)
 | 
						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)
 | 
					 | 
				
			||||||
	*
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user