/
informers.go
131 lines (121 loc) · 5.9 KB
/
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package openshiftapiserver
import (
"time"
authorizationv1client "github.com/openshift/client-go/authorization/clientset/versioned"
authorizationv1informer "github.com/openshift/client-go/authorization/informers/externalversions"
imagev1client "github.com/openshift/client-go/image/clientset/versioned"
imagev1informer "github.com/openshift/client-go/image/informers/externalversions"
oauthv1client "github.com/openshift/client-go/oauth/clientset/versioned"
oauthv1informer "github.com/openshift/client-go/oauth/informers/externalversions"
quotaclient "github.com/openshift/client-go/quota/clientset/versioned"
quotainformer "github.com/openshift/client-go/quota/informers/externalversions"
routev1client "github.com/openshift/client-go/route/clientset/versioned"
routev1informer "github.com/openshift/client-go/route/informers/externalversions"
securityv1client "github.com/openshift/client-go/security/clientset/versioned"
securityv1informer "github.com/openshift/client-go/security/informers/externalversions"
userv1client "github.com/openshift/client-go/user/clientset/versioned"
userv1informer "github.com/openshift/client-go/user/informers/externalversions"
kexternalinformers "k8s.io/client-go/informers"
"k8s.io/client-go/rest"
)
// informerHolder is a convenient way for us to keep track of the informers, but
// is intentionally private. We don't want to leak it out further than this package.
// Everything else should say what it wants.
type InformerHolder struct {
kubernetesInformers kexternalinformers.SharedInformerFactory
// Internal OpenShift informers
authorizationInformers authorizationv1informer.SharedInformerFactory
imageInformers imagev1informer.SharedInformerFactory
oauthInformers oauthv1informer.SharedInformerFactory
quotaInformers quotainformer.SharedInformerFactory
routeInformers routev1informer.SharedInformerFactory
securityInformers securityv1informer.SharedInformerFactory
userInformers userv1informer.SharedInformerFactory
}
// NewInformers is only exposed for the build's integration testing until it can be fixed more appropriately.
func NewInformers(kubeInformers kexternalinformers.SharedInformerFactory, kubeClientConfig *rest.Config, loopbackClientConfig *rest.Config) (*InformerHolder, error) {
authorizationClient, err := authorizationv1client.NewForConfig(nonProtobufConfig(kubeClientConfig))
if err != nil {
return nil, err
}
imageClient, err := imagev1client.NewForConfig(loopbackClientConfig)
if err != nil {
return nil, err
}
oauthClient, err := oauthv1client.NewForConfig(loopbackClientConfig)
if err != nil {
return nil, err
}
quotaClient, err := quotaclient.NewForConfig(nonProtobufConfig(kubeClientConfig))
if err != nil {
return nil, err
}
routerClient, err := routev1client.NewForConfig(loopbackClientConfig)
if err != nil {
return nil, err
}
securityClient, err := securityv1client.NewForConfig(nonProtobufConfig(kubeClientConfig))
if err != nil {
return nil, err
}
userClient, err := userv1client.NewForConfig(loopbackClientConfig)
if err != nil {
return nil, err
}
// TODO find a single place to create and start informers. During the 1.7 rebase this will come more naturally in a config object,
// before then we should try to eliminate our direct to storage access. It's making us do weird things.
const defaultInformerResyncPeriod = 10 * time.Minute
return &InformerHolder{
kubernetesInformers: kubeInformers,
authorizationInformers: authorizationv1informer.NewSharedInformerFactory(authorizationClient, defaultInformerResyncPeriod),
imageInformers: imagev1informer.NewSharedInformerFactory(imageClient, defaultInformerResyncPeriod),
oauthInformers: oauthv1informer.NewSharedInformerFactory(oauthClient, defaultInformerResyncPeriod),
quotaInformers: quotainformer.NewSharedInformerFactory(quotaClient, defaultInformerResyncPeriod),
routeInformers: routev1informer.NewSharedInformerFactory(routerClient, defaultInformerResyncPeriod),
securityInformers: securityv1informer.NewSharedInformerFactory(securityClient, defaultInformerResyncPeriod),
userInformers: userv1informer.NewSharedInformerFactory(userClient, defaultInformerResyncPeriod),
}, nil
}
// nonProtobufConfig returns a copy of inConfig that doesn't force the use of protobufs,
// for working with CRD-based APIs.
func nonProtobufConfig(inConfig *rest.Config) *rest.Config {
npConfig := rest.CopyConfig(inConfig)
npConfig.ContentConfig.AcceptContentTypes = "application/json"
npConfig.ContentConfig.ContentType = "application/json"
return npConfig
}
func (i *InformerHolder) GetKubernetesInformers() kexternalinformers.SharedInformerFactory {
return i.kubernetesInformers
}
func (i *InformerHolder) GetOpenshiftAuthorizationInformers() authorizationv1informer.SharedInformerFactory {
return i.authorizationInformers
}
func (i *InformerHolder) GetOpenshiftImageInformers() imagev1informer.SharedInformerFactory {
return i.imageInformers
}
func (i *InformerHolder) GetOpenshiftOauthInformers() oauthv1informer.SharedInformerFactory {
return i.oauthInformers
}
func (i *InformerHolder) GetOpenshiftQuotaInformers() quotainformer.SharedInformerFactory {
return i.quotaInformers
}
func (i *InformerHolder) GetOpenshiftRouteInformers() routev1informer.SharedInformerFactory {
return i.routeInformers
}
func (i *InformerHolder) GetOpenshiftSecurityInformers() securityv1informer.SharedInformerFactory {
return i.securityInformers
}
func (i *InformerHolder) GetOpenshiftUserInformers() userv1informer.SharedInformerFactory {
return i.userInformers
}
// Start initializes all requested informers.
func (i *InformerHolder) Start(stopCh <-chan struct{}) {
i.kubernetesInformers.Start(stopCh)
i.authorizationInformers.Start(stopCh)
i.imageInformers.Start(stopCh)
i.oauthInformers.Start(stopCh)
i.quotaInformers.Start(stopCh)
i.routeInformers.Start(stopCh)
i.securityInformers.Start(stopCh)
i.userInformers.Start(stopCh)
}