Commit Graph

10 Commits

Author SHA1 Message Date
Patrick Ohly
cf07629bfe k8s.io/client-go/tools/events: pass context into EventSink methods
Because the EventBroadcaster code now has a a context, changing the EventSink
interface so that the methods accepts a context instead of using context.TODO
becomes possible.

Kubernetes-commit: 5dc540ff57eed5d0e6bc8476f95fe03b7a983cf5
2023-09-18 12:17:14 +02:00
Patrick Ohly
3595e5242a k8s.io/client-go/tools: support context for event recording
Using StartRecordingToSinkWithContext instead of StartRecordingToSink and
StartLogging instead of StartStructuredLogging has several advantages:

- Spawned goroutines no longer get stuck for extended periods of
  time during shutdown when passing in a context that gets canceled.
- Log output can be directed towards a specific logger instead of the global
  default, for example one which writes to a testing.T instance.
- The new methods return an error when something went wrong instead of
  merely recording the error.

That last point is the reason for deprecating the old methods instead of merely
adding new alternatives.

Setting a context when constructing an EventBroadcaster makes calling Shutdown
optional. It can also be used to specify the logger.

Both EventRecorder interfaces in tools/events and tools/record now have a
WithLogger helper. Using that method is optional, but recommended to support
contextual logging properly. Without it, errors that occur while emitting an
event are not associated with the caller.

Kubernetes-commit: 27a68aee3a48340f7c14235f7fc24aa69aaeb8f6
2023-09-18 09:13:22 +02:00
jlsong01
34679611a8 rewrite signature of function StartEventWatcher
Kubernetes-commit: c8291e393b32f8ce4e8fd1d4f18e848247be13f8
2022-07-29 23:43:05 +08:00
shawnhanx
93595145a2 Support SetStructuredLogging with the new events library
Kubernetes-commit: 230cb00ddd989ae2359696f6aa09a71253936a49
2021-10-11 16:16:46 +08:00
Chelsey Chen
67fdd63515 Switch event recorder to use events.k8s.io/v1
Kubernetes-commit: ade242288346d968ab97f42ffb30e0855e235afc
2020-06-16 18:25:18 -04:00
Chelsey Chen
a8a31f0d9b Move fallback of Event API into new event lib
Kubernetes-commit: e0e12f25c9ccd33f5578fddef79d93eb7b62ea0c
2020-06-04 21:36:04 -04:00
Ted Yu
c4ea3eed4f Expose Shutdown func for EventBroadcaster
Kubernetes-commit: 57d43e4946f352f075b219b0a2f35942b06cfeb9
2019-10-07 08:58:38 -07:00
Jianfei Bai
a537b01432 docs: add comments for action.
Kubernetes-commit: 993fe6f4bda183e1583cf0f879fbf9a076e99e8a
2019-09-20 21:32:44 +08:00
Yassine TIJANI
36ad1c08c8 add fakes for events package, add startEventWatcher to event interface
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>

Kubernetes-commit: bfa7de0165c911178daaac1991c08f7424b0048f
2019-07-05 14:18:02 +02:00
Yassine TIJANI
231e48e9f3 Implementing logic for v1beta1.Event API
Signed-off-by: Yassine TIJANI <ytijani@vmware.com>

Kubernetes-commit: 464a994a10b71c45583f3426fd970291f8a5b756
2018-07-03 22:25:17 +02:00