return error for duplicate keys rather than panicking

This commit is contained in:
Natasha Sarkar
2021-03-03 12:03:36 -08:00
parent 93dd571df9
commit 722b0131f0
15 changed files with 86 additions and 31 deletions

View File

@@ -98,11 +98,12 @@ func (r *Resource) GetString(p string) (string, error) {
return r.kunStr.GetString(p)
}
func (r *Resource) IsEmpty() bool {
return len(r.kunStr.Map()) == 0
func (r *Resource) IsEmpty() (bool, error) {
m, err := r.kunStr.Map()
return len(m) == 0, err
}
func (r *Resource) Map() map[string]interface{} {
func (r *Resource) Map() (map[string]interface{}, error) {
return r.kunStr.Map()
}
@@ -488,7 +489,11 @@ func (r *Resource) ApplySmPatch(patch *Resource) error {
if err != nil {
return err
}
if !r.IsEmpty() {
empty, err := r.IsEmpty()
if err != nil {
return err
}
if !empty {
r.SetName(n)
r.SetNamespace(ns)
}