Skip to content
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
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func main() {
}
}

w := kube.NewEventWatcher(kubecfg, cfg.Namespace, cfg.MaxEventAgeSeconds, metricsStore, onEvent, cfg.OmitLookup, cfg.CacheSize)
w := kube.NewEventWatcher(kubecfg, cfg.Namespace, cfg.MaxEventAgeSeconds, metricsStore, onEvent, cfg.OmitLookup, cfg.WatchUpdate, cfg.CacheSize)

ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()
Expand Down Expand Up @@ -151,3 +151,4 @@ func main() {
w.Stop()
engine.Stop()
}

2 changes: 2 additions & 0 deletions pkg/exporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Config struct {
KubeBurst int `yaml:"kubeBurst,omitempty"`
MetricsNamePrefix string `yaml:"metricsNamePrefix,omitempty"`
OmitLookup bool `yaml:"omitLookup,omitempty"`
WatchUpdate bool `yaml:"watchUpdate,omitempty"`
CacheSize int `yaml:"cacheSize,omitempty"`
}

Expand Down Expand Up @@ -112,3 +113,4 @@ func (c *Config) validateMetricsNamePrefix() error {
}
return nil
}

13 changes: 10 additions & 3 deletions pkg/kube/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ type EventWatcher struct {
stopper chan struct{}
objectMetadataCache ObjectMetadataProvider
omitLookup bool
watchUpdate bool
fn EventHandler
maxEventAgeSeconds time.Duration
metricsStore *metrics.Store
dynamicClient *dynamic.DynamicClient
clientset *kubernetes.Clientset
}

func NewEventWatcher(config *rest.Config, namespace string, MaxEventAgeSeconds int64, metricsStore *metrics.Store, fn EventHandler, omitLookup bool, cacheSize int) *EventWatcher {
func NewEventWatcher(config *rest.Config, namespace string, MaxEventAgeSeconds int64, metricsStore *metrics.Store, fn EventHandler, omitLookup, watchUpdate bool, cacheSize int) *EventWatcher {
clientset := kubernetes.NewForConfigOrDie(config)
factory := informers.NewSharedInformerFactoryWithOptions(clientset, 0, informers.WithNamespace(namespace))
informer := factory.Core().V1().Events().Informer()
Expand All @@ -42,6 +43,7 @@ func NewEventWatcher(config *rest.Config, namespace string, MaxEventAgeSeconds i
stopper: make(chan struct{}),
objectMetadataCache: NewObjectMetadataProvider(cacheSize),
omitLookup: omitLookup,
watchUpdate: watchUpdate,
fn: fn,
maxEventAgeSeconds: time.Second * time.Duration(MaxEventAgeSeconds),
metricsStore: metricsStore,
Expand All @@ -62,8 +64,12 @@ func (e *EventWatcher) OnAdd(obj interface{}) {
e.onEvent(event)
}

func (e *EventWatcher) OnUpdate(oldObj, newObj interface{}) {
// Ignore updates
func (e *EventWatcher) OnUpdate(_, newObj interface{}) {
// new event emit to watcher when e.enableUpdate is true
if e.watchUpdate {
event := newObj.(*corev1.Event)
e.onEvent(event)
}
}

// Ignore events older than the maxEventAgeSeconds
Expand Down Expand Up @@ -152,3 +158,4 @@ func (e *EventWatcher) Stop() {
func (e *EventWatcher) setStartUpTime(time time.Time) {
startUpTime = time
}