Skip to content

Commit cd9224e

Browse files
committed
Try empty prefix/suffix but fall back on duplicates
1 parent fd23a04 commit cd9224e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

api/filters/nameref/nameref.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ func (f Filter) roleRefFilter() sieveFunc {
284284
return previousIdSelectedByGvk(roleRefGvk)
285285
}
286286

287-
func prefixSuffixEquals(other resource.ResCtx) sieveFunc {
287+
func prefixSuffixEquals(other resource.ResCtx, allowEmpty bool) sieveFunc {
288288
return func(r *resource.Resource) bool {
289-
return r.PrefixesSuffixesEquals(other)
289+
return r.PrefixesSuffixesEquals(other, allowEmpty)
290290
}
291291
}
292292

@@ -325,7 +325,10 @@ func (f Filter) selectReferral(
325325
if len(candidates) == 1 {
326326
return candidates[0], nil
327327
}
328-
candidates = doSieve(candidates, prefixSuffixEquals(f.Referrer))
328+
candidates = doSieve(candidates, prefixSuffixEquals(f.Referrer, true))
329+
if len(candidates) > 1 {
330+
candidates = doSieve(candidates, prefixSuffixEquals(f.Referrer, false))
331+
}
329332
if len(candidates) == 1 {
330333
return candidates[0], nil
331334
}

api/resource/resource.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,18 @@ func (r *Resource) getCsvAnnotation(name string) []string {
290290
// PrefixesSuffixesEquals is conceptually doing the same task
291291
// as OutermostPrefixSuffix but performs a deeper comparison
292292
// of the suffix and prefix slices.
293-
func (r *Resource) PrefixesSuffixesEquals(o ResCtx) bool {
294-
eitherPrefixEmpty := len(r.GetNamePrefixes()) == 0 || len(o.GetNamePrefixes()) == 0
295-
eitherSuffixEmpty := len(r.GetNameSuffixes()) == 0 || len(o.GetNameSuffixes()) == 0
293+
func (r *Resource) PrefixesSuffixesEquals(o ResCtx, allowEmpty bool) bool {
294+
if allowEmpty {
295+
eitherPrefixEmpty := len(r.GetNamePrefixes()) == 0 || len(o.GetNamePrefixes()) == 0
296+
eitherSuffixEmpty := len(r.GetNameSuffixes()) == 0 || len(o.GetNameSuffixes()) == 0
296297

297-
return (eitherPrefixEmpty || utils.SameEndingSubSlice(r.GetNamePrefixes(), o.GetNamePrefixes())) &&
298-
(eitherSuffixEmpty || utils.SameEndingSubSlice(r.GetNameSuffixes(), o.GetNameSuffixes()))
298+
return (eitherPrefixEmpty || utils.SameEndingSubSlice(r.GetNamePrefixes(), o.GetNamePrefixes())) &&
299+
(eitherSuffixEmpty || utils.SameEndingSubSlice(r.GetNameSuffixes(), o.GetNameSuffixes()))
300+
} else {
301+
return utils.SameEndingSubSlice(r.GetNamePrefixes(), o.GetNamePrefixes()) &&
302+
utils.SameEndingSubSlice(r.GetNameSuffixes(), o.GetNameSuffixes())
303+
304+
}
299305
}
300306

301307
// RemoveBuildAnnotations removes annotations created by the build process.

0 commit comments

Comments
 (0)