introduce site overlays

site overlays are place in sysconfdir/overlays and take
precedence over distribution overlays with the same name.

Every `wwctl overlay` command changing overlays will create
an site overlay. distribution overlays can't be deleted or
modified with wwctl.

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2024-11-21 14:52:46 +01:00
parent e8f7c01283
commit d5fc7e9320
12 changed files with 106 additions and 64 deletions

View File

@@ -21,8 +21,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("could not convert requested mode: %s", err)
}
overlaySourceDir = overlay.OverlaySourceDir(overlayName)
err = overlay.CreateSiteOverlay(overlayName)
if err != nil {
return err
}
overlaySourceDir, _ = overlay.OverlaySourceDir(overlayName)
if !util.IsDir(overlaySourceDir) {
return fmt.Errorf("overlay does not exist: %s", overlayName)

View File

@@ -34,8 +34,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} else {
gid = -1
}
overlaySourceDir = overlay.OverlaySourceDir(overlayName)
err = overlay.CreateSiteOverlay(overlayName)
if err != nil {
return err
}
overlaySourceDir, _ = overlay.OverlaySourceDir(overlayName)
if !util.IsDir(overlaySourceDir) {
return fmt.Errorf("overlay does not exist: %s", overlayName)

View File

@@ -22,8 +22,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
fileName = args[1]
}
overlayPath = overlay.OverlaySourceDir(overlayName)
overlayPath, isSite := overlay.OverlaySourceDir(overlayName)
if !isSite {
return fmt.Errorf("distribution overlay can't deleted")
}
if overlayPath == "" {
return fmt.Errorf("overlay name did not resolve: '%s'", overlayName)
}

View File

@@ -30,16 +30,20 @@ const initialTemplate = `# This is a Warewulf Template file.
# Keep the following for better reference:
# ---
# This file is autogenerated by warewulf
# Host: {{.BuildHost}}
# Time: {{.BuildTime}}
# Source: {{.BuildSource}}
`
func CobraRunE(cmd *cobra.Command, args []string) error {
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
overlayName := args[0]
fileName := args[1]
overlaySourceDir := overlay.OverlaySourceDir(overlayName)
createdSite := false
overlaySourceDir, isSite := overlay.OverlaySourceDir(overlayName)
if !isSite {
err = overlay.CreateSiteOverlay(overlayName)
if err != nil {
return err
}
createdSite = true
}
if !util.IsDir(overlaySourceDir) {
return fmt.Errorf("overlay does not exist: %s", overlayName)
}
@@ -102,12 +106,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
} else {
if startTime == fileInfo.ModTime() {
wwlog.Debug("No change detected. Not updating overlay.")
os.Exit(0)
if createdSite {
os.Remove(overlaySourceDir)
}
return nil
}
}
// try renaming the tempfile to overlayfile first
err := os.Rename(tempFile.Name(), overlayFile)
err = os.Rename(tempFile.Name(), overlayFile)
if err != nil {
// if it fails, which probably means that they exists on different partitions
// fallback to data copy

View File

@@ -27,7 +27,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
wwlog.Verbose("Copying '%s' into overlay '%s:%s'", source, overlayName, dest)
overlaySource = overlay.OverlaySourceDir(overlayName)
overlaySource, _ = overlay.OverlaySourceDir(overlayName)
if !util.IsDir(overlaySource) {
return fmt.Errorf("overlay does not exist: %s", overlayName)

View File

@@ -25,14 +25,14 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
}
if ListLong {
wwlog.Info("%-10s %5s %-5s %-18s %s\n", "PERM MODE", "UID", "GID", "SYSTEM-OVERLAY", "FILE PATH")
wwlog.Info("%-10s %5s %-5s %-18s %s\n", "PERM MODE", "UID", "GID", "SYSTEM-OVERLAY", "FILE PATH", "SITE")
} else {
wwlog.Info("%-30s %-12s\n", "OVERLAY NAME", "FILES/DIRS")
wwlog.Info("%-30s %-12s-%12s\n", "OVERLAY NAME", "FILES/DIRS", "SITE")
}
for o := range overlays {
name := overlays[o]
path := overlay.OverlaySourceDir(name)
path, isSite := overlay.OverlaySourceDir(name)
if util.IsDir(path) {
files := util.FindFiles(path)
@@ -50,7 +50,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
sys := s.Sys()
wwlog.Info("%v %5d %-5d %-18s /%s\n", perms, sys.(*syscall.Stat_t).Uid, sys.(*syscall.Stat_t).Gid, overlays[o], files[file])
wwlog.Info("%v %5d %-5d %-18s /%s\n", perms, sys.(*syscall.Stat_t).Uid, sys.(*syscall.Stat_t).Gid, overlays[o], files[file], isSite)
}
} else if ListContents {
var fileCount int
@@ -62,7 +62,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Info("%-30s %-12d\n", name, 0)
}
} else {
wwlog.Info("%-30s %-12d\n", name, len(files))
wwlog.Info("%-30s %-12d\n", name, len(files), isSite)
}
} else {

View File

@@ -11,13 +11,16 @@ import (
"github.com/warewulf/warewulf/internal/pkg/wwlog"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
func CobraRunE(cmd *cobra.Command, args []string) (err error) {
var overlaySourceDir string
overlayName := args[0]
dirName := args[1]
overlaySourceDir = overlay.OverlaySourceDir(overlayName)
err = overlay.CreateSiteOverlay(overlayName)
if err != nil {
return err
}
overlaySourceDir, _ = overlay.OverlaySourceDir(overlayName)
if !util.IsDir(overlaySourceDir) {
return fmt.Errorf("overlay does not exist: %s", overlayName)
@@ -27,7 +30,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
wwlog.Debug("Will create directory in overlay: %s:%s", overlayName, dirName)
err := os.MkdirAll(overlayDir, os.FileMode(PermMode))
err = os.MkdirAll(overlayDir, os.FileMode(PermMode))
if err != nil {
return fmt.Errorf("could not create directory: %s", path.Dir(overlayDir))
}

View File

@@ -22,7 +22,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
overlayName := args[0]
fileName := args[1]
overlaySourceDir = overlay.OverlaySourceDir(overlayName)
overlaySourceDir, _ = overlay.OverlaySourceDir(overlayName)
if !util.IsDir(overlaySourceDir) {
return fmt.Errorf("overlay dir: %s does not exist", overlaySourceDir)
@@ -66,6 +66,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
return err
}
tstruct.BuildSource = overlayFile
tstruct.Overlay = overlayName
buffer, backupFile, writeFile, err := overlay.RenderTemplateFile(overlayFile, tstruct)
if err != nil {
return err