Refactor node

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-10-25 14:17:00 -06:00
parent e6f5c63c21
commit 0665d5dc88
35 changed files with 112 additions and 114 deletions

View File

@@ -35,17 +35,17 @@ type TemplateStruct struct {
Warewulf warewulfconf.WarewulfConf
Tftp warewulfconf.TFTPConf
Paths warewulfconf.BuildConfig
AllNodes []node.NodeConf
node.NodeConf
AllNodes []node.Node
node.Node
// backward compatiblity
Container string
ThisNode *node.NodeConf
ThisNode *node.Node
}
/*
Initialize an TemplateStruct with the given node.NodeInfo
*/
func InitStruct(nodeData node.NodeConf) (TemplateStruct, error) {
func InitStruct(nodeData node.Node) (TemplateStruct, error) {
var tstruct TemplateStruct
hostname, _ := os.Hostname()
tstruct.BuildHost = hostname
@@ -78,7 +78,7 @@ func InitStruct(nodeData node.NodeConf) (TemplateStruct, error) {
dt := time.Now()
tstruct.BuildTime = dt.Format("01-02-2006 15:04:05 MST")
tstruct.BuildTimeUnix = strconv.FormatInt(dt.Unix(), 10)
tstruct.NodeConf.Tags = map[string]string{}
tstruct.Node.Tags = map[string]string{}
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
dec := gob.NewDecoder(&buf)

View File

@@ -106,7 +106,7 @@ func templateContainerFileInclude(containername string, filepath string) string
// don't return an error as we use this function for template evaluation,
// so error will turn up there as the return string
func createIgnitionJson(node *node.NodeConf) string {
func createIgnitionJson(node *node.Node) string {
conf, rep, err := node.GetConfig()
if len(conf.Storage.Disks) == 0 && len(conf.Storage.Filesystems) == 0 {
wwlog.Debug("no disks or filesystems present, don't create a json object")

View File

@@ -28,7 +28,7 @@ var (
/*
Build all overlays for a node
*/
func BuildAllOverlays(nodes []node.NodeConf) error {
func BuildAllOverlays(nodes []node.Node) error {
for _, n := range nodes {
sysOverlays := n.SystemOverlay
@@ -50,7 +50,7 @@ func BuildAllOverlays(nodes []node.NodeConf) error {
// TODO: Add an Overlay Delete for both sourcedir and image
func BuildSpecificOverlays(nodes []node.NodeConf, overlayNames []string) error {
func BuildSpecificOverlays(nodes []node.Node, overlayNames []string) error {
for _, n := range nodes {
wwlog.Info("Building overlay for %s: %v", n, overlayNames)
for _, overlayName := range overlayNames {
@@ -123,7 +123,7 @@ func OverlayInit(overlayName string) error {
/*
Build the given overlays for a node and create a Image for them
*/
func BuildOverlay(nodeConf node.NodeConf, context string, overlayNames []string) error {
func BuildOverlay(nodeConf node.Node, context string, overlayNames []string) error {
if len(overlayNames) == 0 && context == "" {
return nil
}
@@ -172,7 +172,7 @@ func BuildOverlay(nodeConf node.NodeConf, context string, overlayNames []string)
Build the given overlays for a node in the given directory. If the given does not
exists it will be created.
*/
func BuildOverlayIndir(nodeData node.NodeConf, overlayNames []string, outputDir string) error {
func BuildOverlayIndir(nodeData node.Node, overlayNames []string, outputDir string) error {
if len(overlayNames) == 0 {
return nil
}

View File

@@ -265,7 +265,7 @@ func Test_BuildAllOverlays(t *testing.T) {
defer os.RemoveAll(provisionDir)
conf.Paths.WWProvisiondir = provisionDir
var nodes []node.NodeConf
var nodes []node.Node
for i, nodeName := range tt.nodes {
nodeInfo := node.NewNode(nodeName)
if tt.systemOverlays != nil {
@@ -363,7 +363,7 @@ func Test_BuildSpecificOverlays(t *testing.T) {
defer os.RemoveAll(provisionDir)
conf.Paths.WWProvisiondir = provisionDir
var nodes []node.NodeConf
var nodes []node.Node
for _, nodeName := range tt.nodes {
nodeInfo := node.NewNode(nodeName)
nodes = append(nodes, nodeInfo)