Merge pull request #1534 from mslacken/removeWrap
replaced errors.Wrap with fmt.Errorf
This commit is contained in:
@@ -57,6 +57,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- Don't package the API in RPM packages by default. #1493
|
- Don't package the API in RPM packages by default. #1493
|
||||||
- Update default `warewulfd` port to match shipped configuration. #1448
|
- Update default `warewulfd` port to match shipped configuration. #1448
|
||||||
- Replace `olekukonko/tablewriter` with `cheynewallace/tabby`. #1497, #1498
|
- Replace `olekukonko/tablewriter` with `cheynewallace/tabby`. #1497, #1498
|
||||||
|
- replaced deprecated errors.Wrapf with fmr.Errorf. #1534
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/container"
|
"github.com/warewulf/warewulf/internal/pkg/container"
|
||||||
@@ -39,7 +38,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
|||||||
conf := warewulfconf.Get()
|
conf := warewulfconf.Get()
|
||||||
runDir := container.RunDir(containerName)
|
runDir := container.RunDir(containerName)
|
||||||
if _, err := os.Stat(runDir); os.IsNotExist(err) {
|
if _, err := os.Stat(runDir); os.IsNotExist(err) {
|
||||||
return errors.Wrap(err, "container run directory does not exist")
|
return fmt.Errorf("container run directory does not exist: %w", err)
|
||||||
}
|
}
|
||||||
mountPts := conf.MountsContainer
|
mountPts := conf.MountsContainer
|
||||||
mountPts = append(container.InitMountPnts(binds), mountPts...)
|
mountPts = append(container.InitMountPnts(binds), mountPts...)
|
||||||
@@ -80,7 +79,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
|||||||
// running in a private PID space, so also make / private, so that nothing gets out from here
|
// running in a private PID space, so also make / private, so that nothing gets out from here
|
||||||
err = syscall.Mount("", "/", "", syscall.MS_PRIVATE|syscall.MS_REC, "")
|
err = syscall.Mount("", "/", "", syscall.MS_PRIVATE|syscall.MS_REC, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to mount")
|
return fmt.Errorf("failed to mount: %w", err)
|
||||||
}
|
}
|
||||||
ps1Str := fmt.Sprintf("[%s|%s] Warewulf> ", containerName, exitEval)
|
ps1Str := fmt.Sprintf("[%s|%s] Warewulf> ", containerName, exitEval)
|
||||||
wwlog.Info(msgStr)
|
wwlog.Info(msgStr)
|
||||||
@@ -126,11 +125,11 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
|||||||
ps1Str = fmt.Sprintf("[%s|ro] Warewulf> ", containerName)
|
ps1Str = fmt.Sprintf("[%s|ro] Warewulf> ", containerName)
|
||||||
err = syscall.Mount(containerPath, containerPath, "", syscall.MS_BIND, "")
|
err = syscall.Mount(containerPath, containerPath, "", syscall.MS_BIND, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to prepare bind mount")
|
return fmt.Errorf("failed to prepare bind mount: %w", err)
|
||||||
}
|
}
|
||||||
err = syscall.Mount(containerPath, containerPath, "", syscall.MS_REMOUNT|syscall.MS_RDONLY|syscall.MS_BIND, "")
|
err = syscall.Mount(containerPath, containerPath, "", syscall.MS_REMOUNT|syscall.MS_RDONLY|syscall.MS_BIND, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to remount ro")
|
return fmt.Errorf("failed to remount ro: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,25 +155,25 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
|||||||
|
|
||||||
err = syscall.Chroot(containerPath)
|
err = syscall.Chroot(containerPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to chroot")
|
return fmt.Errorf("failed to chroot: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Chdir("/")
|
err = os.Chdir("/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to chdir")
|
return fmt.Errorf("failed to chdir: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := syscall.Mount("devtmpfs", "/dev", "devtmpfs", 0, ""); err != nil {
|
if err := syscall.Mount("devtmpfs", "/dev", "devtmpfs", 0, ""); err != nil {
|
||||||
return errors.Wrap(err, "failed to mount /dev")
|
return fmt.Errorf("failed to mount /dev: %w", err)
|
||||||
}
|
}
|
||||||
if err := syscall.Mount("sysfs", "/sys", "sysfs", 0, ""); err != nil {
|
if err := syscall.Mount("sysfs", "/sys", "sysfs", 0, ""); err != nil {
|
||||||
return errors.Wrap(err, "failed to mount /sys")
|
return fmt.Errorf("failed to mount /sys: %w", err)
|
||||||
}
|
}
|
||||||
if err := syscall.Mount("proc", "/proc", "proc", 0, ""); err != nil {
|
if err := syscall.Mount("proc", "/proc", "proc", 0, ""); err != nil {
|
||||||
return errors.Wrap(err, "failed to mount /proc")
|
return fmt.Errorf("failed to mount /proc: %w", err)
|
||||||
}
|
}
|
||||||
if err := syscall.Mount("tmpfs", "/run", "tmpfs", 0, ""); err != nil {
|
if err := syscall.Mount("tmpfs", "/run", "tmpfs", 0, ""); err != nil {
|
||||||
return errors.Wrap(err, "failed to mount /run")
|
return fmt.Errorf("failed to mount /run: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("PS1", ps1Str)
|
os.Setenv("PS1", ps1Str)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package imprt
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/container"
|
"github.com/warewulf/warewulf/internal/pkg/container"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/kernel"
|
"github.com/warewulf/warewulf/internal/pkg/kernel"
|
||||||
@@ -68,12 +67,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist nodedb")
|
return fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Set default kernel version to: %s\n", args[0])
|
fmt.Printf("Set default kernel version to: %s\n", args[0])
|
||||||
err = warewulfd.DaemonReload()
|
err = warewulfd.DaemonReload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to reload warewulf daemon")
|
return fmt.Errorf("failed to reload warewulf daemon: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
apinode "github.com/warewulf/warewulf/internal/pkg/api/node"
|
apinode "github.com/warewulf/warewulf/internal/pkg/api/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
@@ -133,7 +132,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
err = warewulfd.DaemonReload()
|
err = warewulfd.DaemonReload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to reload warewulf daemon")
|
return fmt.Errorf("failed to reload warewulf daemon: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
if Force {
|
if Force {
|
||||||
err := os.RemoveAll(overlayPath)
|
err := os.RemoveAll(overlayPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed deleting overlay")
|
return fmt.Errorf("failed deleting overlay: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := os.Remove(overlayPath)
|
err := os.Remove(overlayPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed deleting overlay")
|
return fmt.Errorf("failed deleting overlay: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wwlog.Info("Deleted overlay: %s\n", args[0])
|
wwlog.Info("Deleted overlay: %s\n", args[0])
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||||
@@ -59,7 +58,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
err := util.CopyFile(source, path.Join(overlaySource, dest))
|
err := util.CopyFile(source, path.Join(overlaySource, dest))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not copy file into overlay")
|
return fmt.Errorf("could not copy file into overlay: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !NoOverlayUpdate {
|
if !NoOverlayUpdate {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package list
|
package list
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
@@ -20,7 +20,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
var err error
|
var err error
|
||||||
overlays, err = overlay.FindOverlays()
|
overlays, err = overlay.FindOverlays()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not obtain list of overlays from system")
|
return fmt.Errorf("could not obtain list of overlays from system: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
@@ -39,7 +38,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
wwlog.Verbose("Removing profile from node %s: %s", n.Id(), r)
|
wwlog.Verbose("Removing profile from node %s: %s", n.Id(), r)
|
||||||
n.Profiles = append(n.Profiles[:i], n.Profiles[i+1:]...)
|
n.Profiles = append(n.Profiles[:i], n.Profiles[i+1:]...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to update node")
|
return fmt.Errorf("failed to update node: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +72,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
if SetYes {
|
if SetYes {
|
||||||
err := nodeDB.Persist()
|
err := nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist nodedb")
|
return fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
prompt := promptui.Prompt{
|
prompt := promptui.Prompt{
|
||||||
@@ -86,7 +85,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
if result == "y" || result == "yes" {
|
if result == "y" || result == "yes" {
|
||||||
err := nodeDB.Persist()
|
err := nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist nodedb")
|
return fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pkg/errors"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
"github.com/warewulf/warewulf/internal/pkg/warewulfd"
|
||||||
)
|
)
|
||||||
@@ -21,7 +22,7 @@ func GetCommand() *cobra.Command {
|
|||||||
|
|
||||||
func CobraRunE(cmd *cobra.Command, args []string) error {
|
func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||||
if err := warewulfd.DaemonInitLogging(); err != nil {
|
if err := warewulfd.DaemonInitLogging(); err != nil {
|
||||||
return errors.Wrap(err, "failed to configure logging")
|
return fmt.Errorf("failed to configure logging: %w", err)
|
||||||
}
|
}
|
||||||
return errors.Wrap(warewulfd.RunServer(), "failed to start Warewulf server")
|
return fmt.Errorf("failed to start Warewulf server: %w", warewulfd.RunServer())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/container"
|
"github.com/warewulf/warewulf/internal/pkg/container"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/kernel"
|
"github.com/warewulf/warewulf/internal/pkg/kernel"
|
||||||
@@ -101,7 +100,7 @@ func ContainerBuild(cbp *wwapiv1.ContainerBuildParameter) (err error) {
|
|||||||
// TODO: Need a wrapper and flock around this. Sometimes we restart warewulfd and sometimes we don't.
|
// TODO: Need a wrapper and flock around this. Sometimes we restart warewulfd and sometimes we don't.
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist nodedb")
|
return fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Set default profile to container: %s\n", containers[0])
|
fmt.Printf("Set default profile to container: %s\n", containers[0])
|
||||||
}
|
}
|
||||||
@@ -260,14 +259,14 @@ func ContainerImport(cip *wwapiv1.ContainerImportParameter) (containerName strin
|
|||||||
// reload the config or if there is something more.
|
// reload the config or if there is something more.
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "failed to persist nodedb")
|
err = fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Info("Set default profile to container: %s", cip.Name)
|
wwlog.Info("Set default profile to container: %s", cip.Name)
|
||||||
err = warewulfd.DaemonReload()
|
err = warewulfd.DaemonReload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "failed to reload warewulf daemon")
|
err = fmt.Errorf("failed to reload warewulf daemon: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/hostlist"
|
"github.com/warewulf/warewulf/internal/pkg/hostlist"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
@@ -24,7 +23,7 @@ func NodeAdd(nap *wwapiv1.NodeAddParameter) (err error) {
|
|||||||
|
|
||||||
nodeDB, err := node.New()
|
nodeDB, err := node.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to open node database")
|
return fmt.Errorf("failed to open node database: %w", err)
|
||||||
}
|
}
|
||||||
dbHash := nodeDB.Hash()
|
dbHash := nodeDB.Hash()
|
||||||
if hex.EncodeToString(dbHash[:]) != nap.Hash && !nap.Force {
|
if hex.EncodeToString(dbHash[:]) != nap.Hash && !nap.Force {
|
||||||
@@ -35,11 +34,11 @@ func NodeAdd(nap *wwapiv1.NodeAddParameter) (err error) {
|
|||||||
for _, a := range node_args {
|
for _, a := range node_args {
|
||||||
n, err := nodeDB.AddNode(a)
|
n, err := nodeDB.AddNode(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to add node")
|
return fmt.Errorf("failed to add node: %w", err)
|
||||||
}
|
}
|
||||||
err = yaml.Unmarshal([]byte(nap.NodeConfYaml), &n)
|
err = yaml.Unmarshal([]byte(nap.NodeConfYaml), &n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed to decode nodeConf")
|
return fmt.Errorf("Failed to decode nodeConf: %w", err)
|
||||||
}
|
}
|
||||||
wwlog.Info("Added node: %s", a)
|
wwlog.Info("Added node: %s", a)
|
||||||
for _, dev := range n.NetDevs {
|
for _, dev := range n.NetDevs {
|
||||||
@@ -66,12 +65,12 @@ func NodeAdd(nap *wwapiv1.NodeAddParameter) (err error) {
|
|||||||
|
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist new node")
|
return fmt.Errorf("failed to persist new node: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = warewulfd.DaemonReload()
|
err = warewulfd.DaemonReload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to reload warewulf daemon")
|
return fmt.Errorf("failed to reload warewulf daemon: %w", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/hostlist"
|
"github.com/warewulf/warewulf/internal/pkg/hostlist"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
@@ -43,12 +42,12 @@ func NodeDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) {
|
|||||||
|
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist nodedb")
|
return fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = warewulfd.DaemonReload()
|
err = warewulfd.DaemonReload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to reload warewulf daemon")
|
return fmt.Errorf("failed to reload warewulf daemon: %w", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package apinode
|
package apinode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
@@ -35,22 +35,22 @@ Add nodes from yaml
|
|||||||
func NodeAddFromYaml(nodeList *wwapiv1.NodeYaml) (err error) {
|
func NodeAddFromYaml(nodeList *wwapiv1.NodeYaml) (err error) {
|
||||||
nodeDB, err := node.New()
|
nodeDB, err := node.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not open NodeDB: %s\n")
|
return fmt.Errorf("could not open NodeDB: %w", err)
|
||||||
}
|
}
|
||||||
nodeMap := make(map[string]*node.NodeConf)
|
nodeMap := make(map[string]*node.NodeConf)
|
||||||
err = yaml.Unmarshal([]byte(nodeList.NodeConfMapYaml), nodeMap)
|
err = yaml.Unmarshal([]byte(nodeList.NodeConfMapYaml), nodeMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not unmarshal Yaml: %s\n")
|
return fmt.Errorf("could not unmarshal Yaml: %w", err)
|
||||||
}
|
}
|
||||||
for nodeName, node := range nodeMap {
|
for nodeName, node := range nodeMap {
|
||||||
err = nodeDB.SetNode(nodeName, *node)
|
err = nodeDB.SetNode(nodeName, *node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "couldn't set node")
|
return fmt.Errorf("couldn't set node: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist nodedb")
|
return fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func ProfileAdd(nsp *wwapiv1.NodeAddParameter) error {
|
|||||||
}
|
}
|
||||||
nodeDB, err := node.New()
|
nodeDB, err := node.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not open database")
|
return fmt.Errorf("Could not open database: %w", err)
|
||||||
}
|
}
|
||||||
for _, p := range nsp.NodeNames {
|
for _, p := range nsp.NodeNames {
|
||||||
if util.InSlice(nodeDB.ListAllProfiles(), p) {
|
if util.InSlice(nodeDB.ListAllProfiles(), p) {
|
||||||
@@ -31,12 +31,12 @@ func ProfileAdd(nsp *wwapiv1.NodeAddParameter) error {
|
|||||||
}
|
}
|
||||||
err = yaml.Unmarshal([]byte(nsp.NodeConfYaml), &pNew)
|
err = yaml.Unmarshal([]byte(nsp.NodeConfYaml), &pNew)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to add profile")
|
return fmt.Errorf("failed to add profile: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist new profile")
|
return fmt.Errorf("failed to persist new profile: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package apiprofile
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/hostlist"
|
"github.com/warewulf/warewulf/internal/pkg/hostlist"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
@@ -29,11 +28,11 @@ func ProfileDelete(ndp *wwapiv1.NodeDeleteParameter) (err error) {
|
|||||||
|
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist nodedb")
|
return fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
}
|
}
|
||||||
err = warewulfd.DaemonReload()
|
err = warewulfd.DaemonReload()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to reload warewulf daemon")
|
return fmt.Errorf("failed to reload warewulf daemon: %w", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
@@ -35,7 +34,7 @@ Add profiles from yaml
|
|||||||
func ProfileAddFromYaml(nodeList *wwapiv1.NodeAddParameter) (err error) {
|
func ProfileAddFromYaml(nodeList *wwapiv1.NodeAddParameter) (err error) {
|
||||||
nodeDB, err := node.New()
|
nodeDB, err := node.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not open NodeDB: %s\n")
|
return fmt.Errorf("couldn't open NodeDB: %w", err)
|
||||||
}
|
}
|
||||||
if nodeDB.StringHash() != nodeList.Hash && !nodeList.Force {
|
if nodeDB.StringHash() != nodeList.Hash && !nodeList.Force {
|
||||||
return fmt.Errorf("got wrong hash, not modifying profile database")
|
return fmt.Errorf("got wrong hash, not modifying profile database")
|
||||||
@@ -44,17 +43,17 @@ func ProfileAddFromYaml(nodeList *wwapiv1.NodeAddParameter) (err error) {
|
|||||||
profileMap := make(map[string]*node.ProfileConf)
|
profileMap := make(map[string]*node.ProfileConf)
|
||||||
err = yaml.Unmarshal([]byte(nodeList.NodeConfYaml), profileMap)
|
err = yaml.Unmarshal([]byte(nodeList.NodeConfYaml), profileMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not unmarshall Yaml: %s\n")
|
return fmt.Errorf("couldn't unmarshall Yaml: %w", err)
|
||||||
}
|
}
|
||||||
for profileName, profile := range profileMap {
|
for profileName, profile := range profileMap {
|
||||||
err = nodeDB.SetProfile(profileName, *profile)
|
err = nodeDB.SetProfile(profileName, *profile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "couldn't set profile")
|
return fmt.Errorf("couldn't set profile: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = nodeDB.Persist()
|
err = nodeDB.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist nodedb")
|
return fmt.Errorf("failed to persist nodedb: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"dario.cat/mergo"
|
"dario.cat/mergo"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
@@ -21,7 +20,7 @@ func ProfileSet(set *wwapiv1.ConfSetParameter) (err error) {
|
|||||||
}
|
}
|
||||||
nodeDB, _, err := ProfileSetParameterCheck(set)
|
nodeDB, _, err := ProfileSetParameterCheck(set)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "profile set parameters are wrong")
|
return fmt.Errorf("profile set parameters are wrong: %w", err)
|
||||||
}
|
}
|
||||||
if err = nodeDB.Persist(); err != nil {
|
if err = nodeDB.Persist(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ func (conf *RootConf) SetDynamicDefaults() (err error) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
mask = network.Mask
|
mask = network.Mask
|
||||||
} else {
|
} else {
|
||||||
return errors.Wrap(err, "Couldn't parse IP address")
|
return fmt.Errorf("Couldn't parse IP address: %w", err)
|
||||||
}
|
}
|
||||||
if conf.Netmask == "" {
|
if conf.Netmask == "" {
|
||||||
conf.Netmask = fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3])
|
conf.Netmask = fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3])
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package configure
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
@@ -41,7 +40,7 @@ func DHCP() (err error) {
|
|||||||
fmt.Printf("Enabling and restarting the DHCP services\n")
|
fmt.Printf("Enabling and restarting the DHCP services\n")
|
||||||
err = util.SystemdStart(controller.DHCP.SystemdName)
|
err = util.SystemdStart(controller.DHCP.SystemdName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to start")
|
return fmt.Errorf("failed to start: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
@@ -39,7 +38,7 @@ func Hostfile() (err error) {
|
|||||||
if writeFile {
|
if writeFile {
|
||||||
err = overlay.CarefulWriteBuffer("/etc/hosts", buffer, backupFile, info.Mode())
|
err = overlay.CarefulWriteBuffer("/etc/hosts", buffer, backupFile, info.Mode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not write file from template")
|
return fmt.Errorf("could not write file from template: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package configure
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
"github.com/warewulf/warewulf/internal/pkg/overlay"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
@@ -31,12 +30,12 @@ func NFS() error {
|
|||||||
if controller.NFS.SystemdName == "" {
|
if controller.NFS.SystemdName == "" {
|
||||||
err := util.SystemdStart("nfs-server")
|
err := util.SystemdStart("nfs-server")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to start nfs-server")
|
return fmt.Errorf("failed to start nfs-server: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := util.SystemdStart(controller.NFS.SystemdName)
|
err := util.SystemdStart(controller.NFS.SystemdName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to start")
|
return fmt.Errorf("failed to start: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/util"
|
"github.com/warewulf/warewulf/internal/pkg/util"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
@@ -34,7 +33,7 @@ func SSH(keyTypes ...string) error {
|
|||||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", k, "-f", path.Join(wwkeydir, keytype), "-C", "", "-N", "")
|
err = util.ExecInteractive("ssh-keygen", "-q", "-t", k, "-f", path.Join(wwkeydir, keytype), "-C", "", "-N", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Error("Failed to exec ssh-keygen: %s", err)
|
wwlog.Error("Failed to exec ssh-keygen: %s", err)
|
||||||
return errors.Wrap(err, "failed to exec ssh-keygen command")
|
return fmt.Errorf("failed to exec ssh-keygen command: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Skipping, key already exists: %s\n", keytype)
|
fmt.Printf("Skipping, key already exists: %s\n", keytype)
|
||||||
@@ -59,11 +58,11 @@ func SSH(keyTypes ...string) error {
|
|||||||
pubKey := privKey + ".pub"
|
pubKey := privKey + ".pub"
|
||||||
err = util.ExecInteractive("ssh-keygen", "-q", "-t", keyType, "-f", privKey, "-C", "", "-N", "")
|
err = util.ExecInteractive("ssh-keygen", "-q", "-t", keyType, "-f", privKey, "-C", "", "-N", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed to exec ssh-keygen command")
|
return fmt.Errorf("failed to exec ssh-keygen command: %w", err)
|
||||||
}
|
}
|
||||||
err := util.CopyFile(pubKey, authorizedKeys)
|
err := util.CopyFile(pubKey, authorizedKeys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("Failed to copy %s to authorized_keys", pubKey))
|
return fmt.Errorf("failed to copy %s to authorized_keys: %w", pubKey, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Skipping authorized_keys: no key types configured\n")
|
fmt.Printf("Skipping authorized_keys: no key types configured\n")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package container
|
package container
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -33,7 +34,7 @@ func Build(name string, buildForce bool) error {
|
|||||||
var err error
|
var err error
|
||||||
ignore, err = util.ReadFile(excludes_file)
|
ignore, err = util.ReadFile(excludes_file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed creating directory: %s", imagePath)
|
return fmt.Errorf("Failed creating directory: %s: %w", imagePath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,12 +135,12 @@ func Build(kernelVersion, kernelName, root string) error {
|
|||||||
// Create the destination paths just in case it doesn't exist
|
// Create the destination paths just in case it doesn't exist
|
||||||
err := os.MkdirAll(path.Dir(kernelDestination), 0755)
|
err := os.MkdirAll(path.Dir(kernelDestination), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create kernel dest")
|
return fmt.Errorf("failed to create kernel dest: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(path.Dir(driversDestination), 0755)
|
err = os.MkdirAll(path.Dir(driversDestination), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create driver dest")
|
return fmt.Errorf("failed to create driver dest: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(path.Dir(versionDestination), 0755)
|
err = os.MkdirAll(path.Dir(versionDestination), 0755)
|
||||||
@@ -161,7 +161,7 @@ func Build(kernelVersion, kernelName, root string) error {
|
|||||||
if _, err := os.Stat(kernelSource); err == nil {
|
if _, err := os.Stat(kernelSource); err == nil {
|
||||||
kernel, err := os.Open(kernelSource)
|
kernel, err := os.Open(kernelSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not open kernel")
|
return fmt.Errorf("could not open kernel: %w", err)
|
||||||
}
|
}
|
||||||
defer kernel.Close()
|
defer kernel.Close()
|
||||||
|
|
||||||
@@ -171,20 +171,20 @@ func Build(kernelVersion, kernelName, root string) error {
|
|||||||
|
|
||||||
writer, err := os.Create(kernelDestination)
|
writer, err := os.Create(kernelDestination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not decompress kernel")
|
return fmt.Errorf("could not decompress kernel: %w", err)
|
||||||
}
|
}
|
||||||
defer writer.Close()
|
defer writer.Close()
|
||||||
|
|
||||||
_, err = io.Copy(writer, gzipreader)
|
_, err = io.Copy(writer, gzipreader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not write decompressed kernel")
|
return fmt.Errorf("could not write decompressed kernel: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
err := util.CopyFile(kernelSource, kernelDestination)
|
err := util.CopyFile(kernelSource, kernelDestination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not copy kernel")
|
return fmt.Errorf("could not copy kernel: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,16 +220,16 @@ func Build(kernelVersion, kernelName, root string) error {
|
|||||||
wwlog.Verbose("Creating version file")
|
wwlog.Verbose("Creating version file")
|
||||||
file, err := os.Create(versionDestination)
|
file, err := os.Create(versionDestination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed to create version file")
|
return fmt.Errorf("Failed to create version file: %w", err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
_, err = io.WriteString(file, kernelVersion)
|
_, err = io.WriteString(file, kernelVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not write kernel version")
|
return fmt.Errorf("Could not write kernel version: %w", err)
|
||||||
}
|
}
|
||||||
err = file.Sync()
|
err = file.Sync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not sync kernel version")
|
return fmt.Errorf("Could not sync kernel version: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ func BuildAllOverlays(nodes []node.NodeConf) error {
|
|||||||
wwlog.Info("Building system overlays for %s: [%s]", n.Id(), strings.Join(sysOverlays, ", "))
|
wwlog.Info("Building system overlays for %s: [%s]", n.Id(), strings.Join(sysOverlays, ", "))
|
||||||
err := BuildOverlay(n, "system", sysOverlays)
|
err := BuildOverlay(n, "system", sysOverlays)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not build system overlays %v for node %s", sysOverlays, n.Id())
|
return fmt.Errorf("could not build system overlays %v for node %s: %w", sysOverlays, n.Id(), err)
|
||||||
}
|
}
|
||||||
runOverlays := n.RuntimeOverlay
|
runOverlays := n.RuntimeOverlay
|
||||||
wwlog.Info("Building runtime overlays for %s: [%s]", n.Id(), strings.Join(runOverlays, ", "))
|
wwlog.Info("Building runtime overlays for %s: [%s]", n.Id(), strings.Join(runOverlays, ", "))
|
||||||
err = BuildOverlay(n, "runtime", runOverlays)
|
err = BuildOverlay(n, "runtime", runOverlays)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not build runtime overlays %v for node %s", runOverlays, n.Id())
|
return fmt.Errorf("could not build runtime overlays %v for node %s: %w", runOverlays, n.Id(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ func BuildSpecificOverlays(nodes []node.NodeConf, overlayNames []string) error {
|
|||||||
for _, overlayName := range overlayNames {
|
for _, overlayName := range overlayNames {
|
||||||
err := BuildOverlay(n, "", []string{overlayName})
|
err := BuildOverlay(n, "", []string{overlayName})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not build overlay %s for node %s", overlayName, n.Id())
|
return fmt.Errorf("could not build overlay %s for node %s: %w", overlayName, n.Id(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ func BuildHostOverlay() error {
|
|||||||
hostdir := OverlaySourceDir("host")
|
hostdir := OverlaySourceDir("host")
|
||||||
stats, err := os.Stat(hostdir)
|
stats, err := os.Stat(hostdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not build host overlay ")
|
return fmt.Errorf("could not build host overlay: %w ", err)
|
||||||
}
|
}
|
||||||
if !(stats.Mode() == os.FileMode(0750|os.ModeDir) || stats.Mode() == os.FileMode(0700|os.ModeDir)) {
|
if !(stats.Mode() == os.FileMode(0750|os.ModeDir) || stats.Mode() == os.FileMode(0700|os.ModeDir)) {
|
||||||
wwlog.SecWarn("Permissions of host overlay dir %s are %s (750 is considered as secure)", hostdir, stats.Mode())
|
wwlog.SecWarn("Permissions of host overlay dir %s are %s (750 is considered as secure)", hostdir, stats.Mode())
|
||||||
@@ -90,7 +90,7 @@ func FindOverlays() ([]string, error) {
|
|||||||
|
|
||||||
files, err := os.ReadDir(OverlaySourceTopDir())
|
files, err := os.ReadDir(OverlaySourceTopDir())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, errors.Wrap(err, "could not get list of overlays")
|
return ret, fmt.Errorf("could not get list of overlays: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
@@ -135,14 +135,14 @@ func BuildOverlay(nodeConf node.NodeConf, context string, overlayNames []string)
|
|||||||
|
|
||||||
err := os.MkdirAll(overlayImageDir, 0750)
|
err := os.MkdirAll(overlayImageDir, 0750)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed to create directory for %s: %s", name, overlayImageDir)
|
return fmt.Errorf("failed to create directory for %s: %s: %w", name, overlayImageDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Debug("Created directory for %s: %s", name, overlayImageDir)
|
wwlog.Debug("Created directory for %s: %s", name, overlayImageDir)
|
||||||
|
|
||||||
buildDir, err := os.MkdirTemp(os.TempDir(), ".wwctl-overlay-")
|
buildDir, err := os.MkdirTemp(os.TempDir(), ".wwctl-overlay-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed to create temporary directory for %s", name)
|
return fmt.Errorf("failed to create temporary directory for %s: %w", name, err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(buildDir)
|
defer os.RemoveAll(buildDir)
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ func BuildOverlay(nodeConf node.NodeConf, context string, overlayNames []string)
|
|||||||
|
|
||||||
err = BuildOverlayIndir(nodeConf, overlayNames, buildDir)
|
err = BuildOverlayIndir(nodeConf, overlayNames, buildDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed to generate files for %s", name)
|
return fmt.Errorf("failed to generate files for %s: %w", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Debug("Generated files for %s", name)
|
wwlog.Debug("Generated files for %s", name)
|
||||||
@@ -194,13 +194,13 @@ func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir
|
|||||||
wwlog.Debug("Changing directory to OverlayDir: %s", overlaySourceDir)
|
wwlog.Debug("Changing directory to OverlayDir: %s", overlaySourceDir)
|
||||||
err := os.Chdir(overlaySourceDir)
|
err := os.Chdir(overlaySourceDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(ErrDoesNotExist, "directory: %s name: %s", overlaySourceDir, overlayName)
|
return fmt.Errorf("directory: %s name: %s err: %w", overlaySourceDir, overlayName, ErrDoesNotExist)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Verbose("Walking the overlay structure: %s", overlaySourceDir)
|
wwlog.Verbose("Walking the overlay structure: %s", overlaySourceDir)
|
||||||
err = filepath.Walk(".", func(location string, info os.FileInfo, err error) error {
|
err = filepath.Walk(".", func(location string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error for "+location)
|
return fmt.Errorf("error for %s: %w", location, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Debug("Found overlay file: %s", location)
|
wwlog.Debug("Found overlay file: %s", location)
|
||||||
@@ -210,11 +210,11 @@ func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir
|
|||||||
|
|
||||||
err = os.MkdirAll(path.Join(outputDir, location), info.Mode())
|
err = os.MkdirAll(path.Join(outputDir, location), info.Mode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not create directory within overlay")
|
return fmt.Errorf("could not create directory within overlay: %w", err)
|
||||||
}
|
}
|
||||||
err = util.CopyUIDGID(location, path.Join(outputDir, location))
|
err = util.CopyUIDGID(location, path.Join(outputDir, location))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed setting permissions on overlay directory")
|
return fmt.Errorf("failed setting permissions on overlay directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Debug("Created directory in overlay: %s", location)
|
wwlog.Debug("Created directory in overlay: %s", location)
|
||||||
@@ -222,7 +222,7 @@ func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir
|
|||||||
} else if filepath.Ext(location) == ".ww" {
|
} else if filepath.Ext(location) == ".ww" {
|
||||||
tstruct, err := InitStruct(nodeData)
|
tstruct, err := InitStruct(nodeData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("failed to initial data for %s", nodeData.Id()))
|
return fmt.Errorf("failed to initial data for %s: %w", nodeData.Id(), err)
|
||||||
}
|
}
|
||||||
tstruct.BuildSource = path.Join(overlaySourceDir, location)
|
tstruct.BuildSource = path.Join(overlaySourceDir, location)
|
||||||
wwlog.Verbose("Evaluating overlay template file: %s", location)
|
wwlog.Verbose("Evaluating overlay template file: %s", location)
|
||||||
@@ -230,7 +230,7 @@ func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir
|
|||||||
|
|
||||||
buffer, backupFile, writeFile, err := RenderTemplateFile(location, tstruct)
|
buffer, backupFile, writeFile, err := RenderTemplateFile(location, tstruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("Failed to render template %s", location))
|
return fmt.Errorf("failed to render template %s: %w", location, err)
|
||||||
}
|
}
|
||||||
if writeFile {
|
if writeFile {
|
||||||
destFileName := destFile
|
destFileName := destFile
|
||||||
@@ -249,11 +249,11 @@ func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir
|
|||||||
err = CarefulWriteBuffer(path.Join(outputDir, destFileName),
|
err = CarefulWriteBuffer(path.Join(outputDir, destFileName),
|
||||||
fileBuffer, backupFile, info.Mode())
|
fileBuffer, backupFile, info.Mode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not write file from template")
|
return fmt.Errorf("could not write file from template: %w", err)
|
||||||
}
|
}
|
||||||
err = util.CopyUIDGID(location, path.Join(outputDir, destFileName))
|
err = util.CopyUIDGID(location, path.Join(outputDir, destFileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed setting permissions on template output file")
|
return fmt.Errorf("failed setting permissions on template output file: %w", err)
|
||||||
}
|
}
|
||||||
fileBuffer.Reset()
|
fileBuffer.Reset()
|
||||||
}
|
}
|
||||||
@@ -265,11 +265,11 @@ func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir
|
|||||||
}
|
}
|
||||||
err = CarefulWriteBuffer(path.Join(outputDir, destFileName), fileBuffer, backupFile, info.Mode())
|
err = CarefulWriteBuffer(path.Join(outputDir, destFileName), fileBuffer, backupFile, info.Mode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not write file from template")
|
return fmt.Errorf("could not write file from template: %w", err)
|
||||||
}
|
}
|
||||||
err = util.CopyUIDGID(location, path.Join(outputDir, destFileName))
|
err = util.CopyUIDGID(location, path.Join(outputDir, destFileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed setting permissions on template output file")
|
return fmt.Errorf("failed setting permissions on template output file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Debug("Wrote template file into overlay: %s", destFile)
|
wwlog.Debug("Wrote template file into overlay: %s", destFile)
|
||||||
@@ -304,14 +304,14 @@ func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
wwlog.Debug("Copied file into overlay: %s", location)
|
wwlog.Debug("Copied file into overlay: %s", location)
|
||||||
} else {
|
} else {
|
||||||
return errors.Wrap(err, "could not copy file into overlay")
|
return fmt.Errorf("could not copy file into overlay: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to build overlay working directory")
|
return fmt.Errorf("failed to build overlay working directory: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,14 +327,14 @@ func CarefulWriteBuffer(destFile string, buffer bytes.Buffer, backupFile bool, p
|
|||||||
if !util.IsFile(destFile+".wwbackup") && util.IsFile(destFile) {
|
if !util.IsFile(destFile+".wwbackup") && util.IsFile(destFile) {
|
||||||
err := util.CopyFile(destFile, destFile+".wwbackup")
|
err := util.CopyFile(destFile, destFile+".wwbackup")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed to create backup: %s -> %s.wwbackup", destFile, destFile)
|
return fmt.Errorf("failed to create backup: %s -> %s.wwbackup %w", destFile, destFile, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
w, err := os.OpenFile(destFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
w, err := os.OpenFile(destFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not open new file for template")
|
return fmt.Errorf("could not open new file for template %w", err)
|
||||||
}
|
}
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
_, err = buffer.WriteTo(w)
|
_, err = buffer.WriteTo(w)
|
||||||
@@ -403,13 +403,13 @@ func RenderTemplateFile(fileName string, data TemplateStruct) (
|
|||||||
// Create the template with the merged FuncMap
|
// Create the template with the merged FuncMap
|
||||||
tmpl, err := template.New(path.Base(fileName)).Option("missingkey=default").Funcs(funcMap).ParseGlob(fileName)
|
tmpl, err := template.New(path.Base(fileName)).Option("missingkey=default").Funcs(funcMap).ParseGlob(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "could not parse template "+fileName)
|
err = fmt.Errorf("could not parse template %s: %w", fileName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(&buffer, data)
|
err = tmpl.Execute(&buffer, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "could not execute template")
|
err = fmt.Errorf("could not execute template: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -194,7 +193,7 @@ func FindFilterFiles(
|
|||||||
}()
|
}()
|
||||||
err = os.Chdir(path)
|
err = os.Chdir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ofiles, errors.Wrapf(err, "Failed to change path: %s", path)
|
return ofiles, fmt.Errorf("failed to change path: %s: %w", path, err)
|
||||||
}
|
}
|
||||||
// expand our include list as fspath.Match with /foo/* would catch /foo/baar but
|
// expand our include list as fspath.Match with /foo/* would catch /foo/baar but
|
||||||
// not /foo/baar/sibling
|
// not /foo/baar/sibling
|
||||||
@@ -277,11 +276,11 @@ func SystemdStart(systemdName string) error {
|
|||||||
wwlog.Debug("Setting up Systemd service: %s", systemdName)
|
wwlog.Debug("Setting up Systemd service: %s", systemdName)
|
||||||
err := ExecInteractive("/bin/sh", "-c", startCmd)
|
err := ExecInteractive("/bin/sh", "-c", startCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to run start cmd")
|
return fmt.Errorf("failed to run start cmd: %w", err)
|
||||||
}
|
}
|
||||||
err = ExecInteractive("/bin/sh", "-c", enableCmd)
|
err = ExecInteractive("/bin/sh", "-c", enableCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to run enable cmd")
|
return fmt.Errorf("failed to run enable cmd: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -324,13 +323,13 @@ func AppendLines(fileName string, lines []string) error {
|
|||||||
wwlog.Verbose("appending %v lines to %s", len(lines), fileName)
|
wwlog.Verbose("appending %v lines to %s", len(lines), fileName)
|
||||||
file, err := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY, 0644)
|
file, err := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Can't open file: %s", fileName)
|
return fmt.Errorf("can't open file: %s: %w", fileName, err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
wwlog.Debug("Appending '%s' to %s", line, fileName)
|
wwlog.Debug("Appending '%s' to %s", line, fileName)
|
||||||
if _, err := file.WriteString(fmt.Sprintf("%s\n", line)); err != nil {
|
if _, err := file.WriteString(fmt.Sprintf("%s\n", line)); err != nil {
|
||||||
return errors.Wrapf(err, "Can't write to file: %s", fileName)
|
return fmt.Errorf("can't write to file: %s: %w", fileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -392,7 +391,7 @@ func FileGz(
|
|||||||
err := os.Remove(file_gz)
|
err := os.Remove(file_gz)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Could not remove existing file: %s", file_gz)
|
return fmt.Errorf("could not remove existing file: %s: %w", file_gz, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +401,7 @@ func FileGz(
|
|||||||
compressor, err = exec.LookPath("gzip")
|
compressor, err = exec.LookPath("gzip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wwlog.Verbose("Could not locate GZIP")
|
wwlog.Verbose("Could not locate GZIP")
|
||||||
return errors.Wrapf(err, "No compressor program for image file: %s", file_gz)
|
return fmt.Errorf("no compressor program for image file: %s: %w", file_gz, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +425,7 @@ func FileGz(
|
|||||||
/* Open the output file for writing: */
|
/* Open the output file for writing: */
|
||||||
gzippedFile, err = os.Create(file_gz)
|
gzippedFile, err = os.Create(file_gz)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Unable to open compressed image file for writing: %s", file_gz)
|
return fmt.Errorf("unable to open compressed image file for writing: %s: %w", file_gz, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We'll execute gzip with output to stdout and attach stdout to the compressed file we just
|
/* We'll execute gzip with output to stdout and attach stdout to the compressed file we just
|
||||||
@@ -439,7 +438,7 @@ func FileGz(
|
|||||||
proc.Stdout = gzippedFile
|
proc.Stdout = gzippedFile
|
||||||
gzipStderr, err = proc.StderrPipe()
|
gzipStderr, err = proc.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Unable to open stderr pipe for compression program: %s", compressor)
|
return fmt.Errorf("unable to open stderr pipe for compression program: %s: %w", compressor, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute the command: */
|
/* Execute the command: */
|
||||||
@@ -448,13 +447,13 @@ func FileGz(
|
|||||||
_ = proc.Wait()
|
_ = proc.Wait()
|
||||||
gzippedFile.Close()
|
gzippedFile.Close()
|
||||||
os.Remove(file_gz)
|
os.Remove(file_gz)
|
||||||
err = errors.Wrapf(err, "Unable to successfully execute compression program: %s", compressor)
|
err = fmt.Errorf("unable to successfully execute compression program: %s: %w", compressor, err)
|
||||||
} else {
|
} else {
|
||||||
err = proc.Wait()
|
err = proc.Wait()
|
||||||
gzippedFile.Close()
|
gzippedFile.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(file_gz)
|
os.Remove(file_gz)
|
||||||
err = errors.Wrapf(err, "Unable to successfully create compressed image file: %s", file_gz)
|
err = fmt.Errorf("unable to successfully create compressed image file: %s: %w", file_gz, err)
|
||||||
} else {
|
} else {
|
||||||
wwlog.Verbose("Successfully compressed image file: %s", file_gz)
|
wwlog.Verbose("Successfully compressed image file: %s", file_gz)
|
||||||
}
|
}
|
||||||
@@ -484,7 +483,7 @@ func BuildFsImage(
|
|||||||
|
|
||||||
err = os.MkdirAll(path.Dir(imagePath), 0755)
|
err = os.MkdirAll(path.Dir(imagePath), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed to create image directory for %s: %s", name, imagePath)
|
return fmt.Errorf("failed to create image directory for %s: %s: %w", name, imagePath, err)
|
||||||
}
|
}
|
||||||
wwlog.Debug("Created image directory for %s: %s", name, imagePath)
|
wwlog.Debug("Created image directory for %s: %s", name, imagePath)
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
@@ -497,7 +496,7 @@ func BuildFsImage(
|
|||||||
|
|
||||||
err = os.Chdir(rootfsPath)
|
err = os.Chdir(rootfsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed chdir to fs directory for %s: %s", name, rootfsPath)
|
return fmt.Errorf("failed chdir to fs directory for %s: %s: %w", name, rootfsPath, err)
|
||||||
}
|
}
|
||||||
wwlog.Verbose("changed to: %s", rootfsPath)
|
wwlog.Verbose("changed to: %s", rootfsPath)
|
||||||
files, err := FindFilterFiles(
|
files, err := FindFilterFiles(
|
||||||
@@ -506,7 +505,7 @@ func BuildFsImage(
|
|||||||
ignore,
|
ignore,
|
||||||
ignore_xdev)
|
ignore_xdev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed discovering files for %s: %s", name, rootfsPath)
|
return fmt.Errorf("failed discovering files for %s: %s: %w", name, rootfsPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = CpioCreate(
|
err = CpioCreate(
|
||||||
@@ -515,14 +514,14 @@ func BuildFsImage(
|
|||||||
format,
|
format,
|
||||||
cpio_args...)
|
cpio_args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed creating image for %s: %s", name, imagePath)
|
return fmt.Errorf("failed creating image for %s: %s: %w", name, imagePath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Info("Created image for %s: %s", name, imagePath)
|
wwlog.Info("Created image for %s: %s", name, imagePath)
|
||||||
|
|
||||||
err = FileGz(imagePath)
|
err = FileGz(imagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed to compress image for %s: %s", name, imagePath+".gz")
|
return fmt.Errorf("failed to compress image for %s: %s: %w", name, imagePath+".gz", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.Info("Compressed image for %s: %s", name, imagePath+".gz")
|
wwlog.Info("Compressed image for %s: %s", name, imagePath+".gz")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package warewulfd
|
package warewulfd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log/syslog"
|
"log/syslog"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -62,7 +63,7 @@ func DaemonInitLogging() error {
|
|||||||
|
|
||||||
logwriter, err := syslog.New(syslog.LOG_NOTICE, "warewulfd")
|
logwriter, err := syslog.New(syslog.LOG_NOTICE, "warewulfd")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not create syslog writer")
|
return fmt.Errorf("Could not create syslog writer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wwlog.SetLogFormatter(wwlog.DefaultFormatter)
|
wwlog.SetLogFormatter(wwlog.DefaultFormatter)
|
||||||
@@ -86,17 +87,17 @@ func DaemonStatus() error {
|
|||||||
|
|
||||||
dat, err := os.ReadFile(WAREWULFD_PIDFILE)
|
dat, err := os.ReadFile(WAREWULFD_PIDFILE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "could not read Warewulfd PID file")
|
return fmt.Errorf("could not read Warewulfd PID file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pid, _ := strconv.Atoi(string(dat))
|
pid, _ := strconv.Atoi(string(dat))
|
||||||
process, err := os.FindProcess(pid)
|
process, err := os.FindProcess(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to find running PID")
|
return fmt.Errorf("failed to find running PID: %w", err)
|
||||||
} else {
|
} else {
|
||||||
err := process.Signal(syscall.Signal(0))
|
err := process.Signal(syscall.Signal(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to send process SIGCONT")
|
return fmt.Errorf("failed to send process SIGCONT: %w", err)
|
||||||
} else {
|
} else {
|
||||||
wwlog.Serv("Warewulf server is running at PID: %d", pid)
|
wwlog.Serv("Warewulf server is running at PID: %d", pid)
|
||||||
}
|
}
|
||||||
@@ -112,11 +113,11 @@ func DaemonReload() error {
|
|||||||
cmd := exec.Command("/usr/sbin/service", "warewulfd", "reload")
|
cmd := exec.Command("/usr/sbin/service", "warewulfd", "reload")
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to reload warewulfd")
|
return fmt.Errorf("failed to reload warewulfd: %w", err)
|
||||||
}
|
}
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to reload warewulfd")
|
return fmt.Errorf("failed to reload warewulfd: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package warewulfd
|
package warewulfd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
)
|
)
|
||||||
@@ -88,11 +87,11 @@ func GetNodeOrSetDiscoverable(hwaddr string) (node.NodeConf, error) {
|
|||||||
}
|
}
|
||||||
err = db.yml.Persist()
|
err = db.yml.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return node, errors.Wrapf(err, "%s (failed to persist node configuration)", hwaddr)
|
return node, fmt.Errorf("%s (failed to persist node configuration) %w", hwaddr, err)
|
||||||
}
|
}
|
||||||
err = loadNodeDB()
|
err = loadNodeDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return node, errors.Wrapf(err, "%s (failed to reload configuration)", hwaddr)
|
return node, fmt.Errorf("%s (failed to reload configuration) %w", hwaddr, err)
|
||||||
}
|
}
|
||||||
// NOTE: previously all overlays were built here, but that will also
|
// NOTE: previously all overlays were built here, but that will also
|
||||||
// be done automatically when attempting to serve an overlay that
|
// be done automatically when attempting to serve an overlay that
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package warewulfd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/warewulf/warewulf/internal/pkg/node"
|
"github.com/warewulf/warewulf/internal/pkg/node"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
)
|
)
|
||||||
@@ -86,7 +86,7 @@ func statusJSON() ([]byte, error) {
|
|||||||
|
|
||||||
ret, err := json.MarshalIndent(statusDB, "", " ")
|
ret, err := json.MarshalIndent(statusDB, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, errors.Wrap(err, "could not marshal JSON data from status structure")
|
return ret, fmt.Errorf("could not marshal JSON data from status structure: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package warewulfd
|
package warewulfd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -8,7 +9,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||||
)
|
)
|
||||||
@@ -82,7 +82,7 @@ func RunServer() error {
|
|||||||
err = http.ListenAndServe(":"+strconv.Itoa(daemonPort), &slashFix{&wwHandler})
|
err = http.ListenAndServe(":"+strconv.Itoa(daemonPort), &slashFix{&wwHandler})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Could not start listening service")
|
return fmt.Errorf("could not start listening service: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user