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

feat: add skip-event-updates option #16

Merged
merged 2 commits into from
Apr 11, 2024
Merged
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
14 changes: 10 additions & 4 deletions eventrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ type EventRouter struct {
// event sink
// TODO: Determine if we want to support multiple sinks.
eSink sinks.EventSinkInterface

// skipEventUpdates will skip updating events in the sink
skipEventUpdates bool
}

// NewEventRouter will create a new event router using the input params
func NewEventRouter(kubeClient kubernetes.Interface, eventsInformer coreinformers.EventInformer) *EventRouter {
func NewEventRouter(kubeClient kubernetes.Interface, eventsInformer coreinformers.EventInformer, skipEventUpdates bool) *EventRouter {
if viper.GetBool("enable-prometheus") {
prometheus.MustRegister(kubernetesWarningEventCounterVec)
prometheus.MustRegister(kubernetesNormalEventCounterVec)
Expand All @@ -102,8 +105,9 @@ func NewEventRouter(kubeClient kubernetes.Interface, eventsInformer coreinformer
}

er := &EventRouter{
kubeClient: kubeClient,
eSink: sinks.ManufactureSink(),
kubeClient: kubeClient,
eSink: sinks.ManufactureSink(),
skipEventUpdates: skipEventUpdates,
}
_, err := eventsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: er.addEvent,
Expand Down Expand Up @@ -145,7 +149,9 @@ func (er *EventRouter) updateEvent(objOld interface{}, objNew interface{}) {
eOld := objOld.(*v1.Event)
eNew := objNew.(*v1.Event)
prometheusEvent(eNew)
er.eSink.UpdateEvents(eNew, eOld)
if !er.skipEventUpdates {
er.eSink.UpdateEvents(eNew, eOld)
}
}

// prometheusEvent is called when an event is added or updated
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
// addr tells us what address to have the Prometheus metrics listen on.
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")

// setup a signal hander to gracefully exit
// setup a signal handler to gracefully exit
func sigHandler() <-chan struct{} {
stop := make(chan struct{})
go func() {
Expand Down Expand Up @@ -74,6 +74,7 @@ func loadConfig() kubernetes.Interface {
viper.SetDefault("sink", "glog")
viper.SetDefault("resync-interval", time.Minute*30)
viper.SetDefault("enable-prometheus", true)
viper.SetDefault("skip-event-updates", false)
if err = viper.ReadInConfig(); err != nil {
panic(err.Error())
}
Expand Down Expand Up @@ -118,8 +119,9 @@ func main() {
sharedInformers := informers.NewSharedInformerFactory(clientset, viper.GetDuration("resync-interval"))
eventsInformer := sharedInformers.Core().V1().Events()

skipEventUpdates := viper.GetBool("skip-event-updates")
// TODO: Support locking for HA https://github.com/kubernetes/kubernetes/pull/42666
eventRouter := NewEventRouter(clientset, eventsInformer)
eventRouter := NewEventRouter(clientset, eventsInformer, skipEventUpdates)
stop := sigHandler()

// Startup the http listener for Prometheus Metrics endpoint.
Expand Down
3 changes: 2 additions & 1 deletion yaml/eventrouter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ apiVersion: v1
data:
config.json: |-
{
"sink": "stdout"
"sink": "stdout",
"skip-event-updates": "true"
}
---
apiVersion: apps/v1
Expand Down
Loading