-
Notifications
You must be signed in to change notification settings - Fork 5
/
informer.go
52 lines (44 loc) · 1.66 KB
/
informer.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
package configmap
import (
"time"
"k8s.io/client-go/informers"
informerscore "k8s.io/client-go/informers/core/v1"
listerscore "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
)
// SetInformerResyncPeriod will set informer resync period.
func (h *Handler) SetInformerResyncPeriod(resyncPeriod time.Duration) {
h.informerFactory = informers.NewSharedInformerFactory(h.clientset, resyncPeriod)
}
// InformerFactory returns underlying SharedInformerFactory which provides
// shared informer for resources in all known API group version.
func (h *Handler) InformerFactory() informers.SharedInformerFactory {
return h.informerFactory
}
// ConfigMapInformer returns underlying ConfigMapInformer which provides
// access to a shared informer and lister for configmap.
func (h *Handler) ConfigMapInformer() informerscore.ConfigMapInformer {
return h.informerFactory.Core().V1().ConfigMaps()
}
// Informer returns underlying SharedIndexInformer which provides add and Indexers
// ability based on SharedInformer.
func (h *Handler) Informer() cache.SharedIndexInformer {
return h.informerFactory.Core().V1().ConfigMaps().Informer()
}
// Lister returns underlying ConfigMapLister which helps list configmaps.
func (h *Handler) Lister() listerscore.ConfigMapLister {
return h.informerFactory.Core().V1().ConfigMaps().Lister()
}
// RunInformer
func (h *Handler) RunInformer(
addFunc func(obj interface{}),
updateFunc func(oldObj, newObj interface{}),
deleteFunc func(obj interface{}),
stopCh chan struct{}) {
h.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: addFunc,
UpdateFunc: updateFunc,
DeleteFunc: deleteFunc,
})
h.Informer().Run(stopCh)
}