prefer profile overlay value over node one

Signed-off-by: xu yang <xyang@ciq.com>
This commit is contained in:
xu yang
2024-08-07 09:53:42 +00:00
committed by Jonathon Anderson
parent 2b82c2074a
commit cc617007cd
4 changed files with 63 additions and 6 deletions

View File

@@ -51,6 +51,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added a link to an example SELinux-enabled node image in documentation. #1305
- Refine error handling for `wwctl configure`. #1273
- Updated dracut guidance for building initramfs. #1369
- Preferred profile overlay value over node one for node's `SystemOverlay` entry. #1259
## v4.5.6, 2024-08-05

View File

@@ -32,11 +32,19 @@ func recursiveFields(obj interface{}, emptyFields bool, prefix string) (output [
if typeObj.Elem().Field(i).Type == reflect.TypeOf(Entry{}) {
myField := valObj.Elem().Field(i).Interface().(Entry)
if emptyFields || myField.Get() != "" {
output = append(output, NodeFields{
Field: prefix + typeObj.Elem().Field(i).Name,
Source: myField.Source(),
Value: myField.Print(),
})
if typeObj.Elem().Field(i).Name == "SystemOverlay" {
output = append(output, NodeFields{
Field: prefix + typeObj.Elem().Field(i).Name,
Source: myField.Source(),
Value: myField.PrintPreferAlt(),
})
} else {
output = append(output, NodeFields{
Field: prefix + typeObj.Elem().Field(i).Name,
Source: myField.Source(),
Value: myField.Print(),
})
}
}
} else if typeObj.Elem().Field(i).Type == reflect.TypeOf(map[string]*Entry{}) {
for key, val := range valObj.Elem().Field(i).Interface().(map[string]*Entry) {

View File

@@ -287,6 +287,17 @@ func (ent *Entry) GetSlice() []string {
return []string{}
}
func (ent *Entry) GetSlicePreferAlt() []string {
retval := append(ent.altvalue, ent.value...)
if len(retval) != 0 {
return cleanList(retval)
}
if len(ent.def) != 0 {
return ent.def
}
return []string{}
}
/*
Get the real value, not the alternative of default one.
*/
@@ -388,6 +399,43 @@ func (ent *Entry) Print() string {
return "--"
}
/* Gets the the entry of the value in following order
* profile value if set
* node value if set
* default value if set
*/
func (ent *Entry) PrintPreferAlt() string {
if !ent.isSlice {
if len(ent.altvalue) != 0 {
return ent.altvalue[0]
}
if len(ent.value) != 0 {
return ent.value[0]
}
if len(ent.def) != 0 {
return "(" + ent.def[0] + ")"
}
} else {
var ret string
if len(ent.value) != 0 || len(ent.altvalue) != 0 {
combList := append(ent.altvalue, ent.value...)
ret = strings.Join(cleanList(combList), ",")
if len(negList(combList)) > 0 {
ret += " ~{" + strings.Join(negList(combList), ",") + "}"
}
}
if ret != "" {
return ret
}
if len(ent.def) != 0 {
return "(" + strings.Join(ent.def, ",") + ")"
}
}
return "--"
}
/*
Was used for combined stringSlice

View File

@@ -31,7 +31,7 @@ Build all overlays (runtime and generic) for a node
func BuildAllOverlays(nodes []node.NodeInfo) error {
for _, n := range nodes {
sysOverlays := n.SystemOverlay.GetSlice()
sysOverlays := n.SystemOverlay.GetSlicePreferAlt()
wwlog.Info("Building system overlays for %s: [%s]", n.Id.Get(), strings.Join(sysOverlays, ", "))
err := BuildOverlay(n, "system", sysOverlays)
if err != nil {