@@ -14,8 +14,26 @@ import (
1414 "github.com/projectcapsule/capsule/pkg/api/meta"
1515)
1616
17- type LabeledEvent struct {
18- recorder * EventRecorder
17+ type LabeledEvent interface {
18+ Emit (ctx context.Context )
19+ WithRelated (obj runtime.Object ) LabeledEvent
20+ WithLabels (labels map [string ]string ) LabeledEvent
21+ WithAnnotations (annotations map [string ]string ) LabeledEvent
22+ WithTenantLabel (tnt * capsulev1beta2.Tenant ) LabeledEvent
23+ WithRequestAnnotations (req admission.Request ) LabeledEvent
24+
25+ Reason () string
26+ Action () string
27+ Regarding () runtime.Object
28+ Labels () map [string ]string
29+ Annotations () map [string ]string
30+ Note () string
31+ EventType () string
32+ Related () runtime.Object
33+ }
34+
35+ type labeledEvent struct {
36+ emitter eventEmitter
1937
2038 regarding runtime.Object
2139 related runtime.Object
@@ -29,15 +47,47 @@ type LabeledEvent struct {
2947 annotations map [string ]string
3048}
3149
32- func (r * EventRecorder ) LabeledEvent (
50+ func (e * labeledEvent ) Reason () string {
51+ return e .reason
52+ }
53+
54+ func (e * labeledEvent ) Action () string {
55+ return e .action
56+ }
57+
58+ func (e * labeledEvent ) Regarding () runtime.Object {
59+ return e .regarding
60+ }
61+
62+ func (e * labeledEvent ) Labels () map [string ]string {
63+ return maps .Clone (e .labels )
64+ }
65+
66+ func (e * labeledEvent ) Annotations () map [string ]string {
67+ return maps .Clone (e .annotations )
68+ }
69+
70+ func (e * labeledEvent ) Note () string {
71+ return e .note
72+ }
73+
74+ func (e * labeledEvent ) EventType () string {
75+ return e .eventType
76+ }
77+
78+ func (e * labeledEvent ) Related () runtime.Object {
79+ return e .related
80+ }
81+
82+ func (r * eventRecorder ) LabeledEvent (
3383 regarding runtime.Object ,
3484 eventType string ,
3585 reason string ,
3686 action string ,
3787 note string ,
38- ) * LabeledEvent {
39- return & LabeledEvent {
40- recorder : r ,
88+ ) LabeledEvent {
89+ return & labeledEvent {
90+ emitter : r ,
4191 regarding : regarding ,
4292 eventType : eventType ,
4393 reason : reason ,
@@ -48,33 +98,33 @@ func (r *EventRecorder) LabeledEvent(
4898 }
4999}
50100
51- func (e * LabeledEvent ) Emit (ctx context.Context ) {
52- if e == nil || e .recorder == nil {
101+ func (e * labeledEvent ) Emit (ctx context.Context ) {
102+ if e == nil || e .emitter == nil {
53103 return
54104 }
55105
56- e .recorder . emitLabeledEvent (ctx , e )
106+ e .emitter . Emit (ctx , e )
57107}
58108
59- func (e * LabeledEvent ) WithRelated (obj runtime.Object ) * LabeledEvent {
109+ func (e * labeledEvent ) WithRelated (obj runtime.Object ) LabeledEvent {
60110 e .related = obj
61111
62112 return e
63113}
64114
65- func (e * LabeledEvent ) WithLabels (labels map [string ]string ) * LabeledEvent {
115+ func (e * labeledEvent ) WithLabels (labels map [string ]string ) LabeledEvent {
66116 maps .Copy (e .labels , labels )
67117
68118 return e
69119}
70120
71- func (e * LabeledEvent ) WithAnnotations (annotations map [string ]string ) * LabeledEvent {
121+ func (e * labeledEvent ) WithAnnotations (annotations map [string ]string ) LabeledEvent {
72122 maps .Copy (e .annotations , annotations )
73123
74124 return e
75125}
76126
77- func (e * LabeledEvent ) WithTenantLabel (tnt * capsulev1beta2.Tenant ) * LabeledEvent {
127+ func (e * labeledEvent ) WithTenantLabel (tnt * capsulev1beta2.Tenant ) LabeledEvent {
78128 if tnt == nil {
79129 return e
80130 }
@@ -84,7 +134,7 @@ func (e *LabeledEvent) WithTenantLabel(tnt *capsulev1beta2.Tenant) *LabeledEvent
84134 return e
85135}
86136
87- func (e * LabeledEvent ) WithRequestAnnotations (req admission.Request ) * LabeledEvent {
137+ func (e * labeledEvent ) WithRequestAnnotations (req admission.Request ) LabeledEvent {
88138 if req .UID != "" {
89139 e .annotations [meta .AuditRequestUID ] = string (req .UID )
90140 }
0 commit comments