Skip to content

Commit 12f155d

Browse files
committed
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 <sgrunert@redhat.com>
1 parent a255ba0 commit 12f155d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pkg/common/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"os"
2323
"path/filepath"
2424
"time"
25+
26+
"github.com/sirupsen/logrus"
2527
)
2628

2729
// ServerConfiguration is the config for connecting to and using a CRI server.
@@ -50,8 +52,9 @@ func GetServerConfigFromFile(configFileName, currentDir string) (*ServerConfigur
5052
// If the config file was not found, try looking in the program's
5153
// directory as a fallback. This is to accommodate where the config file
5254
// is placed with the cri tools binary.
53-
configFileName = filepath.Join(filepath.Dir(currentDir), "crictl.yaml")
54-
if _, err := os.Stat(configFileName); err != nil {
55+
nextConfigFileName := filepath.Join(filepath.Dir(currentDir), "crictl.yaml")
56+
logrus.Warnf("Config %q does not exist, trying next: %q", configFileName, nextConfigFileName)
57+
if _, err := os.Stat(nextConfigFileName); err != nil {
5558
return nil, fmt.Errorf("load config file: %w", err)
5659
}
5760
}

0 commit comments

Comments
 (0)