-
Notifications
You must be signed in to change notification settings - Fork 128
/
event.go
71 lines (61 loc) · 1.39 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package fake
import (
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
)
type Event struct {
Annotations map[string]string
EventType string
Reason string
Message string
Object runtime.Object
}
func NewEvent(
annotations map[string]string,
eventType,
reason,
message string,
object runtime.Object,
) Event {
return Event{
Annotations: annotations,
EventType: eventType,
Reason: reason,
Message: message,
Object: object,
}
}
var (
_ record.EventRecorder = &EventRecorder{}
)
type EventRecorder struct {
Events chan Event
}
func NewEventRecorder(bufferSize int) *EventRecorder {
return &EventRecorder{
Events: make(chan Event, bufferSize),
}
}
func (r *EventRecorder) Event(object runtime.Object, eventtype, reason, message string) {
if r.Events != nil {
r.Events <- NewEvent(nil, eventtype, reason, message, object)
}
}
func (r *EventRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...any) {
if r.Events != nil {
r.Events <- NewEvent(nil, eventtype, reason, fmt.Sprintf(messageFmt, args...), object)
}
}
func (r *EventRecorder) AnnotatedEventf(
object runtime.Object,
annotations map[string]string,
eventtype,
reason,
messageFmt string,
args ...any,
) {
if r.Events != nil {
r.Events <- NewEvent(annotations, eventtype, reason, fmt.Sprintf(messageFmt, args...), object)
}
}