Skip to content

Commit

Permalink
Merge pull request #48 from hortonworks/CB-12290
Browse files Browse the repository at this point in the history
CB-12290 Introduce flag for disabling ignore label usage
  • Loading branch information
Bajzathd authored Apr 27, 2021
2 parents 633b387 + bcd4b84 commit 2fdd98f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ DRY RUN:
-d
VERBOSE:
-v
DISABLE_IGNORE_LABEL:
-i
HELP:
-h
```
Expand Down
3 changes: 3 additions & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var DryRun = false
// Verbose is a global flag for verbose logging
var Verbose = false

// IgnoreLabelDisabled is a global flag for enabling/disabling ignore label usage
var IgnoreLabelDisabled = true

// Operations contains all the available operations
var Operations = make(map[types.OpType]types.Operation)

Expand Down
42 changes: 27 additions & 15 deletions filter/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ func isFilterMatch(filterName string, item types.CloudItem, filterType types.Fil
ignoreLabelFound := utils.IsAnyMatch(inst.Tags, ctx.IgnoreLabel)
if ignoreLabelFound {
log.Debugf("[%s] Found ignore label on item: %s, label: %s", filterName, name, ctx.IgnoreLabel)
if filterType.IsInclusive() {
log.Debugf("[%s] inclusive filter applied on item: %s", filterName, name)
return false
if ctx.IgnoreLabelDisabled {
log.Debugf("[%s] Ignore label usage is disabled, continuing to apply filter on item: %s", filterName, name)
} else {
if filterType.IsInclusive() {
log.Debugf("[%s] inclusive filter applied on item: %s", filterName, name)
return false
}
log.Debugf("[%s] exclusive filter applied on item: %s", filterName, name)
return true
}
log.Debugf("[%s] exclusive filter applied on item: %s", filterName, name)
return true
}
filtered, applied := applyFilterConfig(filterConfig, filterType, item, filterName, inst.Tags)
if applied {
Expand All @@ -53,12 +57,16 @@ func isFilterMatch(filterName string, item types.CloudItem, filterType types.Fil
ignoreLabelFound := utils.IsAnyMatch(stack.Tags, ctx.IgnoreLabel)
if ignoreLabelFound {
log.Debugf("[%s] Found ignore label on item: %s, label: %s", filterName, name, ctx.IgnoreLabel)
if filterType.IsInclusive() {
log.Debugf("[%s] inclusive filter applied on item: %s", filterName, name)
return false
if ctx.IgnoreLabelDisabled {
log.Debugf("[%s] Ignore label usage is disabled, continuing to apply filter on item: %s", filterName, name)
} else {
if filterType.IsInclusive() {
log.Debugf("[%s] inclusive filter applied on item: %s", filterName, name)
return false
}
log.Debugf("[%s] exclusive filter applied on item: %s", filterName, name)
return true
}
log.Debugf("[%s] exclusive filter applied on item: %s", filterName, name)
return true
}
filtered, applied := applyFilterConfig(filterConfig, filterType, item, filterName, stack.Tags)
if applied {
Expand All @@ -84,12 +92,16 @@ func isFilterMatch(filterName string, item types.CloudItem, filterType types.Fil
ignoreLabelFound := utils.IsAnyMatch(database.Tags, ctx.IgnoreLabel)
if ignoreLabelFound {
log.Debugf("[%s] Found ignore label on item: %s, label: %s", filterName, name, ctx.IgnoreLabel)
if filterType.IsInclusive() {
log.Debugf("[%s] inclusive filter applied on item: %s", filterName, name)
return false
if ctx.IgnoreLabelDisabled {
log.Debugf("[%s] Ignore label usage is disabled, continuing to apply filter on item: %s", filterName, name)
} else {
if filterType.IsInclusive() {
log.Debugf("[%s] inclusive filter applied on item: %s", filterName, name)
return false
}
log.Debugf("[%s] exclusive filter applied on item: %s", filterName, name)
return true
}
log.Debugf("[%s] exclusive filter applied on item: %s", filterName, name)
return true
}
filtered, applied := applyFilterConfig(filterConfig, filterType, item, filterName, database.Tags)
if applied {
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {
filterConfigLoc := flag.String("fc", "", "filterConfig YAML")
dryRun := flag.Bool("d", false, "dry run")
verbose := flag.Bool("v", false, "verbose")
ignoreLabelDisabled := flag.Bool("i", false, "disable ignore label")

flag.Parse()

Expand All @@ -48,6 +49,7 @@ func main() {
if ctx.Verbose {
log.SetLevel(log.DebugLevel)
}
ctx.IgnoreLabelDisabled = *ignoreLabelDisabled

if filterConfigLoc != nil && len(*filterConfigLoc) != 0 {
var err error
Expand Down Expand Up @@ -141,5 +143,6 @@ OPERATIONS:`)
println("FILTER_CONFIG:\n\t-fc=/location/of/filter/config.yml")
println("DRY RUN:\n\t-d")
println("VERBOSE:\n\t-v")
println("DISABLE_IGNORE_LABEL:\n\t-i")
println("HELP:\n\t-h")
}

0 comments on commit 2fdd98f

Please sign in to comment.