From cfdf179e167b2cf972c9ae43e672de81292e0b3c Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Fri, 14 Apr 2023 18:59:39 -0600 Subject: [PATCH] Remove SetDynamicDefaults from Parse Signed-off-by: Jonathon Anderson --- internal/app/wwctl/root.go | 6 ++++-- internal/pkg/config/root.go | 19 ++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/internal/app/wwctl/root.go b/internal/app/wwctl/root.go index 282615b2..e694b09f 100644 --- a/internal/app/wwctl/root.go +++ b/internal/app/wwctl/root.go @@ -85,8 +85,10 @@ func rootPersistentPreRunE(cmd *cobra.Command, args []string) (err error) { } else { err = conf.Read(warewulfconf.ConfigFile) } - } else { - err = conf.SetDynamicDefaults() } + if err != nil { + return + } + err = conf.SetDynamicDefaults() return } diff --git a/internal/pkg/config/root.go b/internal/pkg/config/root.go index 89e418e0..822df5c0 100644 --- a/internal/pkg/config/root.go +++ b/internal/pkg/config/root.go @@ -76,19 +76,22 @@ func Get() (*RootConf) { } -// ReadConf populates [RootConf] with the values from a configuration +// Read populates [RootConf] with the values from a configuration // file. func (conf *RootConf) Read(confFileName string) (error) { wwlog.Debug("Reading warewulf.conf from: %s", confFileName) - data, err := os.ReadFile(confFileName) - if err != nil { + if data, err := os.ReadFile(confFileName); err != nil { return err + } else if err := conf.Parse(data); err != nil { + return err + } else { + conf.fromFile = true + return nil } - return conf.Parse(data) } -// Read populates [RootConf] with the values from a yaml document. +// Parse populates [RootConf] with the values from a yaml document. func (conf *RootConf) Parse(data []byte) (error) { // ipxe binaries are merged not overwritten, store defaults separate defIpxe := make(map[string]string) @@ -99,14 +102,9 @@ func (conf *RootConf) Parse(data []byte) (error) { if err := yaml.Unmarshal(data, &conf); err != nil { return err } - if err := conf.SetDynamicDefaults(); err != nil { - return err - } if len(conf.Tftp.IpxeBinaries) == 0 { conf.Tftp.IpxeBinaries = defIpxe } - cachedConf = *conf - cachedConf.fromFile = true return nil } @@ -174,7 +172,6 @@ func (conf *RootConf) SetDynamicDefaults() (err error) { return errors.New("invalid ipv6 network size") } } - cachedConf = *conf return }