Skip to content

Commit

Permalink
IsInKustomizeCtx should use end of nameprefix array (code review)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrette committed Aug 29, 2019
1 parent 93cedba commit 31262cc
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions pkg/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,37 +146,19 @@ func (r *Resource) GetOutermostNameSuffix() string {
return r.nameSuffixes[len(r.nameSuffixes)-1]
}

func sameBeginningSubarray(a, b []string) bool {
maxlen := len(b)
if len(a) < len(b) {
maxlen = len(a)
}

if maxlen == 0 {
return true
}

for i := 0; i <= maxlen-1; i++ {
if a[i] != b[i] {
return false
}
}
return true
}

func sameEndingSubarray(a, b []string) bool {
maxlen := len(b)
compareLen := len(b)
if len(a) < len(b) {
maxlen = len(a)
compareLen = len(a)
}

if maxlen == 0 {
if compareLen == 0 {
return true
}

alen := len(a) - 1
blen := len(b) - 1
for i := 0; i <= maxlen-1; i++ {
for i := 0; i <= compareLen-1; i++ {
if a[alen-i] != b[blen-i] {
return false
}
Expand All @@ -202,10 +184,17 @@ func (r *Resource) OutermostPrefixSuffixEquals(o ResCtx) bool {

// PrefixesSuffixesEquals is conceptually doing the same task
// as OutermostPrefixSuffix but performs a deeper comparison
// of the the list of suffix and prefix.
// of the suffix and prefix slices.
//
// Important note: The PrefixSuffixTransformer is stacking the
// prefix values in the reverse order of appearance in
// the transformed name. For this reason the sameEndingSubarray
// method is used (as opposed to the sameBeginningSubarray)
// to compare the prefix slice. In the same spirit, the
// GetOutermostNamePrefix is using the last element of the
// nameprefix slice and not the first.
func (r *Resource) PrefixesSuffixesEquals(o ResCtx) bool {
return sameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) && sameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
// return sameBeginningSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) && sameBeginningSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
}

// This is used to compute if a referrer could potentially be impacted
Expand Down

0 comments on commit 31262cc

Please sign in to comment.