@@ -20,33 +20,13 @@ type KubernetesBindingToMonitorLink struct {
2020 BindingConfig htypes.OnKubernetesEventConfig
2121}
2222
23- // KubernetesBindingsController handles kubernetes bindings for one hook.
24- type KubernetesBindingsController interface {
25- WithKubernetesBindings ([]htypes.OnKubernetesEventConfig )
26- WithKubeEventsManager (kubeeventsmanager.KubeEventsManager )
27- EnableKubernetesBindings () ([]BindingExecutionInfo , error )
28- UpdateMonitor (monitorId string , kind , apiVersion string ) error
29- UnlockEvents ()
30- UnlockEventsFor (monitorID string )
31- StopMonitors ()
32- CanHandleEvent (kubeEvent kemtypes.KubeEvent ) bool
33- HandleEvent (kubeEvent kemtypes.KubeEvent ) BindingExecutionInfo
34- BindingNames () []string
35-
36- SnapshotsFrom (bindingNames ... string ) map [string ][]kemtypes.ObjectAndFilterResult
37- SnapshotsFor (bindingName string ) []kemtypes.ObjectAndFilterResult
38- Snapshots () map [string ][]kemtypes.ObjectAndFilterResult
39- SnapshotsInfo () []string
40- SnapshotsDump () map [string ]interface {}
41- }
42-
43- // kubernetesHooksController is a main implementation of KubernetesHooksController
44- type kubernetesBindingsController struct {
23+ // KubernetesHooksController is a main implementation of KubernetesHooksController
24+ type KubernetesBindingsController struct {
4525 // bindings configurations
4626 KubernetesBindings []htypes.OnKubernetesEventConfig
4727
4828 // dependencies
49- kubeEventsManager kubeeventsmanager.KubeEventsManager
29+ kubeEventsManager * kubeeventsmanager.KubeEventsManager
5030
5131 logger * log.Logger
5232
@@ -55,29 +35,26 @@ type kubernetesBindingsController struct {
5535 BindingMonitorLinks map [string ]* KubernetesBindingToMonitorLink
5636}
5737
58- // kubernetesHooksController should implement the KubernetesHooksController
59- var _ KubernetesBindingsController = & kubernetesBindingsController {}
60-
6138// NewKubernetesBindingsController returns an implementation of KubernetesBindingsController
62- var NewKubernetesBindingsController = func (logger * log.Logger ) * kubernetesBindingsController {
63- return & kubernetesBindingsController {
39+ var NewKubernetesBindingsController = func (logger * log.Logger ) * KubernetesBindingsController {
40+ return & KubernetesBindingsController {
6441 BindingMonitorLinks : make (map [string ]* KubernetesBindingToMonitorLink ),
6542 logger : logger ,
6643 }
6744}
6845
69- func (c * kubernetesBindingsController ) WithKubernetesBindings (bindings []htypes.OnKubernetesEventConfig ) {
46+ func (c * KubernetesBindingsController ) WithKubernetesBindings (bindings []htypes.OnKubernetesEventConfig ) {
7047 c .KubernetesBindings = bindings
7148}
7249
73- func (c * kubernetesBindingsController ) WithKubeEventsManager (kubeEventsManager kubeeventsmanager.KubeEventsManager ) {
50+ func (c * KubernetesBindingsController ) WithKubeEventsManager (kubeEventsManager * kubeeventsmanager.KubeEventsManager ) {
7451 c .kubeEventsManager = kubeEventsManager
7552}
7653
7754// EnableKubernetesBindings adds a monitor for each 'kubernetes' binding. This method
7855// returns an array of BindingExecutionInfo to help construct initial tasks to run hooks.
7956// Informers in each monitor are started immediately to keep up the "fresh" state of object caches.
80- func (c * kubernetesBindingsController ) EnableKubernetesBindings () ([]BindingExecutionInfo , error ) {
57+ func (c * KubernetesBindingsController ) EnableKubernetesBindings () ([]BindingExecutionInfo , error ) {
8158 res := make ([]BindingExecutionInfo , 0 )
8259
8360 for _ , config := range c .KubernetesBindings {
@@ -102,7 +79,7 @@ func (c *kubernetesBindingsController) EnableKubernetesBindings() ([]BindingExec
10279 return res , nil
10380}
10481
105- func (c * kubernetesBindingsController ) UpdateMonitor (monitorId string , kind , apiVersion string ) error {
82+ func (c * KubernetesBindingsController ) UpdateMonitor (monitorId string , kind , apiVersion string ) error {
10683 // Find binding for monitorId
10784 link , ok := c .getBindingMonitorLinksById (monitorId )
10885 if ! ok {
@@ -153,7 +130,7 @@ func (c *kubernetesBindingsController) UpdateMonitor(monitorId string, kind, api
153130}
154131
155132// UnlockEvents turns on eventCb for all monitors to emit events after Synchronization.
156- func (c * kubernetesBindingsController ) UnlockEvents () {
133+ func (c * KubernetesBindingsController ) UnlockEvents () {
157134 c .iterateBindingMonitorLinks (func (monitorID string ) bool {
158135 m := c .kubeEventsManager .GetMonitor (monitorID )
159136 m .EnableKubeEventCb ()
@@ -162,7 +139,7 @@ func (c *kubernetesBindingsController) UnlockEvents() {
162139}
163140
164141// UnlockEventsFor turns on eventCb for matched monitor to emit events after Synchronization.
165- func (c * kubernetesBindingsController ) UnlockEventsFor (monitorID string ) {
142+ func (c * KubernetesBindingsController ) UnlockEventsFor (monitorID string ) {
166143 m := c .kubeEventsManager .GetMonitor (monitorID )
167144 if m == nil {
168145 log .Warn ("monitor was not found" , slog .String ("monitorID" , monitorID ))
@@ -173,14 +150,14 @@ func (c *kubernetesBindingsController) UnlockEventsFor(monitorID string) {
173150
174151// StopMonitors stops all monitors for the hook.
175152// TODO handle error!
176- func (c * kubernetesBindingsController ) StopMonitors () {
153+ func (c * KubernetesBindingsController ) StopMonitors () {
177154 c .iterateBindingMonitorLinks (func (monitorID string ) bool {
178155 _ = c .kubeEventsManager .StopMonitor (monitorID )
179156 return false
180157 })
181158}
182159
183- func (c * kubernetesBindingsController ) CanHandleEvent (kubeEvent kemtypes.KubeEvent ) bool {
160+ func (c * KubernetesBindingsController ) CanHandleEvent (kubeEvent kemtypes.KubeEvent ) bool {
184161 var canHandleEvent bool
185162
186163 c .iterateBindingMonitorLinks (func (monitorID string ) bool {
@@ -194,7 +171,7 @@ func (c *kubernetesBindingsController) CanHandleEvent(kubeEvent kemtypes.KubeEve
194171 return canHandleEvent
195172}
196173
197- func (c * kubernetesBindingsController ) iterateBindingMonitorLinks (doFn func (monitorID string ) bool ) {
174+ func (c * KubernetesBindingsController ) iterateBindingMonitorLinks (doFn func (monitorID string ) bool ) {
198175 c .l .RLock ()
199176 for monitorID := range c .BindingMonitorLinks {
200177 if exit := doFn (monitorID ); exit {
@@ -204,22 +181,22 @@ func (c *kubernetesBindingsController) iterateBindingMonitorLinks(doFn func(moni
204181 c .l .RUnlock ()
205182}
206183
207- func (c * kubernetesBindingsController ) getBindingMonitorLinksById (monitorId string ) (* KubernetesBindingToMonitorLink , bool ) {
184+ func (c * KubernetesBindingsController ) getBindingMonitorLinksById (monitorId string ) (* KubernetesBindingToMonitorLink , bool ) {
208185 c .l .RLock ()
209186 link , found := c .BindingMonitorLinks [monitorId ]
210187 c .l .RUnlock ()
211188 return link , found
212189}
213190
214- func (c * kubernetesBindingsController ) setBindingMonitorLinks (monitorId string , link * KubernetesBindingToMonitorLink ) {
191+ func (c * KubernetesBindingsController ) setBindingMonitorLinks (monitorId string , link * KubernetesBindingToMonitorLink ) {
215192 c .l .Lock ()
216193 c .BindingMonitorLinks [monitorId ] = link
217194 c .l .Unlock ()
218195}
219196
220197// HandleEvent receives event from KubeEventManager and returns a BindingExecutionInfo
221198// to help create a new task to run a hook.
222- func (c * kubernetesBindingsController ) HandleEvent (kubeEvent kemtypes.KubeEvent ) BindingExecutionInfo {
199+ func (c * KubernetesBindingsController ) HandleEvent (kubeEvent kemtypes.KubeEvent ) BindingExecutionInfo {
223200 link , hasKey := c .getBindingMonitorLinksById (kubeEvent .MonitorId )
224201 if ! hasKey {
225202 log .Error ("Possible bug!!! Unknown kube event: no such monitor id registered" , slog .String ("monitorID" , kubeEvent .MonitorId ))
@@ -243,7 +220,7 @@ func (c *kubernetesBindingsController) HandleEvent(kubeEvent kemtypes.KubeEvent)
243220 return bInfo
244221}
245222
246- func (c * kubernetesBindingsController ) BindingNames () []string {
223+ func (c * KubernetesBindingsController ) BindingNames () []string {
247224 names := []string {}
248225 for _ , binding := range c .KubernetesBindings {
249226 names = append (names , binding .BindingName )
@@ -253,7 +230,7 @@ func (c *kubernetesBindingsController) BindingNames() []string {
253230
254231// SnapshotsFor returns snapshot for single onKubernetes binding.
255232// It finds a monitorId for a binding name and returns an array of objects.
256- func (c * kubernetesBindingsController ) SnapshotsFor (bindingName string ) []kemtypes.ObjectAndFilterResult {
233+ func (c * KubernetesBindingsController ) SnapshotsFor (bindingName string ) []kemtypes.ObjectAndFilterResult {
257234 for _ , binding := range c .KubernetesBindings {
258235 if bindingName == binding .BindingName {
259236 monitorID := binding .Monitor .Metadata .MonitorId
@@ -269,7 +246,7 @@ func (c *kubernetesBindingsController) SnapshotsFor(bindingName string) []kemtyp
269246// SnapshotsFrom returns snapshot for several binding names.
270247// It finds a monitorId for each binding name and get its Snapshot,
271248// then returns a map of object arrays for each binding name.
272- func (c * kubernetesBindingsController ) SnapshotsFrom (bindingNames ... string ) map [string ][]kemtypes.ObjectAndFilterResult {
249+ func (c * KubernetesBindingsController ) SnapshotsFrom (bindingNames ... string ) map [string ][]kemtypes.ObjectAndFilterResult {
273250 res := map [string ][]kemtypes.ObjectAndFilterResult {}
274251
275252 for _ , bindingName := range bindingNames {
@@ -285,11 +262,11 @@ func (c *kubernetesBindingsController) SnapshotsFrom(bindingNames ...string) map
285262 return res
286263}
287264
288- func (c * kubernetesBindingsController ) Snapshots () map [string ][]kemtypes.ObjectAndFilterResult {
265+ func (c * KubernetesBindingsController ) Snapshots () map [string ][]kemtypes.ObjectAndFilterResult {
289266 return c .SnapshotsFrom (c .BindingNames ()... )
290267}
291268
292- func (c * kubernetesBindingsController ) SnapshotsInfo () []string {
269+ func (c * KubernetesBindingsController ) SnapshotsInfo () []string {
293270 infos := make ([]string , 0 )
294271 for _ , binding := range c .KubernetesBindings {
295272 monitorID := binding .Monitor .Metadata .MonitorId
@@ -314,7 +291,7 @@ func (c *kubernetesBindingsController) SnapshotsInfo() []string {
314291 return infos
315292}
316293
317- func (c * kubernetesBindingsController ) SnapshotsDump () map [string ]interface {} {
294+ func (c * KubernetesBindingsController ) SnapshotsDump () map [string ]interface {} {
318295 dumps := make (map [string ]interface {})
319296 for _ , binding := range c .KubernetesBindings {
320297 monitorID := binding .Monitor .Metadata .MonitorId
0 commit comments