-
Notifications
You must be signed in to change notification settings - Fork 13
/
kubernetes.go
48 lines (39 loc) · 1.18 KB
/
kubernetes.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
package registry
import (
"errors"
"os"
"path"
"github.com/sarulabs/di"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
"github.com/coretrix/hitrix/service/component/kubernetes"
)
func ServiceProviderKubernetes() *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.KubernetesService,
Build: func(ctn di.Container) (interface{}, error) {
configService := ctn.Get(service.ConfigService).(config.IConfig)
configFilePath := ""
configFile, ok := configService.String("kubernetes.config_file")
if ok {
var configFolder string
if path.IsAbs(configFile) {
configFilePath = configFile
} else {
appFolder, hasConfigFolder := os.LookupEnv("APP_FOLDER")
if !hasConfigFolder {
configFolder = ctn.Get("config_directory").(string)
} else {
configFolder = appFolder + "/config"
}
configFilePath = path.Join(configFolder, configFile)
}
}
environment, ok := configService.String("kubernetes.environment")
if !ok {
return nil, errors.New("missing kubernetes.environment")
}
return kubernetes.NewKubernetes(configFilePath, environment), nil
},
}
}