# README
k8s-event-watcher
This library lets you watch for Kubernetes events, and triggers a callback whenever one matching the criteria is found.
An example of configuration is:
sinceNow: true
filters:
- rules:
involvedObject.kind: Job
involvedObject.name: "^*.fail"
reason: BackoffLimitExceeded
errorRules:
# Always mark this event as an error
type: .*
This would match a Job
-failed Event
:
apiVersion: v1
kind: Event
...
involvedObject:
apiVersion: batch/v1
kind: Job
name: job-fail
...
lastTimestamp: "2019-10-14T07:11:45Z"
message: Job has reached the specified backoff limit
metadata:
...
reason: BackoffLimitExceeded
...
type: Warning
Configuration
Configurable keys:
sinceNow
: iftrue
, only processes events generated after the program starts.filters
: a list ofrules
. Eachrules
object is evaluated independently, in anOR
fashion. Any event is evaluated on all sets ofrules
. The first matching filter will cause the trigger of the callback.filters.[*].rules
: a map of regular expressions. Each regular expression is evaluated against the provided object key. If all the regular expressions match, then the event will be sent to the callback, and theMatchedFields
map will be populated with the matching fields.filters.[*].errorRules
: a map of regular expressions. Each regular expression is evaluated against the provided object key. If all the regular expressions match, then the event will be considered an error, and theMatchedErrorFields
map will be populated with the matching error fields.
Local test
You can test the execution of this library by running the example program:
go run ./example --kubeconfig PATH_TO_A_KUBECONFIG_FILE --config ./example/config.yaml
While the example program is running, you can then start a failing job with:
kubectl apply -f ./example/job-fail-k8s.yaml
The example program will then pick up the failure and show the matching event.
# Functions
No description provided by the author
No description provided by the author
# Structs
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author