Moving warewulfd code around and implementing new API for config.*()

This commit is contained in:
Gregory Kurtzer
2020-11-11 22:16:24 -08:00
parent 9a9672a060
commit fa2a7e26d3
18 changed files with 140 additions and 447 deletions

View File

@@ -11,9 +11,8 @@ import (
"path"
)
const kernelProvisionPath = "/provision/kernel/"
func Build(nodeList []assets.NodeInfo, force bool) error {
config := config.New()
set := make(map[string]int)
wwlog.Printf(wwlog.INFO, "Importing Kernels:\n")
@@ -29,12 +28,13 @@ func Build(nodeList []assets.NodeInfo, force bool) error {
for kernelVersion := range set {
kernelImage := "/boot/vmlinuz-"+kernelVersion
kernelDrivers := "/lib/modules/"+kernelVersion
kernelDestination := path.Join(config.LocalStateDir, kernelProvisionPath, "vmlinuz-"+kernelVersion)
driversDestination := path.Join(config.LocalStateDir, kernelProvisionPath, "kmods-"+kernelVersion+".img")
kernelDestination := config.KernelImage(kernelVersion)
driversDestination := config.KmodsImage(kernelVersion)
// Create the destination paths just in case it doesn't exist
os.MkdirAll(path.Dir(kernelDestination), 0755)
os.MkdirAll(path.Dir(driversDestination), 0755)
// Create the kernel destination path just in case it doesn't exist
os.MkdirAll(path.Join(config.LocalStateDir, kernelProvisionPath), 0755)
if _, err := os.Stat(kernelImage); err == nil {
if util.PathIsNewer(kernelImage, kernelDestination) && force == false {

View File

@@ -27,12 +27,14 @@ func fileInclude(path string) string {
func Build(nodeList []assets.NodeInfo, force bool) error {
wwlog.Printf(wwlog.INFO, "Building Runtime Overlays:\n")
config := config.New()
wwlog.SetIndent(4)
for _, node := range nodeList {
if node.RuntimeOverlay != "" {
OverlayDir := path.Join(config.LocalStateDir, "/overlays/runtime/", node.RuntimeOverlay)
OverlayFile := path.Join(config.LocalStateDir, "/provision/overlays/runtime/", node.Fqdn+".img")
OverlayDir := config.RuntimeOverlaySource(node.RuntimeOverlay)
OverlayFile := config.RuntimeOverlayImage(node.Fqdn)
wwlog.Printf(wwlog.VERBOSE, "Building Runtime Overlay for: %s\n", node.Fqdn)

View File

@@ -27,12 +27,14 @@ func fileInclude(path string) string {
func Build(nodeList []assets.NodeInfo, force bool) error {
wwlog.Printf(wwlog.INFO, "Building System Overlays:\n")
config := config.New()
wwlog.SetIndent(4)
for _, node := range nodeList {
if node.SystemOverlay != "" {
OverlayDir := path.Join(config.LocalStateDir, "/overlays/system/", node.SystemOverlay)
OverlayFile := path.Join(config.LocalStateDir, "/provision/overlays/system/", node.Fqdn+".img")
OverlayDir := config.SystemOverlaySource(node.SystemOverlay)
OverlayFile := config.SystemOverlayImage(node.Fqdn)
wwlog.Printf(wwlog.VERBOSE, "Building System Overlay for: %s\n", node.Fqdn)

View File

@@ -2,6 +2,7 @@ package vnfs
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/config"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/vnfs"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
@@ -10,6 +11,7 @@ import (
)
func BuildContainerdir(v vnfs.VnfsObject) {
config := config.New()
if _, err := os.Stat(v.Source()); err != nil {
wwlog.Printf(wwlog.INFO, "%-35s: Skipping (bad path)\n", v.Name())
@@ -17,31 +19,35 @@ func BuildContainerdir(v vnfs.VnfsObject) {
}
wwlog.Printf(wwlog.DEBUG, "Checking if there have been any updates to the VNFS directory\n")
if util.PathIsNewer(v.Source(), v.Image()) {
if util.PathIsNewer(v.Source(), config.VnfsImage(v.NameClean())) {
if buildForce == false {
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, VNFS is current\n", v.Name())
return
}
}
wwlog.Printf(wwlog.DEBUG, "Making the directory: %s\n", path.Dir(v.Image()))
err := os.MkdirAll(path.Dir(v.Image()), 0755)
wwlog.Printf(wwlog.DEBUG, "Making the directory: %s\n", path.Dir(config.VnfsImage(v.NameClean())))
err := os.MkdirAll(path.Dir(config.VnfsImage(v.NameClean())), 0755)
if err != nil {
fmt.Printf("ERROR: %s\n", err)
return
}
wwlog.Printf(wwlog.DEBUG, "Building VNFS image: '%s' -> '%s'\n", v.Source(), v.Image())
err = buildVnfs(v.Source(), v.Image())
wwlog.Printf(wwlog.DEBUG, "Building VNFS image: '%s' -> '%s'\n", v.Source(), config.VnfsImage(v.NameClean()))
err = buildVnfs(v.Source(), config.VnfsImage(v.NameClean()))
if err != nil {
fmt.Printf("ERROR: %s\n", err)
os.Exit(1)
}
wwlog.Printf(wwlog.DEBUG, "Building links for Warewulf access to chroot\n")
err = buildLinks(v, v.Source())
// Setup links from OCI rootfs to chroot path
_ = os.Remove(config.VnfsChroot(v.NameClean()) + "-link")
err = os.Symlink(v.Source(), config.VnfsChroot(v.NameClean())+"-link")
if err != nil {
os.Exit(1)
}
err = os.Rename(config.VnfsChroot(v.NameClean())+"-link", config.VnfsChroot(v.NameClean()))
if err != nil {
fmt.Printf("ERROR: %s\n", err)
os.Exit(1)
}

View File

@@ -11,13 +11,13 @@ import (
"path"
)
const (
OciCacheDir = config.LocalStateDir + "/oci"
VnfsHashDir = config.LocalStateDir + "/oci/vnfs/hash/"
)
func BuildDocker(v vnfs.VnfsObject) {
wwlog.Printf(wwlog.VERBOSE, "Building OCI Container: %s\n", v.Source())
config := config.New()
OciCacheDir := config.LocalStateDir + "/oci"
VnfsHashDir := config.LocalStateDir + "/oci/vnfs"
c, err := oci.NewCache(oci.OptSetCachePath(OciCacheDir))
if err != nil {
@@ -34,7 +34,7 @@ func BuildDocker(v vnfs.VnfsObject) {
hashDestination := VnfsHashDir + path.Base(sourcePath)
name, err := os.Readlink(v.Image())
name, err := os.Readlink(config.VnfsImage(v.NameClean()))
if err == nil {
if name == hashDestination {
wwlog.Printf(wwlog.INFO, "%-35s: Skipping, VNFS is current\n", v.Name())
@@ -47,12 +47,12 @@ func BuildDocker(v vnfs.VnfsObject) {
fmt.Printf("ERROR: %s\n", err)
return
}
err = os.MkdirAll(path.Dir(v.Image()), 0755)
err = os.MkdirAll(path.Dir(config.VnfsImage(v.NameClean())), 0755)
if err != nil {
fmt.Printf("ERROR: %s\n", err)
return
}
err = os.MkdirAll(path.Dir(v.Root()), 0755)
err = os.MkdirAll(path.Dir(config.VnfsChroot(v.NameClean())), 0755)
if err != nil {
fmt.Printf("ERROR: %s\n", err)
return
@@ -68,19 +68,29 @@ func BuildDocker(v vnfs.VnfsObject) {
wwlog.Printf(wwlog.VERBOSE, "Finalizing Build\n")
_ = os.Remove(v.Image() + "-link")
err = os.Symlink(hashDestination, v.Image()+"-link")
// Setup links from OCI image to provision path
_ = os.Remove(config.VnfsImage(v.NameClean()) + "-link")
err = os.Symlink(hashDestination, config.VnfsImage(v.NameClean())+"-link")
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
err = os.Rename(v.Image()+"-link", v.Image())
err = os.Rename(config.VnfsImage(v.NameClean())+"-link", config.VnfsImage(v.NameClean()))
if err != nil {
os.Exit(1)
}
err = buildLinks(v, sourcePath)
// Setup links from OCI rootfs to chroot path
_ = os.Remove(config.VnfsChroot(v.NameClean()) + "-link")
err = os.Symlink(sourcePath, config.VnfsChroot(v.NameClean())+"-link")
if err != nil {
wwlog.Printf(wwlog.ERROR, "%s\n", err)
os.Exit(1)
}
err = os.Rename(config.VnfsChroot(v.NameClean())+"-link", config.VnfsChroot(v.NameClean()))
if err != nil {
os.Exit(1)
}
wwlog.Printf(wwlog.INFO, "%-35s: Done\n", v.Name())

View File

@@ -1,12 +1,8 @@
package vnfs
import (
"fmt"
"github.com/hpcng/warewulf/internal/pkg/vnfs"
"os"
"os/exec"
"path"
)
func buildVnfs(source string, dest string) error {
@@ -16,26 +12,3 @@ func buildVnfs(source string, dest string) error {
return err
}
func buildLinks(v vnfs.VnfsObject, source string) error {
// Just incase the temporary link location is present, remove it if we can
_ = os.Remove(v.Root() + "-link")
// Just incase the directory doesn't exist, make it
_ = os.MkdirAll(path.Dir(v.Root()), 0755)
// Link to a temporary location so we can atomically move the link into place
err := os.Symlink(source, v.Root()+"-link")
if err != nil {
return err
}
// Atomically move the link into place
err = os.Rename(v.Root()+"-link", v.Root())
if err != nil {
return err
}
return nil
}