Skip to content

Commit

Permalink
check both prev and current ids for filtering reject targets
Browse files Browse the repository at this point in the history
  • Loading branch information
bugoverdose committed Aug 10, 2023
1 parent 5e6cbac commit 34c8c0d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions api/filters/replacement/replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targetSelectors []
}

// filter targets by matching resource IDs
for i, id := range ids {
if id.IsSelectedBy(selector.Select.ResId) && !rejectId(selector.Reject, &ids[i]) {
for _, id := range ids {
if id.IsSelectedBy(selector.Select.ResId) && !containsRejectId(selector.Reject, ids) {
err := copyValueToTarget(possibleTarget, value, selector)
if err != nil {
return nil, err
Expand Down Expand Up @@ -168,10 +168,15 @@ func matchesAnnoAndLabelSelector(n *yaml.RNode, selector *types.Selector) (bool,
return annoMatch && labelMatch, nil
}

func rejectId(rejects []*types.Selector, id *resid.ResId) bool {
func containsRejectId(rejects []*types.Selector, ids []resid.ResId) bool {
for _, r := range rejects {
if !r.ResId.IsEmpty() && id.IsSelectedBy(r.ResId) {
return true
if r.ResId.IsEmpty() {
continue
}
for _, id := range ids {
if id.IsSelectedBy(r.ResId) {
return true
}
}
}
return false
Expand Down

0 comments on commit 34c8c0d

Please sign in to comment.