forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
template_informers.go
61 lines (51 loc) · 1.59 KB
/
template_informers.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
package shared
import (
"reflect"
oscache "github.com/openshift/origin/pkg/client/cache"
templateapi "github.com/openshift/origin/pkg/template/api"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/watch"
)
type TemplateInformer interface {
Informer() cache.SharedIndexInformer
Indexer() cache.Indexer
Lister() oscache.StoreToTemplateLister
}
type templateInformer struct {
*sharedInformerFactory
}
func (f *templateInformer) Informer() cache.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informerObj := &templateapi.Template{}
informerType := reflect.TypeOf(informerObj)
informer, exists := f.informers[informerType]
if exists {
return informer
}
informer = cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return f.originClient.Templates(kapi.NamespaceAll).List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return f.originClient.Templates(kapi.NamespaceAll).Watch(options)
},
},
informerObj,
f.defaultResync,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, oscache.TemplateUIDIndex: oscache.TemplateUIDIndexFunc},
)
f.informers[informerType] = informer
return informer
}
func (f *templateInformer) Indexer() cache.Indexer {
informer := f.Informer()
return informer.GetIndexer()
}
func (f *templateInformer) Lister() oscache.StoreToTemplateLister {
informer := f.Informer()
return &oscache.StoreToTemplateListerImpl{Indexer: informer.GetIndexer()}
}