Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reasons filter #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/collector/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (ec *EventCollector) syncEvent(key string) error {
}

func (ec *EventCollector) addFilter(o *options.Options) {
typeFilter := filters.NewEventTypeFilter(o.EventType)
typeFilter := filters.NewEventTypeFilter(o.EventType, o.EventReason)
ec.filters = append(ec.filters, typeFilter)
}

Expand Down
15 changes: 12 additions & 3 deletions pkg/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ type EventFilter interface {
}

type EventTypeFilter struct {
AllowedTypes []string
AllowedTypes []string
AllowedReasons []string
}

func NewEventTypeFilter(allowedTypes []string) *EventTypeFilter {
func NewEventTypeFilter(allowedTypes []string, allowedReasons []string) *EventTypeFilter {
return &EventTypeFilter{
AllowedTypes: allowedTypes,
AllowedTypes: allowedTypes,
AllowedReasons: allowedReasons,
}
}

Expand All @@ -42,5 +44,12 @@ func (e *EventTypeFilter) Filter(event *v1.Event) bool {
return true
}
}

for _, allowedReason := range e.AllowedReasons {
if strings.EqualFold(event.Reason, allowedReason) {
return true
}
}

return false
}
2 changes: 2 additions & 0 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Options struct {
KubeMasterURL string
KubeConfigPath string
EventType []string
EventReason []string
Port int
Version bool
flag *pflag.FlagSet
Expand All @@ -48,6 +49,7 @@ func (o *Options) AddFlags() {
o.flag.StringVar(&o.KubeMasterURL, "kubeMasterURL", "", "The URL of kubernetes apiserver to use as a master")
o.flag.StringVar(&o.KubeConfigPath, "kubeConfigPath", "", "The path of kubernetes configuration file")
o.flag.StringArrayVar(&o.EventType, "eventType", []string{"Warning"}, "List of allowed event types. Default to warning type.")
o.flag.StringArrayVar(&o.EventReason, "eventReason", []string{}, "List of allowed event reasons. Default to all reasons.")
o.flag.IntVar(&o.Port, "port", 9102, "Port to expose event metrics on")
o.flag.BoolVar(&o.Version, "version", false, "event exporter version information")

Expand Down