make the configuration to be based in warewulf.conf

defaults will be se by the Makefile

Signed-off-by: Christian Goll <cgoll@suse.de>
This commit is contained in:
Christian Goll
2023-03-03 16:02:41 +01:00
parent f2eff0f7b8
commit 4deae97bc8
18 changed files with 130 additions and 174 deletions

1
.gitignore vendored
View File

@@ -25,6 +25,7 @@
/etc/bash_completion.d/
warewulf.spec
internal/pkg/buildconfig/setconfigs.go
internal/pkg/warewulfconf/buildconfig.go
include/systemd/warewulfd.service
_dist/
config

View File

@@ -231,19 +231,11 @@ man_pages: wwctl
cp docs/man/man5/*.5 ./man_pages/
cd man_pages; for i in wwctl*1 *.5; do echo "Compressing manpage: $$i"; gzip --force $$i; done
config_defaults: vendor cmd/config_defaults/config_defaults.go
cd cmd/config_defaults && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\
-X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\
-mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../config_defaults
update_configuration: vendor cmd/update_configuration/update_configuration.go
cd cmd/update_configuration && go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/warewulfconf.ConfigFile=./etc/warewulf.conf'\
-X 'github.com/hpcng/warewulf/internal/pkg/node.ConfigFile=./etc/nodes.conf'"\
-mod vendor -tags "$(WW_GO_BUILD_TAGS)" -o ../../update_configuration
warewulfconf: config_defaults
./config_defaults
dist: vendor config
rm -rf .dist/$(WAREWULF)-$(VERSION) $(WAREWULF)-$(VERSION).tar.gz
mkdir -p .dist/$(WAREWULF)-$(VERSION)

View File

@@ -16,7 +16,6 @@ import (
"github.com/coreos/go-systemd/daemon"
"github.com/google/uuid"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/pidfile"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
@@ -50,10 +49,7 @@ func GetRootCommand() *cobra.Command {
}
func CobraRunE(cmd *cobra.Command, args []string) error {
conf, err := warewulfconf.New()
if err != nil {
return err
}
conf := warewulfconf.New()
pid, err := pidfile.Write(PIDFile)
if err != nil && pid == -1 {

View File

@@ -1,98 +0,0 @@
package buildconfig
import "github.com/hpcng/warewulf/internal/pkg/wwlog"
const WWVer = 43
var (
bindir string = "UNDEF"
sysconfdir string = "UNDEF"
localstatedir string = "UNDEF"
srvdir string = "UNDEF"
tftpdir string = "UNDEF"
firewallddir string = "UNDEF"
systemddir string = "UNDEF"
wwoverlaydir string = "UNDEF"
wwchrootdir string = "UNDEF"
wwprovisiondir string = "UNDEF"
version string = "UNDEF"
release string = "UNDEF"
wwclientdir string = "UNDEF"
datadir string = "UNDEF"
tmpdir string = "UNDEF"
)
func BINDIR() string {
wwlog.Debug("BINDIR = '%s'", bindir)
return bindir
}
func DATADIR() string {
wwlog.Debug("DATADIR = '%s'", datadir)
return datadir
}
func SYSCONFDIR() string {
wwlog.Debug("SYSCONFDIR = '%s'", sysconfdir)
return sysconfdir
}
func LOCALSTATEDIR() string {
wwlog.Debug("LOCALSTATEDIR = '%s'", localstatedir)
return localstatedir
}
func SRVDIR() string {
wwlog.Debug("SRVDIR = '%s'", srvdir)
return srvdir
}
func TFTPDIR() string {
wwlog.Debug("TFTPDIR = '%s'", tftpdir)
return tftpdir
}
func FIREWALLDDIR() string {
wwlog.Debug("FIREWALLDDIR = '%s'", firewallddir)
return firewallddir
}
func SYSTEMDDIR() string {
wwlog.Debug("SYSTEMDDIR = '%s'", systemddir)
return systemddir
}
func WWOVERLAYDIR() string {
wwlog.Debug("WWOVERLAYDIR = '%s'", wwoverlaydir)
return wwoverlaydir
}
func WWCHROOTDIR() string {
wwlog.Debug("WWCHROOTDIR = '%s'", wwchrootdir)
return wwchrootdir
}
func WWPROVISIONDIR() string {
wwlog.Debug("WWPROVISIONDIR = '%s'", wwprovisiondir)
return wwprovisiondir
}
func VERSION() string {
wwlog.Debug("VERSION = '%s'", version)
return version
}
func RELEASE() string {
wwlog.Debug("RELEASE = '%s'", release)
return release
}
func WWCLIENTDIR() string {
wwlog.Debug("WWCLIENTDIR = '%s'", wwclientdir)
return wwclientdir
}
func TMPDIR() string {
wwlog.Debug("TMPDIR = '%s'", tmpdir)
return tmpdir
}

View File

@@ -1,19 +0,0 @@
package buildconfig
func init() {
bindir = "@BINDIR@"
sysconfdir = "@SYSCONFDIR@"
datadir = "@DATADIR@"
localstatedir = "@LOCALSTATEDIR@"
srvdir = "@SRVDIR@"
tftpdir = "@TFTPDIR@"
firewallddir = "@FIREWALLDDIR@"
systemddir = "@SYSTEMDDIR@"
wwoverlaydir = "@WWOVERLAYDIR@"
wwchrootdir = "@WWCHROOTDIR@"
wwprovisiondir = "@WWPROVISIONDIR@"
version = "@VERSION@"
release = "@RELEASE@"
wwclientdir = "@WWCLIENTDIR@"
tmpdir = "@TMPDIR@"
}

View File

@@ -5,8 +5,8 @@ import (
"os"
"path"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
)
@@ -14,10 +14,10 @@ import (
func SSH() error {
if os.Getuid() == 0 {
fmt.Printf("Updating system keys\n")
conf := warewulfconf.New()
wwkeydir := path.Join(conf.SYSCONFDIR(), "warewulf/keys") + "/"
wwkeydir := path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys") + "/"
err := os.MkdirAll(path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys"), 0755)
err := os.MkdirAll(path.Join(conf.SYSCONFDIR(), "warewulf/keys"), 0755)
if err != nil {
wwlog.Error("Could not create base directory: %s", err)
os.Exit(1)

View File

@@ -5,15 +5,14 @@ import (
"os"
"path"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
func TFTP() error {
var tftpdir string = path.Join(buildconfig.TFTPDIR(), "warewulf")
controller := warewulfconf.New()
var tftpdir string = path.Join(controller.TFTPDIR(), "warewulf")
err := os.MkdirAll(tftpdir, 0755)
if err != nil {
@@ -28,7 +27,7 @@ func TFTP() error {
continue
}
copyCheck[f] = true
err = util.SafeCopyFile(path.Join(buildconfig.DATADIR(), f), path.Join(tftpdir, f))
err = util.SafeCopyFile(path.Join(controller.DATADIR(), f), path.Join(tftpdir, f))
if err != nil {
wwlog.Warn("ipxe binary could not be copied, booting may not work: %s", err)
}

View File

@@ -3,11 +3,12 @@ package container
import (
"path"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
)
func SourceParentDir() string {
return buildconfig.WWCHROOTDIR()
conf := warewulfconf.New()
return conf.WWCHROOTDIR()
}
func SourceDir(name string) string {
@@ -19,7 +20,8 @@ func RootFsDir(name string) string {
}
func ImageParentDir() string {
return path.Join(buildconfig.WWPROVISIONDIR(), "container/")
conf := warewulfconf.New()
return path.Join(conf.WWPROVISIONDIR(), "container/")
}
func ImageFile(name string) string {

View File

@@ -11,8 +11,8 @@ import (
"github.com/pkg/errors"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
@@ -28,7 +28,8 @@ var (
)
func KernelImageTopDir() string {
return path.Join(buildconfig.WWPROVISIONDIR(), "kernel")
conf := warewulfconf.New()
return path.Join(conf.WWPROVISIONDIR(), "kernel")
}
func KernelImage(kernelName string) string {

View File

@@ -7,7 +7,7 @@ import (
"sort"
"strings"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v2"
@@ -37,11 +37,12 @@ defaultnode:
netmask: 255.255.255.0`
func init() {
conf := warewulfconf.New()
if ConfigFile == "" {
ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/nodes.conf")
ConfigFile = path.Join(conf.SYSCONFDIR(), "warewulf/nodes.conf")
}
if DefaultConfig == "" {
DefaultConfig = path.Join(buildconfig.SYSCONFDIR(), "warewulf/defaults.conf")
DefaultConfig = path.Join(conf.SYSCONFDIR(), "warewulf/defaults.conf")
}
}

View File

@@ -5,11 +5,12 @@ import (
"path"
"strings"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
)
func OverlaySourceTopDir() string {
return buildconfig.WWOVERLAYDIR()
conf := warewulfconf.New()
return conf.WWOVERLAYDIR()
}
/*
@@ -30,5 +31,6 @@ func OverlaySourceDir(overlayName string) string {
Returns the overlay name of the image for a given node
*/
func OverlayImage(nodeName string, overlayName []string) string {
return path.Join(buildconfig.WWPROVISIONDIR(), "overlays/", nodeName, strings.Join(overlayName, "-")+".img")
conf := warewulfconf.New()
return path.Join(conf.WWPROVISIONDIR(), "overlays/", nodeName, strings.Join(overlayName, "-")+".img")
}

View File

@@ -6,9 +6,9 @@ import (
"path"
"strings"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/container"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
)
@@ -18,8 +18,9 @@ the path is relative to SYSCONFDIR.
Templates in the file are no evaluated.
*/
func templateFileInclude(inc string) string {
conf := warewulfconf.New()
if !strings.HasPrefix(inc, "/") {
inc = path.Join(buildconfig.SYSCONFDIR(), "warewulf", inc)
inc = path.Join(conf.SYSCONFDIR(), "warewulf", inc)
}
wwlog.Debug("Including file into template: %s", inc)
content, err := os.ReadFile(inc)
@@ -35,8 +36,9 @@ is the file to read, the second the abort string
Templates in the file are no evaluated.
*/
func templateFileBlock(inc string, abortStr string) (string, error) {
conf := warewulfconf.New()
if !strings.HasPrefix(inc, "/") {
inc = path.Join(buildconfig.SYSCONFDIR(), "warewulf", inc)
inc = path.Join(conf.SYSCONFDIR(), "warewulf", inc)
}
wwlog.Debug("Including file block into template: %s", inc)
readFile, err := os.Open(inc)

View File

@@ -4,14 +4,15 @@ import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/api/routes/wwapiv1"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/warewulfconf"
)
/*
Return the version of wwctl
*/
func GetVersion() string {
return fmt.Sprintf("%s-%s", buildconfig.VERSION(), buildconfig.RELEASE())
conf := warewulfconf.New()
return fmt.Sprintf("%s-%s", conf.VERSION(), conf.RELEASE())
}
/*

View File

@@ -0,0 +1,18 @@
package warewulfconf
type BuildConfig struct {
bindir string `default:"@BINDIR@"`
sysconfdir string `default:"@SYSCONFDIR@"`
datadir string `default:"@DATADIR@"`
localstatedir string `default:"@LOCALSTATEDIR@"`
srvdir string `default:"@SRVDIR@"`
tftpdir string `default:"@TFTPDIR@"`
firewallddir string `default:"@FIREWALLDDIR@"`
systemddir string `default:"@SYSTEMDDIR@"`
wwoverlaydir string `default:"@WWOVERLAYDIR@"`
wwchrootdir string `default:"@WWCHROOTDIR@"`
wwprovisiondir string `default:"@WWPROVISIONDIR@"`
version string `default:"@VERSION@"`
release string `default:"@RELEASE@"`
wwclientdir string `default:"@WWCLIENTDIR@"`
}

View File

@@ -5,11 +5,9 @@ import (
"fmt"
"net"
"os"
"path"
"github.com/brotherpowers/ipsubnet"
"github.com/creasty/defaults"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"gopkg.in/yaml.v2"
)
@@ -18,18 +16,6 @@ var cachedConf ControllerConf
var ConfigFile string
/*
Get the configFile location from the os.ev if set
*/
func init() {
if ConfigFile == "" {
ConfigFile = os.Getenv("WARWULFCONF")
}
if ConfigFile == "" {
ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/warewulf.conf")
}
}
/*
Creates a new empty ControllerConf object, returns a cached
one if called in a nother context.
@@ -42,10 +28,9 @@ func New() (ret ControllerConf) {
ret.Dhcp = new(DhcpConf)
ret.Tftp = new(TftpConf)
ret.Nfs = new(NfsConf)
err := defaults.Set(&ret)
if err != nil {
ret.setDynamicDefaults()
}
ret.Paths = new(BuildConfig)
_ = defaults.Set(&ret)
ret.setDynamicDefaults()
cachedConf = ret
cachedConf.current = true

View File

@@ -18,6 +18,7 @@ type ControllerConf struct {
Tftp *TftpConf `yaml:"tftp"`
Nfs *NfsConf `yaml:"nfs"`
MountsContainer []*MountEntry `yaml:"container mounts" default:"[{\"source\": \"/etc/resolv.conf\", \"dest\": \"/etc/resolv.conf\"}]"`
Paths *BuildConfig `yaml:"mypaths"`
current bool
}

View File

@@ -0,0 +1,73 @@
package warewulfconf
import "github.com/hpcng/warewulf/internal/pkg/wwlog"
func (conf *ControllerConf) BINDIR() string {
wwlog.Debug("BINDIR = '%s'", conf.Paths.bindir)
return conf.Paths.bindir
}
func (conf *ControllerConf) DATADIR() string {
wwlog.Debug("DATADIR = '%s'", conf.Paths.datadir)
return conf.Paths.datadir
}
func (conf *ControllerConf) SYSCONFDIR() string {
wwlog.Debug("SYSCONFDIR = '%s'", conf.Paths.sysconfdir)
return conf.Paths.sysconfdir
}
func (conf *ControllerConf) LOCALSTATEDIR() string {
wwlog.Debug("LOCALSTATEDIR = '%s'", conf.Paths.localstatedir)
return conf.Paths.localstatedir
}
func (conf *ControllerConf) SRVDIR() string {
wwlog.Debug("SRVDIR = '%s'", conf.Paths.srvdir)
return conf.Paths.srvdir
}
func (conf *ControllerConf) TFTPDIR() string {
wwlog.Debug("TFTPDIR = '%s'", conf.Paths.tftpdir)
return conf.Paths.tftpdir
}
func (conf *ControllerConf) FIREWALLDDIR() string {
wwlog.Debug("FIREWALLDDIR = '%s'", conf.Paths.firewallddir)
return conf.Paths.firewallddir
}
func (conf *ControllerConf) SYSTEMDDIR() string {
wwlog.Debug("SYSTEMDDIR = '%s'", conf.Paths.systemddir)
return conf.Paths.systemddir
}
func (conf *ControllerConf) WWOVERLAYDIR() string {
wwlog.Debug("WWOVERLAYDIR = '%s'", conf.Paths.wwoverlaydir)
return conf.Paths.wwoverlaydir
}
func (conf *ControllerConf) WWCHROOTDIR() string {
wwlog.Debug("WWCHROOTDIR = '%s'", conf.Paths.wwchrootdir)
return conf.Paths.wwchrootdir
}
func (conf *ControllerConf) WWPROVISIONDIR() string {
wwlog.Debug("WWPROVISIONDIR = '%s'", conf.Paths.wwprovisiondir)
return conf.Paths.wwprovisiondir
}
func (conf *ControllerConf) VERSION() string {
wwlog.Debug("VERSION = '%s'", conf.Paths.version)
return conf.Paths.version
}
func (conf *ControllerConf) RELEASE() string {
wwlog.Debug("RELEASE = '%s'", conf.Paths.release)
return conf.Paths.release
}
func (conf *ControllerConf) WWCLIENTDIR() string {
wwlog.Debug("WWCLIENTDIR = '%s'", conf.Paths.wwclientdir)
return conf.Paths.wwclientdir
}

View File

@@ -7,7 +7,6 @@ import (
"strconv"
"text/template"
"github.com/hpcng/warewulf/internal/pkg/buildconfig"
"github.com/hpcng/warewulf/internal/pkg/container"
"github.com/hpcng/warewulf/internal/pkg/kernel"
"github.com/hpcng/warewulf/internal/pkg/util"
@@ -80,13 +79,13 @@ func ProvisionSend(w http.ResponseWriter, req *http.Request) {
if !node.Id.Defined() {
wwlog.Error("%s (unknown/unconfigured node)", rinfo.hwaddr)
if rinfo.stage == "ipxe" {
stage_file = path.Join(buildconfig.SYSCONFDIR(), "/warewulf/ipxe/unconfigured.ipxe")
stage_file = path.Join(conf.SYSCONFDIR(), "/warewulf/ipxe/unconfigured.ipxe")
tmpl_data = iPxeTemplate{
Hwaddr: rinfo.hwaddr}
}
} else if rinfo.stage == "ipxe" {
stage_file = path.Join(buildconfig.SYSCONFDIR(), "warewulf/ipxe/"+node.Ipxe.Get()+".ipxe")
stage_file = path.Join(conf.SYSCONFDIR(), "warewulf/ipxe/"+node.Ipxe.Get()+".ipxe")
tmpl_data = iPxeTemplate{
Id: node.Id.Get(),
Cluster: node.ClusterName.Get(),