Skip to content

Commit

Permalink
Add warning log message about which config files to try
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
saschagrunert committed Oct 24, 2024
1 parent a255ba0 commit 12f155d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 12f155d

Please sign in to comment.