From 2e829853805126920ca5952be59056e4ed8277fb Mon Sep 17 00:00:00 2001 From: nimohunter Date: Mon, 16 Sep 2019 09:30:01 +0800 Subject: [PATCH] empty list or map item return error --- k8sdeps/kunstruct/factory.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/k8sdeps/kunstruct/factory.go b/k8sdeps/kunstruct/factory.go index 9d8a97288..d4f7118ca 100644 --- a/k8sdeps/kunstruct/factory.go +++ b/k8sdeps/kunstruct/factory.go @@ -110,26 +110,29 @@ func (kf *KunstructuredFactoryImpl) validate(u unstructured.Unstructured) error 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 nil } -func checkItemNil(in interface{}) (bool, string) { - if in == nil { - return true, "" - } +func checkListItemNil(in interface{}) (bool, string) { + //if in == nil { + // return true, "" + //} switch v := in.(type) { case map[string]interface{}: for key, s := range v { - if result, path := checkItemNil(s); result { + if result, path := checkListItemNil(s); result { return result, key + "/" + path } } case []interface{}: 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 } }