Remove SetDynamicDefaults from Parse

Signed-off-by: Jonathon Anderson <janderson@ciq.co>
This commit is contained in:
Jonathon Anderson
2023-04-14 18:59:39 -06:00
parent 387cd0f7be
commit cfdf179e16
2 changed files with 12 additions and 13 deletions

View File

@@ -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
}

View File

@@ -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
}