@@ -64,19 +64,26 @@ var (
64
64
65
65
// Options is a struct to hold options for the version-checker.
66
66
type Options struct {
67
+ kubeConfigFlags * genericclioptions.ConfigFlags
68
+
69
+ Client client.Options
67
70
MetricsServingAddress string
68
- DefaultTestAll bool
69
- CacheTimeout time.Duration
70
71
LogLevel string
71
72
72
- PprofBindAddress string
73
+ PprofBindAddress string
74
+ selfhosted selfhosted.Options
75
+
76
+ CacheTimeout time.Duration
77
+ RequeueDuration time.Duration
73
78
GracefulShutdownTimeout time.Duration
74
79
CacheSyncPeriod time.Duration
75
80
76
- kubeConfigFlags * genericclioptions. ConfigFlags
77
- selfhosted selfhosted. Options
81
+ DefaultTestAll bool
82
+ }
78
83
79
- Client client.Options
84
+ type envMatcher struct {
85
+ re * regexp.Regexp
86
+ action func (matches []string , value string )
80
87
}
81
88
82
89
func (o * Options ) addFlags (cmd * cobra.Command ) {
@@ -124,6 +131,10 @@ func (o *Options) addAppFlags(fs *pflag.FlagSet) {
124
131
"The time for an image version in the cache to be considered fresh. Images " +
125
132
"will be rechecked after this interval." )
126
133
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
+
127
138
fs .StringVarP (& o .LogLevel ,
128
139
"log-level" , "v" , "info" ,
129
140
"Log level (debug, info, warn, error, fatal, panic)." )
@@ -358,56 +369,81 @@ func (o *Options) assignSelfhosted(envs []string) {
358
369
}
359
370
360
371
initOptions := func (name string ) {
372
+ if name == "" {
373
+ panic ("Not meant to be empty!" )
374
+ }
361
375
if o .Client .Selfhosted [name ] == nil {
362
376
o .Client .Selfhosted [name ] = new (selfhosted.Options )
363
377
}
364
378
}
365
379
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
380
+ // Go maps iterate in random order - Using a slice to consistency
381
+ regexActions := []envMatcher {
382
+ {
383
+ re : selfhostedTokenPath ,
384
+ action : func (matches []string , value string ) {
385
+ initOptions (matches [1 ])
386
+ o .Client .Selfhosted [matches [1 ]].TokenPath = value
387
+ },
370
388
},
371
- selfhostedUsernameReg : func (matches []string , value string ) {
372
- initOptions (matches [1 ])
373
- o .Client .Selfhosted [matches [1 ]].Username = value
389
+ {
390
+ re : selfhostedTokenReg ,
391
+ action : func (matches []string , value string ) {
392
+ initOptions (matches [1 ])
393
+ o .Client .Selfhosted [matches [1 ]].Bearer = value
394
+ },
374
395
},
375
- selfhostedPasswordReg : func (matches []string , value string ) {
376
- initOptions (matches [1 ])
377
- o .Client .Selfhosted [matches [1 ]].Password = value
396
+ // All your other patterns (host, username, password, insecure, capath...)
397
+ {
398
+ re : selfhostedHostReg ,
399
+ action : func (matches []string , value string ) {
400
+ initOptions (matches [1 ])
401
+ o .Client .Selfhosted [matches [1 ]].Host = value
402
+ },
378
403
},
379
- selfhostedTokenPath : func (matches []string , value string ) {
380
- initOptions (matches [1 ])
381
- o .Client .Selfhosted [matches [1 ]].TokenPath = value
404
+ {
405
+ re : selfhostedUsernameReg ,
406
+ action : func (matches []string , value string ) {
407
+ initOptions (matches [1 ])
408
+ o .Client .Selfhosted [matches [1 ]].Username = value
409
+ },
382
410
},
383
- selfhostedTokenReg : func (matches []string , value string ) {
384
- initOptions (matches [1 ])
385
- o .Client .Selfhosted [matches [1 ]].Bearer = value
411
+ {
412
+ re : selfhostedPasswordReg ,
413
+ action : func (matches []string , value string ) {
414
+ initOptions (matches [1 ])
415
+ o .Client .Selfhosted [matches [1 ]].Password = value
416
+ },
386
417
},
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
- }
418
+ {
419
+ re : selfhostedInsecureReg ,
420
+ action : func (matches []string , value string ) {
421
+ initOptions (matches [1 ])
422
+ if b , err := strconv .ParseBool (value ); err == nil {
423
+ o .Client .Selfhosted [matches [1 ]].Insecure = b
424
+ }
425
+ },
392
426
},
393
- selfhostedCAPath : func (matches []string , value string ) {
394
- initOptions (matches [1 ])
395
- o .Client .Selfhosted [matches [1 ]].CAPath = value
427
+ {
428
+ re : selfhostedCAPath ,
429
+ action : func (matches []string , value string ) {
430
+ initOptions (matches [1 ])
431
+ o .Client .Selfhosted [matches [1 ]].CAPath = value
432
+ },
396
433
},
397
434
}
398
435
399
436
for _ , env := range envs {
400
- pair := strings .SplitN (env , "=" , 2 )
401
- if len (pair ) != 2 || len ( pair [1 ]) == 0 {
437
+ parts := strings .SplitN (env , "=" , 2 )
438
+ if len (parts ) != 2 || parts [1 ] == "" {
402
439
continue
403
440
}
441
+ key := strings .ToUpper (parts [0 ])
442
+ val := parts [1 ]
404
443
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 )
444
+ for _ , p := range regexActions {
445
+ if match := p .re .FindStringSubmatch (key ); len (match ) == 2 {
446
+ p .action (match , val )
411
447
break
412
448
}
413
449
}
0 commit comments