Skip to content

Commit

Permalink
Fix namespace checker filter
Browse files Browse the repository at this point in the history
Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
  • Loading branch information
PrasadG193 committed Jan 19, 2021
1 parent 14c8c9d commit 4fc81fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func New(object interface{}, eventType config.EventType, resource, clusterName s
Level: LevelMap[eventType],
Type: eventType,
Cluster: clusterName,
Resource: resource,
}

// initialize event.TimeStamp with the time of event creation
Expand Down Expand Up @@ -122,7 +123,6 @@ func New(object interface{}, eventType config.EventType, resource, clusterName s
event.Count = eventObj.Count
event.Action = eventObj.Action
event.TimeStamp = eventObj.LastTimestamp.Time
event.Resource = resource
}
return event
}
22 changes: 13 additions & 9 deletions pkg/filterengine/filters/namespace_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package filters

import (
"fmt"
"regexp"
"strings"

Expand Down Expand Up @@ -51,16 +50,21 @@ func (f NamespaceChecker) Run(object interface{}, event *events.Event) {
// load config.yaml
botkubeConfig, err := config.New()
if err != nil {
log.Errorf(fmt.Sprintf("Error in loading configuration. Error:%s", err.Error()))
log.Errorf("Error in loading configuration. Error:%s", err.Error())
log.Debug("Skipping ignore namespace filter.")
return
}
if botkubeConfig != nil {
for _, resource := range botkubeConfig.Resources {
if resource.Name == event.Resource {
// check if namespace to be ignored
if isNamespaceIgnored(resource.Namespaces, event.Namespace) {
event.Skip = true
}
if botkubeConfig == nil {
log.Errorf("Error in loading configuration.")
log.Debug("Skipping ignore namespace filter.")
return
}
for _, resource := range botkubeConfig.Resources {
if event.Resource == event.Resource {
// check if namespace to be ignored
if isNamespaceIgnored(resource.Namespaces, event.Namespace) {
event.Skip = true
break
}
}
}
Expand Down

0 comments on commit 4fc81fa

Please sign in to comment.