Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search program directory for config as fallback #463

Merged
merged 1 commit into from
May 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions cmd/crictl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"fmt"
"os"
"path/filepath"
"sort"
"time"

Expand Down Expand Up @@ -128,7 +129,7 @@ func main() {
Name: "config, c",
EnvVar: "CRI_CONFIG_FILE",
Value: defaultConfigPath,
Usage: "Location of the client config file",
Usage: "Location of the client config file. If not specified and the default does not exist, the program's directory is searched as well",
},
cli.StringFlag{
Name: "runtime-endpoint, r",
Expand Down Expand Up @@ -160,8 +161,20 @@ func main() {
} else {
if context.IsSet("config") || !os.IsNotExist(err) {
// note: the absence of default config file is normal case
// when user have not setted it in cli
logrus.Fatalf("Falied to load config file: %v", err)
// when user have not set it in cli
logrus.Fatalf("Failed to load config file: %v", err)
} else {
// If the default config was not found, and the user didn't
// explicitly specify a config, try looking in the program's
// directory as a fallback. This is a convenience for
// deployments of crictl so they don't have to place a file in a
// global location.
configFile = filepath.Join(filepath.Dir(os.Args[0]), "crictl.yaml")
if _, err := os.Stat(configFile); err == nil {
isUseConfig = true
} else if !os.IsNotExist(err) {
logrus.Fatalf("Failed to load config file: %v", err)
}
}
}

Expand Down