@@ -64,19 +64,26 @@ var (
6464
6565// Options is a struct to hold options for the version-checker.
6666type Options struct {
67+ kubeConfigFlags * genericclioptions.ConfigFlags
68+
69+ Client client.Options
6770 MetricsServingAddress string
68- DefaultTestAll bool
69- CacheTimeout time.Duration
7071 LogLevel string
7172
72- PprofBindAddress string
73+ PprofBindAddress string
74+ selfhosted selfhosted.Options
75+
76+ CacheTimeout time.Duration
77+ RequeueDuration time.Duration
7378 GracefulShutdownTimeout time.Duration
7479 CacheSyncPeriod time.Duration
7580
76- kubeConfigFlags * genericclioptions. ConfigFlags
77- selfhosted selfhosted. Options
81+ DefaultTestAll bool
82+ }
7883
79- Client client.Options
84+ type envMatcher struct {
85+ re * regexp.Regexp
86+ action func (matches []string , value string )
8087}
8188
8289func (o * Options ) addFlags (cmd * cobra.Command ) {
@@ -124,6 +131,10 @@ func (o *Options) addAppFlags(fs *pflag.FlagSet) {
124131 "The time for an image version in the cache to be considered fresh. Images " +
125132 "will be rechecked after this interval." )
126133
134+ fs .DurationVarP (& o .RequeueDuration ,
135+ "requeue-duration" , "r" , time .Hour ,
136+ "The time a pod will be re-checked for new versions/tags" )
137+
127138 fs .StringVarP (& o .LogLevel ,
128139 "log-level" , "v" , "info" ,
129140 "Log level (debug, info, warn, error, fatal, panic)." )
@@ -363,51 +374,73 @@ func (o *Options) assignSelfhosted(envs []string) {
363374 }
364375 }
365376
366- regexActions := map [* regexp.Regexp ]func (matches []string , value string ){
367- selfhostedHostReg : func (matches []string , value string ) {
368- initOptions (matches [1 ])
369- o .Client .Selfhosted [matches [1 ]].Host = value
377+ // Go maps iterate in random order - Using a slice to consistency
378+ regexActions := []envMatcher {
379+ {
380+ re : selfhostedTokenPath ,
381+ action : func (matches []string , value string ) {
382+ initOptions (matches [1 ])
383+ o .Client .Selfhosted [matches [1 ]].TokenPath = value
384+ },
370385 },
371- selfhostedUsernameReg : func (matches []string , value string ) {
372- initOptions (matches [1 ])
373- o .Client .Selfhosted [matches [1 ]].Username = value
386+ {
387+ re : selfhostedTokenReg ,
388+ action : func (matches []string , value string ) {
389+ initOptions (matches [1 ])
390+ o .Client .Selfhosted [matches [1 ]].Bearer = value
391+ },
374392 },
375- selfhostedPasswordReg : func (matches []string , value string ) {
376- initOptions (matches [1 ])
377- o .Client .Selfhosted [matches [1 ]].Password = value
393+ // All your other patterns (host, username, password, insecure, capath...)
394+ {
395+ re : selfhostedHostReg ,
396+ action : func (matches []string , value string ) {
397+ initOptions (matches [1 ])
398+ o .Client .Selfhosted [matches [1 ]].Host = value
399+ },
378400 },
379- selfhostedTokenPath : func (matches []string , value string ) {
380- initOptions (matches [1 ])
381- o .Client .Selfhosted [matches [1 ]].TokenPath = value
401+ {
402+ re : selfhostedUsernameReg ,
403+ action : func (matches []string , value string ) {
404+ initOptions (matches [1 ])
405+ o .Client .Selfhosted [matches [1 ]].Username = value
406+ },
382407 },
383- selfhostedTokenReg : func (matches []string , value string ) {
384- initOptions (matches [1 ])
385- o .Client .Selfhosted [matches [1 ]].Bearer = value
408+ {
409+ re : selfhostedPasswordReg ,
410+ action : func (matches []string , value string ) {
411+ initOptions (matches [1 ])
412+ o .Client .Selfhosted [matches [1 ]].Password = value
413+ },
386414 },
387- selfhostedInsecureReg : func (matches []string , value string ) {
388- initOptions (matches [1 ])
389- if val , err := strconv .ParseBool (value ); err == nil {
390- o .Client .Selfhosted [matches [1 ]].Insecure = val
391- }
415+ {
416+ re : selfhostedInsecureReg ,
417+ action : func (matches []string , value string ) {
418+ initOptions (matches [1 ])
419+ if b , err := strconv .ParseBool (value ); err == nil {
420+ o .Client .Selfhosted [matches [1 ]].Insecure = b
421+ }
422+ },
392423 },
393- selfhostedCAPath : func (matches []string , value string ) {
394- initOptions (matches [1 ])
395- o .Client .Selfhosted [matches [1 ]].CAPath = value
424+ {
425+ re : selfhostedCAPath ,
426+ action : func (matches []string , value string ) {
427+ initOptions (matches [1 ])
428+ o .Client .Selfhosted [matches [1 ]].CAPath = value
429+ },
396430 },
397431 }
398432
399433 for _ , env := range envs {
400- pair := strings .SplitN (env , "=" , 2 )
401- if len (pair ) != 2 || len ( pair [1 ]) == 0 {
434+ parts := strings .SplitN (env , "=" , 2 )
435+ if len (parts ) != 2 || parts [1 ] == "" {
402436 continue
403437 }
438+ key := strings .ToUpper (parts [0 ])
439+ val := parts [1 ]
404440
405- key := strings .ToUpper (pair [0 ])
406- value := pair [1 ]
407-
408- for regex , action := range regexActions {
409- if matches := regex .FindStringSubmatch (key ); len (matches ) == 2 {
410- action (matches , value )
441+ for _ , p := range regexActions {
442+ if match := p .re .FindStringSubmatch (key ); len (match ) == 2 {
443+ p .action (match , val )
411444 break
412445 }
413446 }
0 commit comments