* Adds ownerReferences to the exported events
This commit uses the same approach as labels and annotations and adds ownerReferences to the EnhancedEvent struct.
The flow is as follows:
* use an LRU cache to store the ownerReferences with object UID as the key
* if the object doesn't exist in cache, look up using dynamic client and store it in cache
* if the object exists in cache, return the value from cache
* Reduce the number of GetObject calls by using a single cache to store all labels, annotations and ownerReferences
Currently, every time there's an event, the events exporter runs GetObject for metadata like labels and annotations
independently. This results in the same object being looked up multiple times for different pieces of the metadata.
These number of calls grow as we want to look up additional information about the object like ownerReferences.
So, in this change, a struct called `ObjectMetadata` is created to capture all the pieces of information that need to be added
to the EnhancedEvent. And every time there's an event, the object is fetched from the kube-apiserver if it's not in the cache already
and all pieces of metadata require only 1 call. The metadata is cached so repeated events about the same object don't
result in more calls.
Additionally, UID + ResourceVersion is used the cacheKey so if the object changes, it's looked up again.
One more change here is introduction of a `deleted` field in the `EnhancedEvent.InvolvedObject` to capture whether the object
is deleted. This helps receivers identify whether a resource is deleted and create rules for it when needed.
Tests are added for these updates and the mock functions are moved to the test files.
* Make the cache size configurable
* Add metrics for number of reads served from cache and kube-apiserver respectively
* Add `deleted` field to the involvedObject in EnhancedEvent to identify whether the resource is being deleted
* add warn for when event is discarded
* add events discarded metrics
* drop event onUpdate subscription
* rename ThrottlePeriod -> MaxEventAgeSeconds
* update readme to match new name of config var
* add explicit go arch
* gofmt
* add config tests
* revert accidental change to dockerfile
* add tests for event MaxEventAgeSeconds
* add tests for event discarded to onEvent function
* Use custom role with wider read permissions (#2)
* use longer time intervals for more stable tests on slower ci
* fix failing config test
* Updated packages, tidied and changed package name from opsgenie to resmoio
* Handle removal of clusterName from API and leader election api change
* Update Dockerfile Go to 1.19
* Test case for parsing minCount properly for #43
* more extensive test case to also match apiVersion config
Use the configured label value as the regex pattern. Currently it is trying to match the value from the config using the object's label as the pattern, which is incorrect. See also the Annotations matching below which is doing it correctly.
leader election function is disabled by default, and could be enabled by adding the
following section in `config.yaml`:
```yaml
leaderElection:
enabled: true
leaderElectionID: kubernetes-event-exporter // this field can be omited, default value is kubernetes-event-exporter
```
Before the change, the engine didn't call the `Close()` method of the
sinks. This is needed in some cases, i.e when a sink implementation is
buffered.
This change adds a `Close()` method to the registry that
will signal sinks to exit and wait for all sinks to exit before
returning. This is then used in the engine stop logic.
In the channel-based registry, the closing of all sinks is done in
parallel (using a `sync.WaitGroup`). In the sync registry, sinks are
closed sequentially.
Fixes issue #10