forked from openshift/origin
/
interfaces.go
289 lines (252 loc) · 11.8 KB
/
interfaces.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
package controller
import (
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
kexternalinformers "k8s.io/client-go/informers"
controllerapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
kclientsetinternal "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/controller"
routeinformer "github.com/openshift/client-go/route/informers/externalversions"
securityv1client "github.com/openshift/client-go/security/clientset/versioned"
appinformer "github.com/openshift/origin/pkg/apps/generated/informers/internalversion"
appsclientinternal "github.com/openshift/origin/pkg/apps/generated/internalclientset"
authorizationinformer "github.com/openshift/origin/pkg/authorization/generated/informers/internalversion"
buildinformer "github.com/openshift/origin/pkg/build/generated/informers/internalversion"
buildclientinternal "github.com/openshift/origin/pkg/build/generated/internalclientset"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
imageinformer "github.com/openshift/origin/pkg/image/generated/informers/internalversion"
imageclientinternal "github.com/openshift/origin/pkg/image/generated/internalclientset"
networkinformer "github.com/openshift/origin/pkg/network/generated/informers/internalversion"
networkclientinternal "github.com/openshift/origin/pkg/network/generated/internalclientset"
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion"
quotaclient "github.com/openshift/origin/pkg/quota/generated/internalclientset"
securityinformer "github.com/openshift/origin/pkg/security/generated/informers/internalversion"
securityclient "github.com/openshift/origin/pkg/security/generated/internalclientset"
templateinformer "github.com/openshift/origin/pkg/template/generated/informers/internalversion"
templateclient "github.com/openshift/origin/pkg/template/generated/internalclientset"
)
type ControllerContext struct {
OpenshiftControllerConfig configapi.OpenshiftControllerConfig
// ClientBuilder will provide a client for this controller to use
ClientBuilder ControllerClientBuilder
ExternalKubeInformers kexternalinformers.SharedInformerFactory
AppInformers appinformer.SharedInformerFactory
BuildInformers buildinformer.SharedInformerFactory
ImageInformers imageinformer.SharedInformerFactory
NetworkInformers networkinformer.SharedInformerFactory
TemplateInformers templateinformer.SharedInformerFactory
QuotaInformers quotainformer.SharedInformerFactory
AuthorizationInformers authorizationinformer.SharedInformerFactory
RouteInformers routeinformer.SharedInformerFactory
SecurityInformers securityinformer.SharedInformerFactory
GenericResourceInformer GenericResourceInformer
RestMapper meta.RESTMapper
// Stop is the stop channel
Stop <-chan struct{}
// InformersStarted is closed after all of the controllers have been initialized and are running. After this point it is safe,
// for an individual controller to start the shared informers. Before it is closed, they should not.
InformersStarted chan struct{}
}
type GenericResourceInformer interface {
ForResource(resource schema.GroupVersionResource) (kexternalinformers.GenericInformer, error)
Start(stopCh <-chan struct{})
}
func (c ControllerContext) IsControllerEnabled(name string) bool {
return controllerapp.IsControllerEnabled(name, sets.String{}, c.OpenshiftControllerConfig.Controllers...)
}
type ControllerClientBuilder interface {
controller.ControllerClientBuilder
KubeInternalClient(name string) (kclientsetinternal.Interface, error)
KubeInternalClientOrDie(name string) kclientsetinternal.Interface
OpenshiftInternalAppsClient(name string) (appsclientinternal.Interface, error)
OpenshiftInternalAppsClientOrDie(name string) appsclientinternal.Interface
OpenshiftInternalBuildClient(name string) (buildclientinternal.Interface, error)
OpenshiftInternalBuildClientOrDie(name string) buildclientinternal.Interface
// OpenShift clients based on generated internal clientsets
OpenshiftInternalTemplateClient(name string) (templateclient.Interface, error)
OpenshiftInternalTemplateClientOrDie(name string) templateclient.Interface
OpenshiftInternalImageClient(name string) (imageclientinternal.Interface, error)
OpenshiftInternalImageClientOrDie(name string) imageclientinternal.Interface
OpenshiftInternalQuotaClient(name string) (quotaclient.Interface, error)
OpenshiftInternalQuotaClientOrDie(name string) quotaclient.Interface
OpenshiftInternalNetworkClient(name string) (networkclientinternal.Interface, error)
OpenshiftInternalNetworkClientOrDie(name string) networkclientinternal.Interface
OpenshiftInternalSecurityClient(name string) (securityclient.Interface, error)
OpenshiftInternalSecurityClientOrDie(name string) securityclient.Interface
OpenshiftV1SecurityClient(name string) (securityv1client.Interface, error)
OpenshiftV1SecurityClientOrDie(name string) securityv1client.Interface
}
// InitFunc is used to launch a particular controller. It may run additional "should I activate checks".
// Any error returned will cause the controller process to `Fatal`
// The bool indicates whether the controller was enabled.
type InitFunc func(ctx ControllerContext) (bool, error)
type OpenshiftControllerClientBuilder struct {
controller.ControllerClientBuilder
}
func (b OpenshiftControllerClientBuilder) KubeInternalClient(name string) (kclientsetinternal.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return kclientsetinternal.NewForConfig(clientConfig)
}
func (b OpenshiftControllerClientBuilder) KubeInternalClientOrDie(name string) kclientsetinternal.Interface {
client, err := b.KubeInternalClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}
// OpenshiftInternalTemplateClient provides a REST client for the template API.
// If the client cannot be created because of configuration error, this function
// will return an error.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalTemplateClient(name string) (templateclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return templateclient.NewForConfig(clientConfig)
}
// OpenshiftInternalTemplateClientOrDie provides a REST client for the template API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalTemplateClientOrDie(name string) templateclient.Interface {
client, err := b.OpenshiftInternalTemplateClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}
// OpenshiftInternalImageClient provides a REST client for the image API.
// If the client cannot be created because of configuration error, this function
// will error.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalImageClient(name string) (imageclientinternal.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return imageclientinternal.NewForConfig(clientConfig)
}
// OpenshiftInternalImageClientOrDie provides a REST client for the image API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalImageClientOrDie(name string) imageclientinternal.Interface {
client, err := b.OpenshiftInternalImageClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}
// OpenshiftInternalAppsClient provides a REST client for the apps API.
// If the client cannot be created because of configuration error, this function
// will error.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalAppsClient(name string) (appsclientinternal.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return appsclientinternal.NewForConfig(clientConfig)
}
// OpenshiftInternalAppsClientOrDie provides a REST client for the apps API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalAppsClientOrDie(name string) appsclientinternal.Interface {
client, err := b.OpenshiftInternalAppsClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}
// OpenshiftInternalBuildClient provides a REST client for the build API.
// If the client cannot be created because of configuration error, this function
// will error.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalBuildClient(name string) (buildclientinternal.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return buildclientinternal.NewForConfig(clientConfig)
}
// OpenshiftInternalBuildClientOrDie provides a REST client for the build API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalBuildClientOrDie(name string) buildclientinternal.Interface {
client, err := b.OpenshiftInternalBuildClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}
func (b OpenshiftControllerClientBuilder) OpenshiftInternalQuotaClient(name string) (quotaclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return quotaclient.NewForConfig(clientConfig)
}
// OpenshiftInternalBuildClientOrDie provides a REST client for the build API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalQuotaClientOrDie(name string) quotaclient.Interface {
client, err := b.OpenshiftInternalQuotaClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}
// OpenshiftInternalNetworkClient provides a REST client for the network API.
// If the client cannot be created because of configuration error, this function
// will error.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalNetworkClient(name string) (networkclientinternal.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return networkclientinternal.NewForConfig(clientConfig)
}
// OpenshiftInternalNetworkClientOrDie provides a REST client for the network API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalNetworkClientOrDie(name string) networkclientinternal.Interface {
client, err := b.OpenshiftInternalNetworkClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}
// OpenshiftInternalSecurityClient provides a REST client for the security API.
// If the client cannot be created because of configuration error, this function
// will error.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalSecurityClient(name string) (securityclient.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return securityclient.NewForConfig(clientConfig)
}
// OpenshiftInternalSecurityClientOrDie provides a REST client for the security API.
// If the client cannot be created because of configuration error, this function
// will panic.
func (b OpenshiftControllerClientBuilder) OpenshiftInternalSecurityClientOrDie(name string) securityclient.Interface {
client, err := b.OpenshiftInternalSecurityClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}
func (b OpenshiftControllerClientBuilder) OpenshiftV1SecurityClient(name string) (securityv1client.Interface, error) {
clientConfig, err := b.Config(name)
if err != nil {
return nil, err
}
return securityv1client.NewForConfig(clientConfig)
}
func (b OpenshiftControllerClientBuilder) OpenshiftV1SecurityClientOrDie(name string) securityv1client.Interface {
client, err := b.OpenshiftV1SecurityClient(name)
if err != nil {
glog.Fatal(err)
}
return client
}