From ce43dfa0b77d0fb26e5023f17475e57de9f9ff98 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Mon, 6 Mar 2023 09:59:25 +0100 Subject: [PATCH] removed getters as configs must exportable Signed-off-by: Christian Goll --- .github/workflows/lint.yaml | 3 +- Makefile | 3 +- internal/app/api/wwapic/wwapic.go | 2 +- internal/app/api/wwapid/wwapid.go | 2 +- internal/app/api/wwapird/wwapird.go | 2 +- internal/app/wwclient/root.go | 4 +- internal/pkg/configure/ssh.go | 4 +- internal/pkg/configure/tftp.go | 4 +- internal/pkg/container/config.go | 4 +- internal/pkg/kernel/kernel.go | 2 +- internal/pkg/node/constructors.go | 4 +- internal/pkg/overlay/config.go | 4 +- internal/pkg/overlay/funcmap.go | 7 +- internal/pkg/version/version.go | 2 +- internal/pkg/warewulfconf/buildconfig.go.in | 8 +-- internal/pkg/warewulfconf/getter.go | 73 --------------------- internal/pkg/warewulfd/provision.go | 4 +- 17 files changed, 29 insertions(+), 103 deletions(-) delete mode 100644 internal/pkg/warewulfconf/getter.go diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 53901d02..3c6eafee 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -21,7 +21,8 @@ jobs: go: [ '1.17' ] steps: - uses: actions/checkout@v3 - + - name: Create config + run: make config - name: Setup go ${{ matrix.go }} uses: actions/setup-go@v3 with: diff --git a/Makefile b/Makefile index f1d08c92..cd7b20f7 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ export GOPROXY WW_GO_BUILD_TAGS := containers_image_openpgp containers_image_ostree # Default target -all: config vendor wwctl wwclient man_pages config_defaults wwapid wwapic wwapird +all: config vendor wwctl wwclient man_pages wwapid wwapic wwapird # Validate source and build all packages build: lint test-it vet all @@ -287,7 +287,6 @@ contclean: rm -f config rm -f Defaults.mk rm -rf $(TOOLS_DIR) - rm -f config_defaults rm -f update_configuration rm -f etc/wwapi{c,d,rd}.conf diff --git a/internal/app/api/wwapic/wwapic.go b/internal/app/api/wwapic/wwapic.go index bd35a973..36cfb002 100644 --- a/internal/app/api/wwapic/wwapic.go +++ b/internal/app/api/wwapic/wwapic.go @@ -27,7 +27,7 @@ func main() { conf := warewulfconf.New() // Read the config file. - config, err := apiconfig.NewClient(path.Join(conf.SYSCONFDIR(), "warewulf/wwapic.conf")) + config, err := apiconfig.NewClient(path.Join(conf.Paths.Sysconfdir, "warewulf/wwapic.conf")) if err != nil { log.Fatalf("err: %v", err) } diff --git a/internal/app/api/wwapid/wwapid.go b/internal/app/api/wwapid/wwapid.go index 0678114c..ce7457e5 100644 --- a/internal/app/api/wwapid/wwapid.go +++ b/internal/app/api/wwapid/wwapid.go @@ -36,7 +36,7 @@ func main() { conf := warewulfconf.New() // Read the config file. - config, err := apiconfig.NewServer(path.Join(conf.SYSCONFDIR(), "warewulf/wwapid.conf")) + config, err := apiconfig.NewServer(path.Join(conf.Paths.Sysconfdir, "warewulf/wwapid.conf")) if err != nil { log.Fatalf("err: %v", err) } diff --git a/internal/app/api/wwapird/wwapird.go b/internal/app/api/wwapird/wwapird.go index 13f12d4e..e9b210ac 100644 --- a/internal/app/api/wwapird/wwapird.go +++ b/internal/app/api/wwapird/wwapird.go @@ -31,7 +31,7 @@ func run() error { conf := warewulfconf.New() // Read the config file. - config, err := apiconfig.NewClientServer(path.Join(conf.SYSCONFDIR(), "warewulf/wwapird.conf")) + config, err := apiconfig.NewClientServer(path.Join(conf.Paths.Sysconfdir, "warewulf/wwapird.conf")) if err != nil { glog.Fatalf("Failed to read config file, err: %v", err) } diff --git a/internal/app/wwclient/root.go b/internal/app/wwclient/root.go index 72691595..b63f3f41 100644 --- a/internal/app/wwclient/root.go +++ b/internal/app/wwclient/root.go @@ -58,7 +58,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { return errors.New("found pidfile " + PIDFile + " not starting") } - if os.Args[0] == path.Join(conf.WWCLIENTDIR(), "wwclient") { + if os.Args[0] == path.Join(conf.Paths.WWClientdir, "wwclient") { err := os.Chdir("/") if err != nil { wwlog.Error("failed to change dir: %s", err) @@ -70,7 +70,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } else { fmt.Printf("Called via: %s\n", os.Args[0]) fmt.Printf("Runtime overlay is being put in '/warewulf/wwclient-test' rather than '/'\n") - fmt.Printf("For full functionality call with: %s\n", path.Join(conf.WWCLIENTDIR(), "wwclient")) + fmt.Printf("For full functionality call with: %s\n", path.Join(conf.Paths.WWClientdir, "wwclient")) err := os.MkdirAll("/warewulf/wwclient-test", 0755) if err != nil { wwlog.Error("failed to create dir: %s", err) diff --git a/internal/pkg/configure/ssh.go b/internal/pkg/configure/ssh.go index 0c60e053..10186bc2 100644 --- a/internal/pkg/configure/ssh.go +++ b/internal/pkg/configure/ssh.go @@ -15,9 +15,9 @@ 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(conf.Paths.Sysconfdir, "warewulf/keys") + "/" - err := os.MkdirAll(path.Join(conf.SYSCONFDIR(), "warewulf/keys"), 0755) + err := os.MkdirAll(path.Join(conf.Paths.Sysconfdir, "warewulf/keys"), 0755) if err != nil { wwlog.Error("Could not create base directory: %s", err) os.Exit(1) diff --git a/internal/pkg/configure/tftp.go b/internal/pkg/configure/tftp.go index 718a4030..74bed889 100644 --- a/internal/pkg/configure/tftp.go +++ b/internal/pkg/configure/tftp.go @@ -12,7 +12,7 @@ import ( func TFTP() error { controller := warewulfconf.New() - var tftpdir string = path.Join(controller.TFTPDIR(), "warewulf") + var tftpdir string = path.Join(controller.Paths.Tftpdir, "warewulf") err := os.MkdirAll(tftpdir, 0755) if err != nil { @@ -27,7 +27,7 @@ func TFTP() error { continue } copyCheck[f] = true - err = util.SafeCopyFile(path.Join(controller.DATADIR(), f), path.Join(tftpdir, f)) + err = util.SafeCopyFile(path.Join(controller.Paths.Datadir, f), path.Join(tftpdir, f)) if err != nil { wwlog.Warn("ipxe binary could not be copied, booting may not work: %s", err) } diff --git a/internal/pkg/container/config.go b/internal/pkg/container/config.go index ebbc8569..ecd751fa 100644 --- a/internal/pkg/container/config.go +++ b/internal/pkg/container/config.go @@ -8,7 +8,7 @@ import ( func SourceParentDir() string { conf := warewulfconf.New() - return conf.WWCHROOTDIR() + return conf.Paths.WWChrootdir } func SourceDir(name string) string { @@ -21,7 +21,7 @@ func RootFsDir(name string) string { func ImageParentDir() string { conf := warewulfconf.New() - return path.Join(conf.WWPROVISIONDIR(), "container/") + return path.Join(conf.Paths.WWProvisiondir, "container/") } func ImageFile(name string) string { diff --git a/internal/pkg/kernel/kernel.go b/internal/pkg/kernel/kernel.go index 14ce78a2..32a1da47 100644 --- a/internal/pkg/kernel/kernel.go +++ b/internal/pkg/kernel/kernel.go @@ -29,7 +29,7 @@ var ( func KernelImageTopDir() string { conf := warewulfconf.New() - return path.Join(conf.WWPROVISIONDIR(), "kernel") + return path.Join(conf.Paths.WWProvisiondir, "kernel") } func KernelImage(kernelName string) string { diff --git a/internal/pkg/node/constructors.go b/internal/pkg/node/constructors.go index 3d83f8df..bcf57d0b 100644 --- a/internal/pkg/node/constructors.go +++ b/internal/pkg/node/constructors.go @@ -39,10 +39,10 @@ defaultnode: func init() { conf := warewulfconf.New() if ConfigFile == "" { - ConfigFile = path.Join(conf.SYSCONFDIR(), "warewulf/nodes.conf") + ConfigFile = path.Join(conf.Paths.Sysconfdir, "warewulf/nodes.conf") } if DefaultConfig == "" { - DefaultConfig = path.Join(conf.SYSCONFDIR(), "warewulf/defaults.conf") + DefaultConfig = path.Join(conf.Paths.Sysconfdir, "warewulf/defaults.conf") } } diff --git a/internal/pkg/overlay/config.go b/internal/pkg/overlay/config.go index 3f5b1bd4..91452e4a 100644 --- a/internal/pkg/overlay/config.go +++ b/internal/pkg/overlay/config.go @@ -10,7 +10,7 @@ import ( func OverlaySourceTopDir() string { conf := warewulfconf.New() - return conf.WWOVERLAYDIR() + return conf.Paths.WWOverlaydir } /* @@ -32,5 +32,5 @@ Returns the overlay name of the image for a given node */ func OverlayImage(nodeName string, overlayName []string) string { conf := warewulfconf.New() - return path.Join(conf.WWPROVISIONDIR(), "overlays/", nodeName, strings.Join(overlayName, "-")+".img") + return path.Join(conf.Paths.WWProvisiondir, "overlays/", nodeName, strings.Join(overlayName, "-")+".img") } diff --git a/internal/pkg/overlay/funcmap.go b/internal/pkg/overlay/funcmap.go index d3fe05e5..ebdb1b1a 100644 --- a/internal/pkg/overlay/funcmap.go +++ b/internal/pkg/overlay/funcmap.go @@ -14,13 +14,12 @@ import ( /* Reads a file file from the host fs. If the file has nor '/' prefix -the path is relative to SYSCONFDIR. -Templates in the file are no evaluated. +the path is relative to Paths.SysconfdirTemplates in the file are no evaluated. */ func templateFileInclude(inc string) string { conf := warewulfconf.New() if !strings.HasPrefix(inc, "/") { - inc = path.Join(conf.SYSCONFDIR(), "warewulf", inc) + inc = path.Join(conf.Paths.Sysconfdir, "warewulf", inc) } wwlog.Debug("Including file into template: %s", inc) content, err := os.ReadFile(inc) @@ -38,7 +37,7 @@ 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(conf.SYSCONFDIR(), "warewulf", inc) + inc = path.Join(conf.Paths.Sysconfdir, "warewulf", inc) } wwlog.Debug("Including file block into template: %s", inc) readFile, err := os.Open(inc) diff --git a/internal/pkg/version/version.go b/internal/pkg/version/version.go index 5ce00f23..6b4771bb 100644 --- a/internal/pkg/version/version.go +++ b/internal/pkg/version/version.go @@ -12,7 +12,7 @@ Return the version of wwctl */ func GetVersion() string { conf := warewulfconf.New() - return fmt.Sprintf("%s-%s", conf.VERSION(), conf.RELEASE()) + return fmt.Sprintf("%s-%s", conf.Paths.Version, conf.Paths.Release) } /* diff --git a/internal/pkg/warewulfconf/buildconfig.go.in b/internal/pkg/warewulfconf/buildconfig.go.in index 3a5a52cd..cd7ac2f4 100644 --- a/internal/pkg/warewulfconf/buildconfig.go.in +++ b/internal/pkg/warewulfconf/buildconfig.go.in @@ -9,10 +9,10 @@ type BuildConfig struct { Tftpdir string `default:"@TFTPDIR@"` Firewallddir string `default:"@FIREWALLDDIR@"` Systemddir string `default:"@SYSTEMDDIR@"` - Wwoverlaydir string `default:"@WWOVERLAYDIR@"` - Wwchrootdir string `default:"@WWCHROOTDIR@"` - Wwprovisiondir string `default:"@WWPROVISIONDIR@"` + WWOverlaydir string `default:"@WWOVERLAYDIR@"` + WWChrootdir string `default:"@WWCHROOTDIR@"` + WWProvisiondir string `default:"@WWPROVISIONDIR@"` Version string `default:"@VERSION@"` Release string `default:"@RELEASE@"` - Wwclientdir string `default:"@WWCLIENTDIR@"` + WWClientdir string `default:"@WWCLIENTDIR@"` } diff --git a/internal/pkg/warewulfconf/getter.go b/internal/pkg/warewulfconf/getter.go deleted file mode 100644 index 6d92a2fe..00000000 --- a/internal/pkg/warewulfconf/getter.go +++ /dev/null @@ -1,73 +0,0 @@ -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 -} diff --git a/internal/pkg/warewulfd/provision.go b/internal/pkg/warewulfd/provision.go index 7b96ee6d..c96267cc 100644 --- a/internal/pkg/warewulfd/provision.go +++ b/internal/pkg/warewulfd/provision.go @@ -79,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(conf.SYSCONFDIR(), "/warewulf/ipxe/unconfigured.ipxe") + stage_file = path.Join(conf.Paths.Sysconfdir, "/warewulf/ipxe/unconfigured.ipxe") tmpl_data = iPxeTemplate{ Hwaddr: rinfo.hwaddr} } } else if rinfo.stage == "ipxe" { - stage_file = path.Join(conf.SYSCONFDIR(), "warewulf/ipxe/"+node.Ipxe.Get()+".ipxe") + stage_file = path.Join(conf.Paths.Sysconfdir, "warewulf/ipxe/"+node.Ipxe.Get()+".ipxe") tmpl_data = iPxeTemplate{ Id: node.Id.Get(), Cluster: node.ClusterName.Get(),