Skip to content

Commit 9f1d5ac

Browse files
committed
fix: check both prev and current ids for filtering reject targets
1 parent 9756d92 commit 9f1d5ac

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
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

api/krusty/replacementtransformer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ spec:
604604
spec:
605605
containers:
606606
- image: app1:1.0
607-
name: something-else
607+
name: app
608608
---
609609
apiVersion: v1
610610
data:

0 commit comments

Comments
 (0)