Fix lifecycle rules not applied in some cases (#10072)

HasActiveRules was not behaving as expected, this commit fixes it
and adds more unit tests.
This commit is contained in:
Anis Elleuch
2020-07-17 17:48:00 +01:00
committed by GitHub
parent 4bfc50411c
commit 4a447a439a
2 changed files with 64 additions and 6 deletions

View File

@@ -62,14 +62,19 @@ func (lc Lifecycle) HasActiveRules(prefix string, recursive bool) bool {
if rule.Status == Disabled {
continue
}
if len(prefix) > 0 && len(rule.Filter.Prefix) > 0 {
// incoming prefix must be in rule prefix
if !recursive && !strings.HasPrefix(prefix, rule.Filter.Prefix) {
continue
if !recursive {
// If not recursive, incoming prefix must be in rule prefix
if !strings.HasPrefix(prefix, rule.Filter.Prefix) {
continue
}
}
// If recursive, we can skip this rule if it doesn't match the tested prefix.
if recursive && !strings.HasPrefix(rule.Filter.Prefix, prefix) {
continue
if recursive {
// If recursive, we can skip this rule if it doesn't match the tested prefix.
if !strings.HasPrefix(prefix, rule.Filter.Prefix) && !strings.HasPrefix(rule.Filter.Prefix, prefix) {
continue
}
}
}