prefer profile overlay value over node one
Signed-off-by: xu yang <xyang@ciq.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
2b82c2074a
commit
cc617007cd
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user