mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Merge pull request #105603 from shawnhanx/eventstructuredlogging
Support SetStructuredLogging with the new events library
This commit is contained in:
commit
668c666fce
@ -290,6 +290,20 @@ func getKey(event *eventsv1.Event) eventKey {
|
|||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartStructuredLogging starts sending events received from this EventBroadcaster to the structured logging function.
|
||||||
|
// The return value can be ignored or used to stop recording, if desired.
|
||||||
|
func (e *eventBroadcasterImpl) StartStructuredLogging(verbosity klog.Level) func() {
|
||||||
|
return e.StartEventWatcher(
|
||||||
|
func(obj runtime.Object) {
|
||||||
|
event, ok := obj.(*eventsv1.Event)
|
||||||
|
if !ok {
|
||||||
|
klog.Errorf("unexpected type, expected eventsv1.Event")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
klog.V(verbosity).InfoS("Event occurred", "object", klog.KRef(event.Regarding.Namespace, event.Regarding.Name), "kind", event.Regarding.Kind, "apiVersion", event.Regarding.APIVersion, "type", event.Type, "reason", event.Reason, "action", event.Action, "note", event.Note)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// StartEventWatcher starts sending events received from this EventBroadcaster to the given event handler function.
|
// StartEventWatcher starts sending events received from this EventBroadcaster to the given event handler function.
|
||||||
// The return value is used to stop recording
|
// The return value is used to stop recording
|
||||||
func (e *eventBroadcasterImpl) StartEventWatcher(eventHandler func(event runtime.Object)) func() {
|
func (e *eventBroadcasterImpl) StartEventWatcher(eventHandler func(event runtime.Object)) func() {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
eventsv1 "k8s.io/api/events/v1"
|
eventsv1 "k8s.io/api/events/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EventRecorder knows how to record events on behalf of an EventSource.
|
// EventRecorder knows how to record events on behalf of an EventSource.
|
||||||
@ -56,6 +57,10 @@ type EventBroadcaster interface {
|
|||||||
// TODO: figure out if this can be removed.
|
// TODO: figure out if this can be removed.
|
||||||
StartEventWatcher(eventHandler func(event runtime.Object)) func()
|
StartEventWatcher(eventHandler func(event runtime.Object)) func()
|
||||||
|
|
||||||
|
// StartStructuredLogging starts sending events received from this EventBroadcaster to the structured
|
||||||
|
// logging function. The return value can be ignored or used to stop recording, if desired.
|
||||||
|
StartStructuredLogging(verbosity klog.Level) func()
|
||||||
|
|
||||||
// Shutdown shuts down the broadcaster
|
// Shutdown shuts down the broadcaster
|
||||||
Shutdown()
|
Shutdown()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user