Skip to content

Commit 3d02558

Browse files
committed
Fixed loading config path
1 parent 2be87d0 commit 3d02558

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

cmd/agent/main.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,24 @@ func initConfig() {
7171
config = nebula.NewConfig(l)
7272

7373
if configPath == "" {
74-
configPath = getConfigDir()
74+
configPath = getConfigPath()
7575
}
7676

7777
if configPath != "" {
78-
configDir = filepath.Dir(configPath)
79-
err := config.Load(configPath)
78+
79+
configPathInfo, err := os.Stat(configPath)
80+
if err != nil {
81+
l.WithError(err).Errorln("failed to load config")
82+
os.Exit(1)
83+
}
84+
85+
if configPathInfo.IsDir() {
86+
configDir = configPath
87+
} else {
88+
configDir = filepath.Dir(configPath)
89+
}
90+
91+
err = config.Load(configPath)
8092
if err != nil {
8193
l.WithError(err).Errorln("failed to load config")
8294
os.Exit(1)
@@ -96,6 +108,8 @@ func initConfig() {
96108
l.Errorf("failed to detect config path")
97109
os.Exit(1)
98110
}
111+
l.Tracef("using config: %s", configPath)
112+
l.Tracef("using config dir: %s", configDir)
99113
}
100114

101115
func main() {

cmd/agent/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func dirExists(path string) (bool, os.FileInfo) {
2727
return fileinfo.IsDir(), fileinfo
2828
}
2929

30-
func getConfigDir() string {
30+
func getConfigPath() string {
3131
ok, _ := dirExists("/etc/nebula-provisioner")
3232
if ok {
3333
return "/etc/nebula-provisioner"

0 commit comments

Comments
 (0)