@@ -48,16 +48,16 @@ func RunKubeStateMetricsWrapper(opts *options.Options) {
48
48
cfgViper := viper .New ()
49
49
cfgViper .SetConfigType ("yaml" )
50
50
cfgViper .SetConfigFile (file )
51
- var err error
52
- if err = cfgViper .ReadInConfig (); err != nil {
53
- if errors .Is (err , viper.ConfigFileNotFoundError {}) {
51
+ var cfgViperReadInConfigErr error
52
+ if cfgViperReadInConfigErr = cfgViper .ReadInConfig (); cfgViperReadInConfigErr != nil {
53
+ if errors .Is (cfgViperReadInConfigErr , viper.ConfigFileNotFoundError {}) {
54
54
klog .InfoS ("Options configuration file not found at startup" , "file" , file )
55
- } else if _ , err = os .Stat (filepath .Clean (file )); os .IsNotExist (err ) {
55
+ } else if _ , isNotExisterr : = os .Stat (filepath .Clean (file )); os .IsNotExist (isNotExisterr ) {
56
56
// TODO: Remove this check once viper.ConfigFileNotFoundError is working as expected, see this issue -
57
57
// https://github.com/spf13/viper/issues/1783
58
58
klog .InfoS ("Options configuration file not found at startup" , "file" , file )
59
59
} else {
60
- klog .ErrorS (err , "Error reading options configuration file" , "file" , file )
60
+ klog .ErrorS (cfgViperReadInConfigErr , "Error reading options configuration file" , "file" , file )
61
61
}
62
62
if ! opts .ContinueWithoutConfig {
63
63
klog .FlushAndExit (klog .ExitFlushTimeout , 1 )
@@ -73,7 +73,7 @@ func RunKubeStateMetricsWrapper(opts *options.Options) {
73
73
})
74
74
cfgViper .WatchConfig ()
75
75
76
- if err == nil {
76
+ if cfgViperReadInConfigErr == nil {
77
77
// Merge configFile values with opts so we get the CustomResourceConfigFile from config as well
78
78
configFile , err := os .ReadFile (filepath .Clean (file ))
79
79
if err != nil {
0 commit comments