Configure nodes.conf path dynamically from config

Removes the use of init() to initialize the variable.

- Closes: #1596
- See also: #1569

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-12-12 12:11:04 -07:00
parent b0d0e26b4a
commit a80ba8ee01
30 changed files with 78 additions and 203 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"encoding/gob"
"os"
"path"
"sort"
"dario.cat/mergo"
@@ -14,23 +13,13 @@ import (
"gopkg.in/yaml.v3"
)
var (
ConfigFile string
)
func init() {
conf := warewulfconf.Get()
if ConfigFile == "" {
ConfigFile = path.Join(conf.Paths.Sysconfdir, "warewulf/nodes.conf")
}
}
/*
Creates a new nodeDb object from the on-disk configuration
*/
func New() (NodesYaml, error) {
wwlog.Verbose("Opening node configuration file: %s", ConfigFile)
data, err := os.ReadFile(ConfigFile)
nodesConf := warewulfconf.Get().Paths.NodesConf()
wwlog.Verbose("Opening node configuration file: %s", nodesConf)
data, err := os.ReadFile(nodesConf)
if err != nil {
return NodesYaml{}, err
}