From 12f155d0bd3376313d08a72631e65ca183a20b62 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Thu, 24 Oct 2024 14:39:32 +0200 Subject: [PATCH] Add warning log message about which config files to try If the specified `--config` does not exist, then crictl will try the binary directory as last resort. We now log that behavior so that end users don't think unintentionally they specified the wrong `--config` value: ``` > sudo ./build/bin/linux/amd64/crictl --config ~/downloads/crictl.yaml config --list WARN[0000] Config "/home/x/downloads/crictl.yaml" does not exist, trying: "/home/s/go/src/sigs.k8s.io/cri-tools/build/bin/linux/amd64/crictl.yaml" FATA[0000] load config file: stat /home/sascha/go/src/sigs.k8s.io/cri-tools/build/bin/linux/amd64/crictl.yaml: no such file or directory ``` Signed-off-by: Sascha Grunert --- pkg/common/config.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/common/config.go b/pkg/common/config.go index a228693b5a..5cd165df8e 100644 --- a/pkg/common/config.go +++ b/pkg/common/config.go @@ -22,6 +22,8 @@ import ( "os" "path/filepath" "time" + + "github.com/sirupsen/logrus" ) // ServerConfiguration is the config for connecting to and using a CRI server. @@ -50,8 +52,9 @@ func GetServerConfigFromFile(configFileName, currentDir string) (*ServerConfigur // If the config file was not found, try looking in the program's // directory as a fallback. This is to accommodate where the config file // is placed with the cri tools binary. - configFileName = filepath.Join(filepath.Dir(currentDir), "crictl.yaml") - if _, err := os.Stat(configFileName); err != nil { + nextConfigFileName := filepath.Join(filepath.Dir(currentDir), "crictl.yaml") + logrus.Warnf("Config %q does not exist, trying next: %q", configFileName, nextConfigFileName) + if _, err := os.Stat(nextConfigFileName); err != nil { return nil, fmt.Errorf("load config file: %w", err) } }