diff --git a/pkg/kapp/resources/mod_field_copy.go b/pkg/kapp/resources/mod_field_copy.go index 5d483f454..52d1af7fc 100644 --- a/pkg/kapp/resources/mod_field_copy.go +++ b/pkg/kapp/resources/mod_field_copy.go @@ -139,7 +139,7 @@ func (t FieldCopyMod) copyIntoMap(obj map[string]interface{}, fullPath Path, src val, found, err := t.obtainValue(srcRes.unstructured().Object, fullPath) if err != nil { - return false, fmt.Errorf("Obtaining value from '%s': %s", src, err) + return false, err } else if !found { continue } @@ -159,7 +159,7 @@ func (t FieldCopyMod) obtainValue(obj interface{}, path Path) (interface{}, bool case part.MapKey != nil: typedObj, ok := obj.(map[string]interface{}) if !ok { - return nil, false, fmt.Errorf("Unexpected non-map found for key '%s': %T", *part.MapKey, obj) + return nil, false, fmt.Errorf("Unexpected non-map found: %T", obj) } var found bool @@ -167,10 +167,6 @@ func (t FieldCopyMod) obtainValue(obj interface{}, path Path) (interface{}, bool if !found { return nil, false, nil // index is not found return } - // TODO check strictness? - if !isLast && obj == nil { - return nil, false, nil // expected to be a map but was a nil value, return - } case part.ArrayIndex != nil: if isLast { diff --git a/pkg/kapp/resources/mod_field_copy_test.go b/pkg/kapp/resources/mod_field_copy_test.go index 1d502d81c..762b785d0 100644 --- a/pkg/kapp/resources/mod_field_copy_test.go +++ b/pkg/kapp/resources/mod_field_copy_test.go @@ -29,7 +29,7 @@ metadata: label-key: existing-label-val`, }, { - Description: "when destination is non-map", + Description: "copy from existing, when destination is non-map", Res: ` metadata: labels: null`, @@ -37,7 +37,7 @@ metadata: metadata: labels: label-key: new-label-val`, - Sources: []ctlres.FieldCopyModSource{ctlres.FieldCopyModSourceNew, ctlres.FieldCopyModSourceExisting}, + Sources: []ctlres.FieldCopyModSource{ctlres.FieldCopyModSourceExisting}, Path: ctlres.NewPathFromStrings([]string{"metadata", "labels", "label-key"}), NewRes: ` metadata: @@ -55,7 +55,7 @@ metadata: Expected: ` metadata: labels: null`, - Sources: []ctlres.FieldCopyModSource{ctlres.FieldCopyModSourceNew, ctlres.FieldCopyModSourceExisting}, + Sources: []ctlres.FieldCopyModSource{ctlres.FieldCopyModSourceExisting}, Path: ctlres.NewPathFromStrings([]string{"metadata", "labels", "label-key"}), NewRes: ` metadata: