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:
@@ -99,11 +99,7 @@ func NewProfile(id string) (profileconf Profile) {
|
||||
}
|
||||
|
||||
func EmptyNode() (nodeconf Node) {
|
||||
nodeconf.Ipmi = new(IpmiConf)
|
||||
nodeconf.Ipmi.Tags = map[string]string{}
|
||||
nodeconf.Kernel = new(KernelConf)
|
||||
nodeconf.NetDevs = make(map[string]*NetDev)
|
||||
nodeconf.Tags = map[string]string{}
|
||||
nodeconf.Expand()
|
||||
return nodeconf
|
||||
}
|
||||
|
||||
@@ -111,14 +107,37 @@ func EmptyNode() (nodeconf Node) {
|
||||
Creates a ProfileConf but doesn't add it to the database.
|
||||
*/
|
||||
func EmptyProfile() (profileconf Profile) {
|
||||
profileconf.Ipmi = new(IpmiConf)
|
||||
profileconf.Ipmi.Tags = map[string]string{}
|
||||
profileconf.Kernel = new(KernelConf)
|
||||
profileconf.NetDevs = make(map[string]*NetDev)
|
||||
profileconf.Tags = map[string]string{}
|
||||
profileconf.Expand()
|
||||
return profileconf
|
||||
}
|
||||
|
||||
func (nodeconf *Node) Expand() {
|
||||
nodeconf.Profile.Expand()
|
||||
}
|
||||
|
||||
func (profile *Profile) Expand() {
|
||||
if profile.Ipmi == nil {
|
||||
profile.Ipmi = new(IpmiConf)
|
||||
}
|
||||
if profile.Ipmi.Tags == nil {
|
||||
profile.Ipmi.Tags = make(map[string]string)
|
||||
}
|
||||
if profile.Kernel == nil {
|
||||
profile.Kernel = new(KernelConf)
|
||||
}
|
||||
if profile.NetDevs == nil {
|
||||
profile.NetDevs = make(map[string]*NetDev)
|
||||
}
|
||||
for i := range profile.NetDevs {
|
||||
if profile.NetDevs[i].Tags == nil {
|
||||
profile.NetDevs[i].Tags = make(map[string]string)
|
||||
}
|
||||
}
|
||||
if profile.Tags == nil {
|
||||
profile.Tags = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Flattens out a NodeConf, which means if there are no explicit values in *IpmiConf
|
||||
or *KernelConf, these pointer will set to nil. This will remove something like
|
||||
|
||||
Reference in New Issue
Block a user