fix: host add a local config file (#18936)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2023-12-08 21:26:28 +08:00
committed by GitHub
parent fa83705414
commit 43b2ad2972

View File

@@ -17,6 +17,9 @@ package options
import (
"os"
"yunion.io/x/log"
"yunion.io/x/structarg"
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
"yunion.io/x/onecloud/pkg/util/fileutils2"
)
@@ -38,6 +41,7 @@ type SHostOptions struct {
SHostBaseOptions
CommonConfigFile string `help:"common config file for container"`
LocalConfigFile string `help:"local config file" default:"/etc/yunion/host_local.conf"`
HostType string `help:"Host server type, either hypervisor or kubelet" default:"hypervisor"`
ListenInterface string `help:"Master address of host server"`
@@ -189,6 +193,17 @@ func Parse() (hostOpts SHostOptions) {
// keep base options
hostOpts.BaseOptions.BaseOptions = baseOpt
}
if len(hostOpts.LocalConfigFile) > 0 && fileutils2.Exists(hostOpts.LocalConfigFile) {
log.Infof("Use local configuration file: %s", hostOpts.Config)
parser, err := structarg.NewArgumentParser(&hostOpts, "", "", "")
if err != nil {
log.Fatalf("fail to create local parse %s", err)
}
err = parser.ParseFile(hostOpts.LocalConfigFile)
if err != nil {
log.Fatalf("Parse local configuration file: %v", err)
}
}
return hostOpts
}