Expand nodes when rendering overlay templates
Before #1628, all default constructors for nodes and profiles attempted to construct objects with pre-populated empty fields (e.g., for pointers to member structs and for collections that default to nil). Changes to MergeNode in #1629 changed this behavior intentionally to simplify the generation of minimal json; but this had the unintended side-effect of breaking existing templates that may now encounter a nil pointer, particularly when accessing member structs. Introduced here, the Expand() methods on Node and Profile are now responsible for populating such fields, and Node.Expand() is now called during template processing. Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -53,9 +53,7 @@ func InitStruct(overlayName string, nodeData node.Node, allNodes []node.Node) (T
|
||||
tstruct.BuildHost = hostname
|
||||
controller := warewulfconf.Get()
|
||||
tstruct.ThisNode = &nodeData
|
||||
if tstruct.ThisNode.Kernel == nil {
|
||||
tstruct.ThisNode.Kernel = new(node.KernelConf)
|
||||
}
|
||||
tstruct.ThisNode.Expand()
|
||||
if tstruct.ThisNode.Kernel.Version == "" {
|
||||
if kernel_ := kernel.FromNode(tstruct.ThisNode); kernel_ != nil {
|
||||
tstruct.ThisNode.Kernel.Version = kernel_.Version()
|
||||
@@ -77,6 +75,9 @@ func InitStruct(overlayName string, nodeData node.Node, allNodes []node.Node) (T
|
||||
tstruct.Container = nodeData.ContainerName
|
||||
// Backwards compatibility for templates using "Keys"
|
||||
tstruct.AllNodes = allNodes
|
||||
for i := range tstruct.AllNodes {
|
||||
tstruct.AllNodes[i].Expand()
|
||||
}
|
||||
dt := time.Now()
|
||||
tstruct.BuildTime = dt.Format("01-02-2006 15:04:05 MST")
|
||||
tstruct.BuildTimeUnix = strconv.FormatInt(dt.Unix(), 10)
|
||||
|
||||
Reference in New Issue
Block a user