/
quota_informers.go
70 lines (58 loc) · 1.94 KB
/
quota_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
62
63
64
65
66
67
68
69
70
package shared
import (
"reflect"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/watch"
ocache "github.com/openshift/origin/pkg/client/cache"
quotaapi "github.com/openshift/origin/pkg/quota/api"
)
type ClusterResourceQuotaInformer interface {
Informer() framework.SharedIndexInformer
// still use an indexer, no telling what someone will want to index on someday
Indexer() cache.Indexer
Lister() *ocache.IndexerToClusterResourceQuotaLister
}
// clusterResourceQuotaInformer is a core informer because quota needs to be working before the "ensure"
// steps in the API server can complete
type clusterResourceQuotaInformer struct {
*sharedInformerFactory
}
func (f *clusterResourceQuotaInformer) Informer() framework.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informerObj := "aapi.ClusterResourceQuota{}
informerType := reflect.TypeOf(informerObj)
informer, exists := f.coreInformers[informerType]
if exists {
return informer
}
lw := f.customListerWatchers.GetListerWatcher(kapi.Resource("clusterresourcequotas"))
if lw == nil {
lw = &cache.ListWatch{
ListFunc: func(options kapi.ListOptions) (runtime.Object, error) {
return f.originClient.ClusterResourceQuotas().List(options)
},
WatchFunc: func(options kapi.ListOptions) (watch.Interface, error) {
return f.originClient.ClusterResourceQuotas().Watch(options)
},
}
}
informer = framework.NewSharedIndexInformer(
lw,
informerObj,
f.defaultResync,
cache.Indexers{},
)
f.coreInformers[informerType] = informer
return informer
}
func (f *clusterResourceQuotaInformer) Indexer() cache.Indexer {
informer := f.Informer()
return informer.GetIndexer()
}
func (f *clusterResourceQuotaInformer) Lister() *ocache.IndexerToClusterResourceQuotaLister {
return &ocache.IndexerToClusterResourceQuotaLister{Indexer: f.Indexer()}
}