@@ -27,7 +27,7 @@ type Controller[T client.Object] struct {
27
27
startTime time.Time
28
28
kubeClient client.Client
29
29
EventCount pmetrics.CounterMetric
30
- eventWatch watch.Interface
30
+ EventWatch watch.Interface
31
31
}
32
32
33
33
func NewController [T client.Object ](ctx context.Context , client client.Client , clock clock.Clock , kubernetesInterface kubernetes.Interface ) * Controller [T ] {
@@ -37,7 +37,7 @@ func NewController[T client.Object](ctx context.Context, client client.Client, c
37
37
startTime : clock .Now (),
38
38
kubeClient : client ,
39
39
EventCount : eventTotalMetric (strings .ToLower (gvk .Kind )),
40
- eventWatch : lo .Must (kubernetesInterface .CoreV1 ().Events ("" ).Watch (ctx , metav1.ListOptions {
40
+ EventWatch : lo .Must (kubernetesInterface .CoreV1 ().Events ("" ).Watch (ctx , metav1.ListOptions {
41
41
FieldSelector : fmt .Sprintf ("involvedObject.kind=%s,involvedObject.apiVersion=%s" , gvk .Kind , gvk .GroupVersion ().String ()),
42
42
})),
43
43
}
@@ -47,21 +47,17 @@ func (c *Controller[T]) Register(ctx context.Context, m manager.Manager) error {
47
47
return controllerruntime .NewControllerManagedBy (m ).
48
48
Named (fmt .Sprintf ("operatorpkg.%s.events" , strings .ToLower (c .gvk .Kind ))).
49
49
WatchesRawSource (singleton .Source ()).
50
- Complete (singleton .AsReconciler ( c ))
50
+ Complete (singleton .AsChannelObjectReconciler ( c . EventWatch . ResultChan (), c ))
51
51
}
52
52
53
- func (c * Controller [T ]) Reconcile (ctx context.Context ) (reconcile.Result , error ) {
54
- for e := range c .eventWatch .ResultChan () {
55
- event := e .Object .(* v1.Event )
56
-
57
- // We check if the event was created in the lifetime of this controller
58
- // since we don't duplicate metrics on controller restart or lease handover
59
- if c .startTime .Before (event .LastTimestamp .Time ) {
60
- c .EventCount .Inc (map [string ]string {
61
- pmetrics .LabelType : event .Type ,
62
- pmetrics .LabelReason : event .Reason ,
63
- })
64
- }
53
+ func (c * Controller [T ]) Reconcile (ctx context.Context , event * v1.Event ) (reconcile.Result , error ) {
54
+ // We check if the event was created in the lifetime of this controller
55
+ // since we don't duplicate metrics on controller restart or lease handover
56
+ if c .startTime .Before (event .LastTimestamp .Time ) {
57
+ c .EventCount .Inc (map [string ]string {
58
+ pmetrics .LabelType : event .Type ,
59
+ pmetrics .LabelReason : event .Reason ,
60
+ })
65
61
}
66
62
67
63
return reconcile.Result {}, nil
0 commit comments