-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
50 lines (42 loc) · 1.21 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package commands
import (
"os"
config "github.com/kubeflow/arena/pkg/util/config"
homedir "github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
)
const (
RecommendedConfigPathEnvVar = "ARENA_CONFIG"
DefaultArenaConfigPath = "~/.arena/config"
)
var (
arenaConfigs map[string]string
alreadyInitArenaConfig bool
)
// loadArenaConifg returns configs in map
func loadArenaConifg() {
log.Debugf("init arena config")
if alreadyInitArenaConfig {
return
}
alreadyInitArenaConfig = true
arenaConfigs = make(map[string]string)
envVarFileName := os.Getenv(RecommendedConfigPathEnvVar)
_, err := os.Stat(envVarFileName)
if err != nil {
log.Debugf("illegal arena config file: %s due to %v", envVarFileName, err)
envVarFileName, err = homedir.Expand(DefaultArenaConfigPath)
if err != nil {
log.Debugf("fail to get arena config file: %s due to %v", envVarFileName, err)
return
}
}
_, err = os.Stat(envVarFileName)
if err != nil {
log.Debugf("illegal arena config file: %s due to %v", envVarFileName, err)
return
}
log.Debugf("load arena config file %s", envVarFileName)
arenaConfigs = config.ReadConfigFile(envVarFileName)
log.Debugf("arena configs: %v", arenaConfigs)
}