Skip to content

Commit

Permalink
adopted some nits
Browse files Browse the repository at this point in the history
Signed-off-by: sethiyash <[email protected]>
  • Loading branch information
sethiyash committed Jun 5, 2023
1 parent ab33947 commit f07be0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/kapp/resources/mod_field_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func (t FieldCopyMod) IsResourceMatching(res Resource) bool {

func (t FieldCopyMod) ApplyFromMultiple(res Resource, srcs map[FieldCopyModSource]Resource) error {
for _, src := range t.Sources {
// Make a copy of resource, to avoid modifications
// that may be done even in case when there is nothing to copy
updatedRes := res.DeepCopy()
source, found := srcs[src]
if !found {
continue
}
// Make a copy of resource, to avoid modifications
// that may be done even in case when there is nothing to copy
updatedRes := res.DeepCopy()
updated, err := t.apply(updatedRes.unstructured().Object, source.unstructured().Object, t.Path, Path{}, srcs)
if err != nil {
return fmt.Errorf("FieldCopyMod for path '%s' on resource '%s': %s", t.Path.AsString(), res.Description(), err)
Expand All @@ -47,6 +47,7 @@ func (t FieldCopyMod) ApplyFromMultiple(res Resource, srcs map[FieldCopyModSourc
res.setUnstructured(updatedRes.unstructured())
}
}

return nil
}

Expand Down Expand Up @@ -159,19 +160,21 @@ func (t FieldCopyMod) apply(obj interface{}, srcObj interface{}, path Path, full
if err != nil {
return false, err
}
allUpdated := true
var anyUpdated bool
for _, key := range matchedKeys {
newPath := append(Path{&PathPart{MapKey: &key}}, path[i+1:]...)
newFullPath := fullPath[:len(fullPath)-1]
updated, err := t.apply(obj, srcObj, newPath, newFullPath, srcs)
if err != nil {
return false, err
}
if !updated {
allUpdated = false
if updated {
anyUpdated = true
}
}
return allUpdated, nil

return anyUpdated, nil

default:
panic(fmt.Sprintf("Unexpected path part: %#v", part))
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/kapp/resources/mod_field_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (t FieldRemoveMod) apply(obj interface{}, path Path) error {
return err
}
}

return nil // dealt with children, get out

case part.ArrayIndex.Index != nil:
Expand Down Expand Up @@ -108,6 +109,7 @@ func (t FieldRemoveMod) apply(obj interface{}, path Path) error {
return err
}
}

return nil

default:
Expand Down

0 comments on commit f07be0c

Please sign in to comment.