Skip to content

Commit

Permalink
Revert "be less strict about obtaing values from null maps in FieldCo…
Browse files Browse the repository at this point in the history
…pyMod"

This reverts commit 67bad4f.
  • Loading branch information
cppforlife committed Jul 27, 2019
1 parent a7ad35d commit 2bfcbe4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 2 additions & 6 deletions pkg/kapp/resources/mod_field_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -159,18 +159,14 @@ 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
obj, found = typedObj[*part.MapKey]
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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/kapp/resources/mod_field_copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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`,
Expected: `
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:
Expand All @@ -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:
Expand Down

0 comments on commit 2bfcbe4

Please sign in to comment.