Fix processing of UNDEF and UNSET during wwctl <node|profile> set. #1837

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-03-25 18:13:24 -06:00
parent 102916b1c8
commit 09488db3f6
8 changed files with 424 additions and 561 deletions

View File

@@ -201,7 +201,7 @@ func recursiveFlatten(obj interface{}) (hasContent bool) {
if typeObj.Elem().Field(i).Type == reflect.TypeOf([]string{}) {
del := false
for _, elem := range (valObj.Elem().Field(i).Interface()).([]string) {
if strings.EqualFold(elem, undef) {
if isUnsetValue(elem) {
del = true
}
}
@@ -213,7 +213,7 @@ func recursiveFlatten(obj interface{}) (hasContent bool) {
hasContent = true
}
case reflect.String:
if strings.EqualFold(valObj.Elem().Field(i).String(), undef) {
if isUnsetValue(valObj.Elem().Field(i).String()) {
valObj.Elem().Field(i).SetString("")
}
if valObj.Elem().Field(i).String() != "" {
@@ -421,3 +421,9 @@ func (netdev *NetDev) IpCIDR() string {
}
return ipCIDR.String()
}
var unsetValues = []string{"UNSET", "UNDEF"}
func isUnsetValue(value string) bool {
return util.InSlice(unsetValues, value)
}