forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaster.go
516 lines (443 loc) · 21 KB
/
master.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
package origin
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"time"
"github.com/golang/glog"
apiextensionsinformers "k8s.io/apiextensions-apiserver/pkg/client/informers/internalversion"
utilnet "k8s.io/apimachinery/pkg/util/net"
apiserver "k8s.io/apiserver/pkg/server"
aggregatorapiserver "k8s.io/kube-aggregator/pkg/apiserver"
kubeapiserver "k8s.io/kubernetes/pkg/master"
kcorestorage "k8s.io/kubernetes/pkg/registry/core/rest"
rbacrest "k8s.io/kubernetes/pkg/registry/rbac/rest"
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
kubernetes "github.com/openshift/origin/pkg/cmd/server/kubernetes/master"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/oauth/urls"
oauthutil "github.com/openshift/origin/pkg/oauth/util"
routeplugin "github.com/openshift/origin/pkg/route/allocation/simple"
routeallocationcontroller "github.com/openshift/origin/pkg/route/controller/allocation"
sccstorage "github.com/openshift/origin/pkg/security/registry/securitycontextconstraints/etcd"
"k8s.io/apimachinery/pkg/util/wait"
kapiserveroptions "k8s.io/kubernetes/cmd/kube-apiserver/app/options"
)
const (
openShiftOAuthAPIPrefix = "/oauth"
openShiftLoginPrefix = "/login"
openShiftOAuthCallbackPrefix = "/oauth2callback"
)
func (c *MasterConfig) newOpenshiftAPIConfig(kubeAPIServerConfig apiserver.Config) (*OpenshiftAPIConfig, error) {
// sccStorage must use the upstream RESTOptionsGetter to be in the correct location
// this probably creates a duplicate cache, but there are not very many SCCs, so live with it to avoid further linkage
sccStorage := sccstorage.NewREST(kubeAPIServerConfig.RESTOptionsGetter)
// make a shallow copy to let us twiddle a few things
// most of the config actually remains the same. We only need to mess with a couple items
genericConfig := kubeAPIServerConfig
// TODO try to stop special casing these. We should all agree on them.
genericConfig.RESTOptionsGetter = c.RESTOptionsGetter
var caData []byte
if len(c.Options.ImagePolicyConfig.AdditionalTrustedCA) != 0 {
glog.V(2).Infof("Image import using additional CA path: %s", c.Options.ImagePolicyConfig.AdditionalTrustedCA)
var err error
caData, err = ioutil.ReadFile(c.Options.ImagePolicyConfig.AdditionalTrustedCA)
if err != nil {
return nil, fmt.Errorf("failed to read CA bundle %s for image importing: %v", c.Options.ImagePolicyConfig.AdditionalTrustedCA, err)
}
}
ret := &OpenshiftAPIConfig{
GenericConfig: &apiserver.RecommendedConfig{Config: genericConfig},
ExtraConfig: OpenshiftAPIExtraConfig{
KubeAPIServerClientConfig: &c.PrivilegedLoopbackClientConfig,
KubeClientInternal: c.PrivilegedLoopbackKubernetesClientsetInternal,
KubeInternalInformers: c.InternalKubeInformers,
KubeInformers: c.ClientGoKubeInformers,
QuotaInformers: c.QuotaInformers,
SecurityInformers: c.SecurityInformers,
RuleResolver: c.RuleResolver,
SubjectLocator: c.SubjectLocator,
LimitVerifier: c.LimitVerifier,
RegistryHostnameRetriever: c.RegistryHostnameRetriever,
AllowedRegistriesForImport: c.Options.ImagePolicyConfig.AllowedRegistriesForImport,
MaxImagesBulkImportedPerRepository: c.Options.ImagePolicyConfig.MaxImagesBulkImportedPerRepository,
AdditionalTrustedCA: caData,
RouteAllocator: c.RouteAllocator(),
ProjectAuthorizationCache: c.ProjectAuthorizationCache,
ProjectCache: c.ProjectCache,
ProjectRequestTemplate: c.Options.ProjectConfig.ProjectRequestTemplate,
ProjectRequestMessage: c.Options.ProjectConfig.ProjectRequestMessage,
ClusterQuotaMappingController: c.ClusterQuotaMappingController,
RESTMapper: c.RESTMapper,
SCCStorage: sccStorage,
},
}
if c.Options.OAuthConfig != nil {
ret.ExtraConfig.ServiceAccountMethod = c.Options.OAuthConfig.GrantConfig.ServiceAccountMethod
}
return ret, ret.ExtraConfig.Validate()
}
func (c *MasterConfig) newOpenshiftNonAPIConfig(kubeAPIServerConfig apiserver.Config) (*OpenshiftNonAPIConfig, error) {
var err error
ret := &OpenshiftNonAPIConfig{
GenericConfig: &apiserver.RecommendedConfig{
Config: kubeAPIServerConfig,
SharedInformerFactory: c.ClientGoKubeInformers,
},
}
ret.ExtraConfig.OAuthMetadata, _, err = oauthutil.PrepOauthMetadata(c.Options)
if err != nil {
return nil, err
}
return ret, nil
}
func (c *MasterConfig) withAPIExtensions(delegateAPIServer apiserver.DelegationTarget, kubeAPIServerOptions *kapiserveroptions.ServerRunOptions, kubeAPIServerConfig apiserver.Config) (apiserver.DelegationTarget, apiextensionsinformers.SharedInformerFactory, error) {
apiExtensionsConfig, err := createAPIExtensionsConfig(kubeAPIServerConfig, c.ClientGoKubeInformers, kubeAPIServerOptions)
if err != nil {
return nil, nil, err
}
apiExtensionsServer, err := createAPIExtensionsServer(apiExtensionsConfig, delegateAPIServer)
if err != nil {
return nil, nil, err
}
return apiExtensionsServer.GenericAPIServer, apiExtensionsServer.Informers, nil
}
func (c *MasterConfig) withNonAPIRoutes(delegateAPIServer apiserver.DelegationTarget, kubeAPIServerConfig apiserver.Config) (apiserver.DelegationTarget, error) {
openshiftNonAPIConfig, err := c.newOpenshiftNonAPIConfig(kubeAPIServerConfig)
if err != nil {
return nil, err
}
openshiftNonAPIServer, err := openshiftNonAPIConfig.Complete().New(delegateAPIServer)
if err != nil {
return nil, err
}
return openshiftNonAPIServer.GenericAPIServer, nil
}
func (c *MasterConfig) withOpenshiftAPI(delegateAPIServer apiserver.DelegationTarget, kubeAPIServerConfig apiserver.Config) (*apiserver.GenericAPIServer, error) {
openshiftAPIServerConfig, err := c.newOpenshiftAPIConfig(kubeAPIServerConfig)
if err != nil {
return nil, err
}
// We need to add an openshift type to the kube's core storage until at least 3.8. This does that by using a patch we carry.
kcorestorage.LegacyStorageMutatorFn = sccstorage.AddSCC(openshiftAPIServerConfig.ExtraConfig.SCCStorage)
openshiftAPIServer, err := openshiftAPIServerConfig.Complete().New(delegateAPIServer)
if err != nil {
return nil, err
}
// this sets up the openapi endpoints
preparedOpenshiftAPIServer := openshiftAPIServer.GenericAPIServer.PrepareRun()
return preparedOpenshiftAPIServer.GenericAPIServer, nil
}
func (c *MasterConfig) withKubeAPI(delegateAPIServer apiserver.DelegationTarget, kubeAPIServerConfig kubeapiserver.Config) (apiserver.DelegationTarget, error) {
var err error
if err != nil {
return nil, err
}
kubeAPIServer, err := kubeAPIServerConfig.Complete(c.ClientGoKubeInformers).New(delegateAPIServer)
if err != nil {
return nil, err
}
// this sets up the openapi endpoints
preparedKubeAPIServer := kubeAPIServer.GenericAPIServer.PrepareRun()
// this remains here and separate so that you can check both kube and openshift levels
// TODO make this is a proxy at some point
addOpenshiftVersionRoute(kubeAPIServer.GenericAPIServer.Handler.GoRestfulContainer, "/version/openshift")
return preparedKubeAPIServer.GenericAPIServer, nil
}
func (c *MasterConfig) newWebConsoleProxy() (http.Handler, error) {
caBundle, err := ioutil.ReadFile(c.Options.ControllerConfig.ServiceServingCert.Signer.CertFile)
if err != nil {
return nil, err
}
proxyHandler, err := NewServiceProxyHandler("webconsole", "openshift-web-console", aggregatorapiserver.NewClusterIPServiceResolver(c.ClientGoKubeInformers.Core().V1().Services().Lister()), caBundle, "OpenShift web console")
if err != nil {
return nil, err
}
return proxyHandler, nil
}
func (c *MasterConfig) newOAuthServerHandler(genericConfig *apiserver.Config) (http.Handler, map[string]apiserver.PostStartHookFunc, error) {
if c.Options.OAuthConfig == nil {
return http.NotFoundHandler(), nil, nil
}
config, err := NewOAuthServerConfigFromMasterConfig(c, genericConfig.SecureServing.Listener)
if err != nil {
return nil, nil, err
}
config.GenericConfig.AuditBackend = genericConfig.AuditBackend
config.GenericConfig.AuditPolicyChecker = genericConfig.AuditPolicyChecker
oauthServer, err := config.Complete().New(apiserver.NewEmptyDelegate())
if err != nil {
return nil, nil, err
}
return oauthServer.GenericAPIServer.PrepareRun().GenericAPIServer.Handler.FullHandlerChain,
map[string]apiserver.PostStartHookFunc{
"oauth.openshift.io-StartOAuthClientsBootstrapping": config.StartOAuthClientsBootstrapping,
},
nil
}
func (c *MasterConfig) withAggregator(delegateAPIServer apiserver.DelegationTarget, kubeAPIServerOptions *kapiserveroptions.ServerRunOptions, kubeAPIServerConfig apiserver.Config, apiExtensionsInformers apiextensionsinformers.SharedInformerFactory) (*aggregatorapiserver.APIAggregator, error) {
aggregatorConfig, err := createAggregatorConfig(
kubeAPIServerConfig,
kubeAPIServerOptions,
c.ClientGoKubeInformers,
aggregatorapiserver.NewClusterIPServiceResolver(c.ClientGoKubeInformers.Core().V1().Services().Lister()),
utilnet.SetTransportDefaults(&http.Transport{}),
)
if err != nil {
return nil, err
}
aggregatorServer, err := createAggregatorServer(aggregatorConfig, delegateAPIServer, apiExtensionsInformers)
if err != nil {
// we don't need special handling for innerStopCh because the aggregator server doesn't create any go routines
return nil, err
}
return aggregatorServer, nil
}
// Run launches the OpenShift master by creating a kubernetes master, installing
// OpenShift APIs into it and then running it.
// TODO this method only exists to support the old openshift start path. It should be removed a little ways into 3.10.
func (c *MasterConfig) Run(stopCh <-chan struct{}) error {
var err error
var apiExtensionsInformers apiextensionsinformers.SharedInformerFactory
var delegateAPIServer apiserver.DelegationTarget
var extraPostStartHooks map[string]apiserver.PostStartHookFunc
c.kubeAPIServerConfig.GenericConfig.BuildHandlerChainFunc, extraPostStartHooks, err = c.buildHandlerChain(c.kubeAPIServerConfig.GenericConfig, stopCh)
if err != nil {
return err
}
kubeAPIServerOptions, err := kubernetes.BuildKubeAPIserverOptions(c.Options)
if err != nil {
return err
}
delegateAPIServer = apiserver.NewEmptyDelegate()
delegateAPIServer, apiExtensionsInformers, err = c.withAPIExtensions(delegateAPIServer, kubeAPIServerOptions, *c.kubeAPIServerConfig.GenericConfig)
if err != nil {
return err
}
delegateAPIServer, err = c.withNonAPIRoutes(delegateAPIServer, *c.kubeAPIServerConfig.GenericConfig)
if err != nil {
return err
}
delegateAPIServer, err = c.withOpenshiftAPI(delegateAPIServer, *c.kubeAPIServerConfig.GenericConfig)
if err != nil {
return err
}
delegateAPIServer, err = c.withKubeAPI(delegateAPIServer, *c.kubeAPIServerConfig)
if err != nil {
return err
}
aggregatedAPIServer, err := c.withAggregator(delegateAPIServer, kubeAPIServerOptions, *c.kubeAPIServerConfig.GenericConfig, apiExtensionsInformers)
if err != nil {
return err
}
// Start the audit backend before any request comes in. This means we cannot turn it into a
// post start hook because without calling Backend.Run the Backend.ProcessEvents call might block.
if c.AuditBackend != nil {
if err := c.AuditBackend.Run(stopCh); err != nil {
return fmt.Errorf("failed to run the audit backend: %v", err)
}
}
if GRPCThreadLimit > 0 {
if err := aggregatedAPIServer.GenericAPIServer.AddHealthzChecks(NewGRPCStuckThreads()); err != nil {
return err
}
// We start a separate gofunc that will panic for us because nothing is watching healthz at the moment.
PanicOnGRPCStuckThreads(10*time.Second, stopCh)
}
// add post-start hooks
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("authorization.openshift.io-bootstrapclusterroles", bootstrapData(bootstrappolicy.Policy()).EnsureRBACPolicy())
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("authorization.openshift.io-ensureopenshift-infra", ensureOpenShiftInfraNamespace)
c.AddPostStartHooks(aggregatedAPIServer.GenericAPIServer)
for name, fn := range c.additionalPostStartHooks {
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie(name, fn)
}
for name, fn := range extraPostStartHooks {
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie(name, fn)
}
go aggregatedAPIServer.GenericAPIServer.PrepareRun().Run(stopCh)
// Attempt to verify the server came up for 20 seconds (100 tries * 100ms, 100ms timeout per try)
return cmdutil.WaitForSuccessfulDial(true, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.BindAddress, 100*time.Millisecond, 100*time.Millisecond, 100)
}
func (c *MasterConfig) RunKubeAPIServer(stopCh <-chan struct{}) error {
var err error
var apiExtensionsInformers apiextensionsinformers.SharedInformerFactory
var delegateAPIServer apiserver.DelegationTarget
var extraPostStartHooks map[string]apiserver.PostStartHookFunc
c.kubeAPIServerConfig.GenericConfig.BuildHandlerChainFunc, extraPostStartHooks, err = c.buildHandlerChain(c.kubeAPIServerConfig.GenericConfig, stopCh)
if err != nil {
return err
}
kubeAPIServerOptions, err := kubernetes.BuildKubeAPIserverOptions(c.Options)
if err != nil {
return err
}
delegateAPIServer = apiserver.NewEmptyDelegate()
delegateAPIServer, apiExtensionsInformers, err = c.withAPIExtensions(delegateAPIServer, kubeAPIServerOptions, *c.kubeAPIServerConfig.GenericConfig)
if err != nil {
return err
}
delegateAPIServer, err = c.withNonAPIRoutes(delegateAPIServer, *c.kubeAPIServerConfig.GenericConfig)
if err != nil {
return err
}
delegateAPIServer, err = c.withKubeAPI(delegateAPIServer, *c.kubeAPIServerConfig)
if err != nil {
return err
}
aggregatedAPIServer, err := c.withAggregator(delegateAPIServer, kubeAPIServerOptions, *c.kubeAPIServerConfig.GenericConfig, apiExtensionsInformers)
if err != nil {
return err
}
// Start the audit backend before any request comes in. This means we cannot turn it into a
// post start hook because without calling Backend.Run the Backend.ProcessEvents call might block.
if c.AuditBackend != nil {
if err := c.AuditBackend.Run(stopCh); err != nil {
return fmt.Errorf("failed to run the audit backend: %v", err)
}
}
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("authorization.openshift.io-bootstrapclusterroles", bootstrapData(bootstrappolicy.Policy()).EnsureRBACPolicy())
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie("authorization.openshift.io-ensureopenshift-infra", ensureOpenShiftInfraNamespace)
c.AddPostStartHooks(aggregatedAPIServer.GenericAPIServer)
// add post-start hooks
for name, fn := range c.additionalPostStartHooks {
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie(name, fn)
}
for name, fn := range extraPostStartHooks {
aggregatedAPIServer.GenericAPIServer.AddPostStartHookOrDie(name, fn)
}
go aggregatedAPIServer.GenericAPIServer.PrepareRun().Run(stopCh)
// Attempt to verify the server came up for 20 seconds (100 tries * 100ms, 100ms timeout per try)
return cmdutil.WaitForSuccessfulDial(true, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.BindAddress, 100*time.Millisecond, 100*time.Millisecond, 100)
}
func (c *MasterConfig) RunOpenShift(stopCh <-chan struct{}) error {
// TODO rewrite the authenticator and authorizer here to use the webhooks. I think we'll be able to manage this
// using the existing client connections since they'll all point to the kube-apiserver, but some new separation may be required
// to handle the distinction between loopback and kube-apiserver
// the openshift apiserver shouldn't need to host these and they make us crashloop
c.kubeAPIServerConfig.GenericConfig.EnableSwaggerUI = false
c.kubeAPIServerConfig.GenericConfig.SwaggerConfig = nil
c.kubeAPIServerConfig.GenericConfig.BuildHandlerChainFunc = openshiftHandlerChain
openshiftAPIServer, err := c.withOpenshiftAPI(apiserver.NewEmptyDelegate(), *c.kubeAPIServerConfig.GenericConfig)
if err != nil {
return err
}
// Start the audit backend before any request comes in. This means we cannot turn it into a
// post start hook because without calling Backend.Run the Backend.ProcessEvents call might block.
if c.AuditBackend != nil {
if err := c.AuditBackend.Run(stopCh); err != nil {
return fmt.Errorf("failed to run the audit backend: %v", err)
}
}
// add post-start hooks
c.AddPostStartHooks(openshiftAPIServer)
for name, fn := range c.additionalPostStartHooks {
openshiftAPIServer.AddPostStartHookOrDie(name, fn)
}
go openshiftAPIServer.PrepareRun().Run(stopCh)
// Attempt to verify the server came up for 20 seconds (100 tries * 100ms, 100ms timeout per try)
return cmdutil.WaitForSuccessfulDial(true, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.BindAddress, 100*time.Millisecond, 100*time.Millisecond, 100)
}
func (c *MasterConfig) buildHandlerChain(genericConfig *apiserver.Config, stopCh <-chan struct{}) (func(apiHandler http.Handler, kc *apiserver.Config) http.Handler, map[string]apiserver.PostStartHookFunc, error) {
webconsoleProxyHandler, err := c.newWebConsoleProxy()
if err != nil {
return nil, nil, err
}
oauthServerHandler, extraPostStartHooks, err := c.newOAuthServerHandler(genericConfig)
if err != nil {
return nil, nil, err
}
return func(apiHandler http.Handler, genericConfig *apiserver.Config) http.Handler {
// Machinery that let's use discover the Web Console Public URL
accessor := newWebConsolePublicURLAccessor(c.PrivilegedLoopbackClientConfig)
go accessor.Run(stopCh)
// these are after the kube handler
handler := c.versionSkewFilter(apiHandler)
// this is the normal kube handler chain
handler = apiserver.DefaultBuildHandlerChain(handler, genericConfig)
// these handlers are all before the normal kube chain
handler = translateLegacyScopeImpersonation(handler)
handler = withCacheControl(handler, "no-store") // protected endpoints should not be cached
// redirects from / to /console if you're using a browser
handler = withAssetServerRedirect(handler, accessor)
// these handlers are actually separate API servers which have their own handler chains.
// our server embeds these
handler = c.withConsoleRedirection(handler, webconsoleProxyHandler, accessor)
handler = c.withOAuthRedirection(handler, oauthServerHandler)
return handler
},
extraPostStartHooks,
nil
}
func openshiftHandlerChain(apiHandler http.Handler, genericConfig *apiserver.Config) http.Handler {
// this is the normal kube handler chain
handler := apiserver.DefaultBuildHandlerChain(apiHandler, genericConfig)
handler = withCacheControl(handler, "no-store") // protected endpoints should not be cached
return handler
}
func (c *MasterConfig) withOAuthRedirection(handler, oauthServerHandler http.Handler) http.Handler {
if c.Options.OAuthConfig == nil {
return handler
}
glog.Infof("Starting OAuth2 API at %s", urls.OpenShiftOAuthAPIPrefix)
return WithPatternPrefixHandler(handler, oauthServerHandler, openShiftOAuthAPIPrefix, openShiftLoginPrefix, openShiftOAuthCallbackPrefix)
}
// RouteAllocator returns a route allocation controller.
func (c *MasterConfig) RouteAllocator() *routeallocationcontroller.RouteAllocationController {
factory := routeallocationcontroller.RouteAllocationControllerFactory{
KubeClient: c.PrivilegedLoopbackKubernetesClientsetInternal,
}
plugin, err := routeplugin.NewSimpleAllocationPlugin(c.Options.RoutingConfig.Subdomain)
if err != nil {
glog.Fatalf("Route plugin initialization failed: %v", err)
}
return factory.Create(plugin)
}
// env returns an environment variable, or the defaultValue if it is not set.
func env(key string, defaultValue string) string {
val := os.Getenv(key)
if len(val) == 0 {
return defaultValue
}
return val
}
func WithPatternPrefixHandler(handler http.Handler, patternHandler http.Handler, prefixes ...string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
for _, p := range prefixes {
if strings.HasPrefix(req.URL.Path, p) {
patternHandler.ServeHTTP(w, req)
return
}
}
handler.ServeHTTP(w, req)
})
}
func (c *MasterConfig) AddPostStartHooks(server *apiserver.GenericAPIServer) {
server.AddPostStartHookOrDie("quota.openshift.io-clusterquotamapping", c.startClusterQuotaMapping)
server.AddPostStartHookOrDie("openshift.io-RESTMapper", c.startRESTMapper)
}
func (c *MasterConfig) startClusterQuotaMapping(context apiserver.PostStartHookContext) error {
go c.ClusterQuotaMappingController.Run(5, context.StopCh)
return nil
}
func (c *MasterConfig) startRESTMapper(context apiserver.PostStartHookContext) error {
c.RESTMapper.Reset()
go func() {
wait.Until(func() {
c.RESTMapper.Reset()
}, 10*time.Second, context.StopCh)
}()
return nil
}
// bootstrapData casts our policy data to the rbacrest helper that can
// materialize the policy.
func bootstrapData(data *bootstrappolicy.PolicyData) *rbacrest.PolicyData {
return &rbacrest.PolicyData{
ClusterRoles: data.ClusterRoles,
ClusterRoleBindings: data.ClusterRoleBindings,
Roles: data.Roles,
RoleBindings: data.RoleBindings,
ClusterRolesToAggregate: data.ClusterRolesToAggregate,
}
}