mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
empty list or map item return error
This commit is contained in:
@@ -110,26 +110,29 @@ func (kf *KunstructuredFactoryImpl) validate(u unstructured.Unstructured) error
|
|||||||
return fmt.Errorf("missing metadata.name in object %v", u)
|
return fmt.Errorf("missing metadata.name in object %v", u)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result, path := checkItemNil(u.Object); result {
|
if result, path := checkListItemNil(u.Object); result {
|
||||||
return fmt.Errorf("empty item at %v in object %v", path, u)
|
return fmt.Errorf("empty item at %v in object %v", path, u)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkItemNil(in interface{}) (bool, string) {
|
func checkListItemNil(in interface{}) (bool, string) {
|
||||||
if in == nil {
|
//if in == nil {
|
||||||
return true, ""
|
// return true, ""
|
||||||
}
|
//}
|
||||||
switch v := in.(type) {
|
switch v := in.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
for key, s := range v {
|
for key, s := range v {
|
||||||
if result, path := checkItemNil(s); result {
|
if result, path := checkListItemNil(s); result {
|
||||||
return result, key + "/" + path
|
return result, key + "/" + path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
for index, s := range v {
|
for index, s := range v {
|
||||||
if result, path := checkItemNil(s); result {
|
if s == nil {
|
||||||
|
return true, ""
|
||||||
|
}
|
||||||
|
if result, path := checkListItemNil(s); result {
|
||||||
return result, "[" + strconv.Itoa(index) + "]/" + path
|
return result, "[" + strconv.Itoa(index) + "]/" + path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user