[#44] node: Support multiple configs
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
337049b2ce
commit
87e69b9349
5 changed files with 141 additions and 2 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/internal"
|
||||
"github.com/TrueCloudLab/frostfs-node/pkg/util/config"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
|
@ -54,6 +55,12 @@ func New(_ Prm, opts ...Option) *Config {
|
|||
}
|
||||
}
|
||||
|
||||
if o.configDir != "" {
|
||||
if err := config.ReadConfigDir(v, o.configDir); err != nil {
|
||||
panic(fmt.Errorf("failed to read config dir: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
return &Config{
|
||||
v: v,
|
||||
opts: *o,
|
||||
|
@ -69,5 +76,11 @@ func (x *Config) Reload() error {
|
|||
}
|
||||
}
|
||||
|
||||
if x.opts.configDir != "" {
|
||||
if err := config.ReadConfigDir(x.v, x.opts.configDir); err != nil {
|
||||
return fmt.Errorf("rereading configuration dir: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package config
|
||||
|
||||
type opts struct {
|
||||
path string
|
||||
path string
|
||||
configDir string
|
||||
}
|
||||
|
||||
func defaultOpts() *opts {
|
||||
|
@ -18,3 +19,11 @@ func WithConfigFile(path string) Option {
|
|||
o.path = path
|
||||
}
|
||||
}
|
||||
|
||||
// WithConfigDir returns an option to set the system path
|
||||
// to the directory with configuration files.
|
||||
func WithConfigDir(path string) Option {
|
||||
return func(o *opts) {
|
||||
o.configDir = path
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ func fatalOnErrDetails(details string, err error) {
|
|||
|
||||
func main() {
|
||||
configFile := flag.String("config", "", "path to config")
|
||||
configDir := flag.String("config-dir", "", "path to config directory")
|
||||
versionFlag := flag.Bool("version", false, "frostfs node version")
|
||||
dryRunFlag := flag.Bool("check", false, "validate configuration and exit")
|
||||
flag.Parse()
|
||||
|
@ -44,7 +45,7 @@ func main() {
|
|||
os.Exit(SuccessReturnCode)
|
||||
}
|
||||
|
||||
appCfg := config.New(config.Prm{}, config.WithConfigFile(*configFile))
|
||||
appCfg := config.New(config.Prm{}, config.WithConfigFile(*configFile), config.WithConfigDir(*configDir))
|
||||
|
||||
err := validateConfig(appCfg)
|
||||
fatalOnErr(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue