forked from openshift/origin
/
policy.go
57 lines (49 loc) · 2.25 KB
/
policy.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
// This file was automatically generated by informer-gen
package internalversion
import (
authorization "github.com/openshift/origin/pkg/authorization/apis/authorization"
internalinterfaces "github.com/openshift/origin/pkg/authorization/generated/informers/internalversion/internalinterfaces"
internalclientset "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
internalversion "github.com/openshift/origin/pkg/authorization/generated/listers/authorization/internalversion"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
watch "k8s.io/apimachinery/pkg/watch"
cache "k8s.io/client-go/tools/cache"
time "time"
)
// PolicyInformer provides access to a shared informer and lister for
// Policies.
type PolicyInformer interface {
Informer() cache.SharedIndexInformer
Lister() internalversion.PolicyLister
}
type policyInformer struct {
factory internalinterfaces.SharedInformerFactory
}
// NewPolicyInformer constructs a new informer for Policy type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewPolicyInformer(client internalclientset.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
return client.Authorization().Policies(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
return client.Authorization().Policies(namespace).Watch(options)
},
},
&authorization.Policy{},
resyncPeriod,
indexers,
)
}
func defaultPolicyInformer(client internalclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewPolicyInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
}
func (f *policyInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&authorization.Policy{}, defaultPolicyInformer)
}
func (f *policyInformer) Lister() internalversion.PolicyLister {
return internalversion.NewPolicyLister(f.Informer().GetIndexer())
}