Skip to content

Commit 34c8c0d

Browse files
committed
check both prev and current ids for filtering reject targets
1 parent 5e6cbac commit 34c8c0d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

api/filters/replacement/replacement.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targetSelectors []
126126
}
127127

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

171-
func rejectId(rejects []*types.Selector, id *resid.ResId) bool {
171+
func containsRejectId(rejects []*types.Selector, ids []resid.ResId) bool {
172172
for _, r := range rejects {
173-
if !r.ResId.IsEmpty() && id.IsSelectedBy(r.ResId) {
174-
return true
173+
if r.ResId.IsEmpty() {
174+
continue
175+
}
176+
for _, id := range ids {
177+
if id.IsSelectedBy(r.ResId) {
178+
return true
179+
}
175180
}
176181
}
177182
return false

0 commit comments

Comments
 (0)