This commit is contained in:
mr
2026-03-26 11:14:29 +01:00
parent c1609ea9d9
commit a8fa18520c
16 changed files with 730 additions and 261 deletions

View File

@@ -2,21 +2,23 @@ package conf
import (
"sync"
"github.com/beego/beego/logs"
"github.com/goraz/onion"
)
type Config struct {
MonitorPath string
Logs string
KubeHost string
KubePort string
KubeCA string
KubeCert string
KubeData string
KubeNamespace string
KubeImage string
MonitorPath string
Logs string
Mode string
KubeHost string
KubePort string
KubeCA string
KubeCert string
KubeData string
KubeNamespace string
KubeImage string
// PrepLeadSeconds is how many seconds before the scheduled start oc-monitord
// is launched so it can complete pre-pull + infra setup before the actual
// execution time. Default: 120s (2 min).
PrepLeadSeconds int
}
var instance *Config
@@ -24,32 +26,6 @@ var once sync.Once
const defaultConfigFile = "/etc/oc/schedulerd.json"
func init() {
configFile := ""
var o *onion.Onion
l3 := onion.NewEnvLayerPrefix("_", "OCSCHEDULERD_")
l2, err := onion.NewFileLayer(defaultConfigFile, nil)
if err == nil {
logs.Info("Config file found : " + defaultConfigFile)
configFile = defaultConfigFile
}
if configFile == "" || l2 == nil {
logs.Info("No config file found, using env")
o = onion.New(l3)
} else {
o = onion.New(l2, l3)
}
GetConfig().MonitorPath = o.GetStringDefault("MONITORD_PATH", "../oc-monitord/oc-monitord")
GetConfig().KubeHost = o.GetStringDefault("KUBE_HOST", "")
GetConfig().KubePort = o.GetStringDefault("KUBE_PORT", "6443")
GetConfig().KubeCA = o.GetStringDefault("KUBE_CA", "")
GetConfig().KubeCert = o.GetStringDefault("KUBE_CERT", "")
GetConfig().KubeData = o.GetStringDefault("KUBE_DATA", "")
GetConfig().KubeNamespace = o.GetStringDefault("KUBE_NAMESPACE", "default")
GetConfig().KubeImage = o.GetStringDefault("KUBE_IMAGE", "oc-monitord")
}
func GetConfig() *Config {
once.Do(func() {
instance = &Config{}