Skip to content

Commit 378224d

Browse files
fix errors
1 parent 6c7f0ea commit 378224d

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

internal/wrapper.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ func RunKubeStateMetricsWrapper(opts *options.Options) {
5151
var cfgViperReadInConfigErr error
5252
if cfgViperReadInConfigErr = cfgViper.ReadInConfig(); cfgViperReadInConfigErr != nil {
5353
if errors.Is(cfgViperReadInConfigErr, viper.ConfigFileNotFoundError{}) {
54-
klog.InfoS("Options configuration file not found at startup", "file", file)
54+
klog.ErrorS(cfgViperReadInConfigErr, "Options configuration file not found at startup", "file", file)
5555
} else if _, isNotExisterr := os.Stat(filepath.Clean(file)); os.IsNotExist(isNotExisterr) {
5656
// TODO: Remove this check once viper.ConfigFileNotFoundError is working as expected, see this issue -
5757
// https://github.com/spf13/viper/issues/1783
58-
klog.InfoS("Options configuration file not found at startup", "file", file)
58+
klog.ErrorS(isNotExisterr, "Options configuration file not found at startup", "file", file)
5959
} else {
6060
klog.ErrorS(cfgViperReadInConfigErr, "Error reading options configuration file", "file", file)
6161
}
@@ -87,15 +87,15 @@ func RunKubeStateMetricsWrapper(opts *options.Options) {
8787
crcViper := viper.New()
8888
crcViper.SetConfigType("yaml")
8989
crcViper.SetConfigFile(opts.CustomResourceConfigFile)
90-
if err := crcViper.ReadInConfig(); err != nil {
91-
if errors.Is(err, viper.ConfigFileNotFoundError{}) {
92-
klog.InfoS("Custom resource configuration file not found at startup", "file", opts.CustomResourceConfigFile)
93-
} else if _, err = os.Stat(filepath.Clean(opts.CustomResourceConfigFile)); os.IsNotExist(err) {
90+
if cfgViperReadInConfigErr := crcViper.ReadInConfig(); cfgViperReadInConfigErr != nil {
91+
if errors.Is(cfgViperReadInConfigErr, viper.ConfigFileNotFoundError{}) {
92+
klog.ErrorS(cfgViperReadInConfigErr, "Custom resource configuration file not found at startup", "file", opts.CustomResourceConfigFile)
93+
} else if _, isNotExisterr = os.Stat(filepath.Clean(opts.CustomResourceConfigFile)); os.IsNotExist(isNotExisterr) {
9494
// Adding this check in addition to the above since viper.ConfigFileNotFoundError is not working as expected due to this issue -
9595
// https://github.com/spf13/viper/issues/1783
96-
klog.InfoS("Custom resource configuration file not found at startup", "file", opts.CustomResourceConfigFile)
96+
klog.ErrorS(isNotExisterr, "Custom resource configuration file not found at startup", "file", opts.CustomResourceConfigFile)
9797
} else {
98-
klog.ErrorS(err, "Error reading Custom resource configuration file", "file", opts.CustomResourceConfigFile)
98+
klog.ErrorS(cfgViperReadInConfigErr, "Error reading Custom resource configuration file", "file", opts.CustomResourceConfigFile)
9999
}
100100
if !opts.ContinueWithoutCustomResourceConfigFile {
101101
klog.FlushAndExit(klog.ExitFlushTimeout, 1)

pkg/app/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
128128
got := options.GetConfigFile(*opts)
129129
if got != "" {
130130
if _, err := os.Stat(filepath.Clean(got)); os.IsNotExist(err) {
131-
klog.InfoS("config file does not exist, ignoring", "file", got)
131+
klog.ErrorS(err, "config file does not exist, ignoring", "file", got)
132132
} else {
133133
configFile, err := os.ReadFile(filepath.Clean(got))
134134
if err != nil {
@@ -182,7 +182,7 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
182182

183183
if opts.CustomResourceConfigFile != "" {
184184
if _, err := os.Stat(filepath.Clean(opts.CustomResourceConfigFile)); os.IsNotExist(err) {
185-
klog.InfoS("config file does not exist,ignoring", "file", opts.CustomResourceConfigFile)
185+
klog.ErrorS(err, "config file does not exist, ignoring", "file", opts.CustomResourceConfigFile)
186186
} else {
187187
crcFile, err := os.ReadFile(filepath.Clean(opts.CustomResourceConfigFile))
188188
if err != nil {

0 commit comments

Comments
 (0)