-
Notifications
You must be signed in to change notification settings - Fork 53
/
config.go
41 lines (38 loc) · 932 Bytes
/
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
package cliutil
import (
"errors"
"os"
"github.com/rancher/opni/pkg/config"
"github.com/rancher/opni/pkg/config/meta"
"github.com/rancher/opni/pkg/logger"
"go.uber.org/zap"
)
func LoadConfigObjectsOrDie(
configLocation string,
lg logger.ExtendedSugaredLogger,
) meta.ObjectList {
if configLocation == "" {
// find config file
path, err := config.FindConfig()
if err != nil {
if errors.Is(err, config.ErrConfigNotFound) {
wd, _ := os.Getwd()
lg.Fatalf(`could not find a config file in ["%s","/etc/opni-monitoring"], and --config was not given`, wd)
}
lg.With(
zap.Error(err),
).Fatal("an error occurred while searching for a config file")
}
lg.With(
"path", path,
).Info("using config file")
configLocation = path
}
objects, err := config.LoadObjectsFromFile(configLocation)
if err != nil {
lg.With(
zap.Error(err),
).Fatal("failed to load config")
}
return objects
}