-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
run_components.go
597 lines (522 loc) · 26.5 KB
/
run_components.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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
package origin
import (
"io/ioutil"
"net"
"path"
"sync"
"time"
"github.com/golang/glog"
deployclient "github.com/openshift/origin/pkg/deploy/generated/internalclientset/typed/deploy/internalversion"
"k8s.io/apimachinery/pkg/runtime/schema"
utilwait "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/admission"
"k8s.io/client-go/util/cert"
"k8s.io/client-go/util/flowcontrol"
kctrlmgr "k8s.io/kubernetes/cmd/kube-controller-manager/app"
cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
kapi "k8s.io/kubernetes/pkg/api"
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
kclientsetexternal "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
kclientsetinternal "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/controller"
kresourcequota "k8s.io/kubernetes/pkg/controller/resourcequota"
sacontroller "k8s.io/kubernetes/pkg/controller/serviceaccount"
kubeadmission "k8s.io/kubernetes/pkg/kubeapiserver/admission"
"k8s.io/kubernetes/pkg/registry/core/service/allocator"
etcdallocator "k8s.io/kubernetes/pkg/registry/core/service/allocator/storage"
"k8s.io/kubernetes/pkg/serviceaccount"
serviceaccountadmission "k8s.io/kubernetes/plugin/pkg/admission/serviceaccount"
builddefaults "github.com/openshift/origin/pkg/build/admission/defaults"
buildoverrides "github.com/openshift/origin/pkg/build/admission/overrides"
buildclient "github.com/openshift/origin/pkg/build/client"
buildpodcontroller "github.com/openshift/origin/pkg/build/controller/buildpod"
buildcontrollerfactory "github.com/openshift/origin/pkg/build/controller/factory"
buildstrategy "github.com/openshift/origin/pkg/build/controller/strategy"
osclient "github.com/openshift/origin/pkg/client"
oscache "github.com/openshift/origin/pkg/client/cache"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
"github.com/openshift/origin/pkg/cmd/server/crypto"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/controller/shared"
deploycontroller "github.com/openshift/origin/pkg/deploy/controller/deployment"
deployconfigcontroller "github.com/openshift/origin/pkg/deploy/controller/deploymentconfig"
triggercontroller "github.com/openshift/origin/pkg/deploy/controller/generictrigger"
"github.com/openshift/origin/pkg/dns"
imagecontroller "github.com/openshift/origin/pkg/image/controller"
projectcontroller "github.com/openshift/origin/pkg/project/controller"
quota "github.com/openshift/origin/pkg/quota"
quotacontroller "github.com/openshift/origin/pkg/quota/controller"
"github.com/openshift/origin/pkg/quota/controller/clusterquotareconciliation"
sdnplugin "github.com/openshift/origin/pkg/sdn/plugin"
securitycontroller "github.com/openshift/origin/pkg/security/controller"
"github.com/openshift/origin/pkg/security/mcs"
"github.com/openshift/origin/pkg/security/uid"
"github.com/openshift/origin/pkg/security/uidallocator"
"github.com/openshift/origin/pkg/service/controller/ingressip"
servingcertcontroller "github.com/openshift/origin/pkg/service/controller/servingcert"
serviceaccountcontrollers "github.com/openshift/origin/pkg/serviceaccounts/controllers"
templatecontroller "github.com/openshift/origin/pkg/template/controller"
unidlingcontroller "github.com/openshift/origin/pkg/unidling/controller"
)
const (
defaultConcurrentResourceQuotaSyncs int = 5
defaultResourceQuotaSyncPeriod time.Duration = 5 * time.Minute
// from CMServer MinResyncPeriod
defaultReplenishmentSyncPeriod time.Duration = 12 * time.Hour
defaultIngressIPSyncPeriod time.Duration = 10 * time.Minute
)
// RunProjectAuthorizationCache starts the project authorization cache
func (c *MasterConfig) RunProjectAuthorizationCache() {
// TODO: look at exposing a configuration option in future to control how often we run this loop
period := 1 * time.Second
c.ProjectAuthorizationCache.Run(period)
}
// RunOriginNamespaceController starts the controller that takes part in namespace termination of openshift content
func (c *MasterConfig) RunOriginNamespaceController() {
kclient := c.OriginNamespaceControllerClient()
factory := projectcontroller.NamespaceControllerFactory{
KubeClient: kclient,
}
controller := factory.Create()
controller.Run()
}
// RunServiceAccountsController starts the service account controller
func (c *MasterConfig) RunServiceAccountsController() {
if len(c.Options.ServiceAccountConfig.ManagedNames) == 0 {
glog.Infof("Skipped starting Service Account Manager, no managed names specified")
return
}
options := sacontroller.DefaultServiceAccountsControllerOptions()
options.ServiceAccounts = []kapiv1.ServiceAccount{}
for _, saName := range c.Options.ServiceAccountConfig.ManagedNames {
sa := kapiv1.ServiceAccount{}
sa.Name = saName
options.ServiceAccounts = append(options.ServiceAccounts, sa)
}
//REBASE: add new args to NewServiceAccountsController
go sacontroller.NewServiceAccountsController(c.Informers.KubernetesInformers().Core().V1().ServiceAccounts(), c.Informers.KubernetesInformers().Core().V1().Namespaces(), c.KubeClientsetExternal(), options).Run(1, utilwait.NeverStop)
}
// RunServiceAccountTokensController starts the service account token controller
func (c *MasterConfig) RunServiceAccountTokensController(cm *cmapp.CMServer) {
if len(c.Options.ServiceAccountConfig.PrivateKeyFile) == 0 {
glog.Infof("Skipped starting Service Account Token Manager, no private key specified")
return
}
privateKey, err := serviceaccount.ReadPrivateKey(c.Options.ServiceAccountConfig.PrivateKeyFile)
if err != nil {
glog.Fatalf("Error reading signing key for Service Account Token Manager: %v", err)
}
rootCA := []byte{}
if len(c.Options.ServiceAccountConfig.MasterCA) > 0 {
rootCA, err = ioutil.ReadFile(c.Options.ServiceAccountConfig.MasterCA)
if err != nil {
glog.Fatalf("Error reading master ca file for Service Account Token Manager: %s: %v", c.Options.ServiceAccountConfig.MasterCA, err)
}
if _, err := cert.ParseCertsPEM(rootCA); err != nil {
glog.Fatalf("Error parsing master ca file for Service Account Token Manager: %s: %v", c.Options.ServiceAccountConfig.MasterCA, err)
}
}
servingServingCABundle := []byte{}
if c.Options.ControllerConfig.ServiceServingCert.Signer != nil && len(c.Options.ControllerConfig.ServiceServingCert.Signer.CertFile) > 0 {
servingServingCA, err := ioutil.ReadFile(c.Options.ControllerConfig.ServiceServingCert.Signer.CertFile)
if err != nil {
glog.Fatalf("Error reading ca file for Service Serving Certificate Signer: %s: %v", c.Options.ControllerConfig.ServiceServingCert.Signer.CertFile, err)
}
if _, err := crypto.CertsFromPEM(servingServingCA); err != nil {
glog.Fatalf("Error parsing ca file for Service Serving Certificate Signer: %s: %v", c.Options.ControllerConfig.ServiceServingCert.Signer.CertFile, err)
}
// if we have a rootCA bundle add that too. The rootCA will be used when hitting the default master service, since those are signed
// using a different CA by default. The rootCA's key is more closely guarded than ours and if it is compromised, that power could
// be used to change the trusted signers for every pod anyway, so we're already effectively trusting it.
if len(rootCA) > 0 {
servingServingCABundle = append(servingServingCABundle, rootCA...)
servingServingCABundle = append(servingServingCABundle, []byte("\n")...)
}
servingServingCABundle = append(servingServingCABundle, servingServingCA...)
}
options := sacontroller.TokensControllerOptions{
TokenGenerator: serviceaccount.JWTTokenGenerator(privateKey),
RootCA: rootCA,
ServiceServingCA: servingServingCABundle,
}
go sacontroller.NewTokensController(c.KubeClientsetExternal(), options).Run(int(cm.ConcurrentSATokenSyncs), utilwait.NeverStop)
}
// RunServiceAccountPullSecretsControllers starts the service account pull secret controllers
func (c *MasterConfig) RunServiceAccountPullSecretsControllers() {
serviceaccountcontrollers.NewDockercfgDeletedController(c.KubeClientsetInternal(), serviceaccountcontrollers.DockercfgDeletedControllerOptions{}).Run()
serviceaccountcontrollers.NewDockercfgTokenDeletedController(c.KubeClientsetInternal(), serviceaccountcontrollers.DockercfgTokenDeletedControllerOptions{}).Run()
dockerURLsIntialized := make(chan struct{})
dockercfgController := serviceaccountcontrollers.NewDockercfgController(c.KubeClientsetInternal(), serviceaccountcontrollers.DockercfgControllerOptions{DockerURLsIntialized: dockerURLsIntialized})
go dockercfgController.Run(5, utilwait.NeverStop)
dockerRegistryControllerOptions := serviceaccountcontrollers.DockerRegistryServiceControllerOptions{
RegistryNamespace: "default",
RegistryServiceName: "docker-registry",
DockercfgController: dockercfgController,
DockerURLsIntialized: dockerURLsIntialized,
}
go serviceaccountcontrollers.NewDockerRegistryServiceController(c.KubeClientsetInternal(), dockerRegistryControllerOptions).Run(10, make(chan struct{}))
}
// RunAssetServer starts the asset server for the OpenShift UI.
func (c *MasterConfig) RunAssetServer() {
}
// RunDNSServer starts the DNS server
func (c *MasterConfig) RunDNSServer() {
config, err := dns.NewServerDefaults()
if err != nil {
glog.Fatalf("Could not start DNS: %v", err)
}
switch c.Options.DNSConfig.BindNetwork {
case "tcp":
config.BindNetwork = "ip"
case "tcp4":
config.BindNetwork = "ipv4"
case "tcp6":
config.BindNetwork = "ipv6"
}
config.DnsAddr = c.Options.DNSConfig.BindAddress
config.NoRec = !c.Options.DNSConfig.AllowRecursiveQueries
_, port, err := net.SplitHostPort(c.Options.DNSConfig.BindAddress)
if err != nil {
glog.Fatalf("Could not start DNS: %v", err)
}
if port != "53" {
glog.Warningf("Binding DNS on port %v instead of 53, which may not be resolvable from all clients", port)
}
if ok, err := cmdutil.TryListen(c.Options.DNSConfig.BindNetwork, c.Options.DNSConfig.BindAddress); !ok {
glog.Warningf("Could not start DNS: %v", err)
return
}
services, err := dns.NewCachedServiceAccessor(c.Informers.InternalKubernetesInformers().Core().InternalVersion().Services())
if err != nil {
glog.Fatalf("Could not start DNS: failed to add ClusterIP index: %v", err)
}
go func() {
s := dns.NewServer(
config,
services,
c.Informers.InternalKubernetesInformers().Core().InternalVersion().Endpoints().Lister(),
"apiserver",
)
err = s.ListenAndServe()
glog.Fatalf("Could not start DNS: %v", err)
}()
cmdutil.WaitForSuccessfulDial(false, "tcp", c.Options.DNSConfig.BindAddress, 100*time.Millisecond, 100*time.Millisecond, 100)
glog.Infof("DNS listening at %s", c.Options.DNSConfig.BindAddress)
}
// RunProjectCache populates project cache, used by scheduler and project admission controller.
func (c *MasterConfig) RunProjectCache() {
glog.Infof("Using default project node label selector: %s", c.Options.ProjectConfig.DefaultNodeSelector)
c.ProjectCache.Run()
}
// RunBuildController starts the build sync loop for builds and buildConfig processing.
func (c *MasterConfig) RunBuildController(informers shared.InformerFactory) error {
// initialize build controller
dockerImage := c.ImageFor("docker-builder")
stiImage := c.ImageFor("sti-builder")
storageVersion := c.Options.EtcdStorageConfig.OpenShiftStorageVersion
groupVersion := schema.GroupVersion{Group: "", Version: storageVersion}
codec := kapi.Codecs.LegacyCodec(groupVersion)
pluginInitializer := kubeadmission.NewPluginInitializer(
c.KubeClientsetInternal(),
c.Informers.InternalKubernetesInformers(),
nil, // api authorizer, only used by PSP
nil, // cloud config
)
admissionControl, err := admission.InitPlugin("SecurityContextConstraint", nil, pluginInitializer)
if err != nil {
return err
}
buildDefaults, err := builddefaults.NewBuildDefaults(c.Options.AdmissionConfig.PluginConfig)
if err != nil {
return err
}
buildOverrides, err := buildoverrides.NewBuildOverrides(c.Options.AdmissionConfig.PluginConfig)
if err != nil {
return err
}
osclient, internalKubeClientset, externalKubeClientset := c.BuildControllerClients()
factory := buildcontrollerfactory.BuildControllerFactory{
KubeClient: internalKubeClientset,
ExternalKubeClient: externalKubeClientset,
OSClient: osclient,
BuildUpdater: buildclient.NewOSClientBuildClient(osclient),
BuildLister: buildclient.NewOSClientBuildClient(osclient),
DockerBuildStrategy: &buildstrategy.DockerBuildStrategy{
Image: dockerImage,
// TODO: this will be set to --storage-version (the internal schema we use)
Codec: codec,
},
SourceBuildStrategy: &buildstrategy.SourceBuildStrategy{
Image: stiImage,
// TODO: this will be set to --storage-version (the internal schema we use)
Codec: codec,
AdmissionControl: admissionControl,
},
CustomBuildStrategy: &buildstrategy.CustomBuildStrategy{
// TODO: this will be set to --storage-version (the internal schema we use)
Codec: codec,
},
BuildDefaults: buildDefaults,
BuildOverrides: buildOverrides,
}
controller := factory.Create()
controller.Run()
deleteController := factory.CreateDeleteController()
deleteController.Run()
return nil
}
// RunBuildPodController starts the build/pod status sync loop for build status
func (c *MasterConfig) RunBuildPodController() {
buildInfomer := c.Informers.Builds().Informer()
podInformer := c.Informers.InternalKubernetesInformers().Core().InternalVersion().Pods()
osclient, kclientInternal, kclientExternal := c.BuildPodControllerClients()
controller := buildpodcontroller.NewBuildPodController(buildInfomer, podInformer, kclientInternal, kclientExternal, osclient)
go controller.Run(5, utilwait.NeverStop)
}
// RunBuildImageChangeTriggerController starts the build image change trigger controller process.
func (c *MasterConfig) RunBuildImageChangeTriggerController() {
bcClient, _ := c.BuildImageChangeTriggerControllerClients()
bcInstantiator := buildclient.NewOSClientBuildConfigInstantiatorClient(bcClient)
bcIndex := &oscache.StoreToBuildConfigListerImpl{Indexer: c.Informers.BuildConfigs().Indexer()}
bcIndexSynced := c.Informers.BuildConfigs().Informer().HasSynced
factory := buildcontrollerfactory.ImageChangeControllerFactory{Client: bcClient, BuildConfigInstantiator: bcInstantiator, BuildConfigIndex: bcIndex, BuildConfigIndexSynced: bcIndexSynced}
go func() {
factory.Create().Run()
}()
}
// RunBuildConfigChangeController starts the build config change trigger controller process.
func (c *MasterConfig) RunBuildConfigChangeController() {
bcClient, internalKubeClientset, externalKubeClientset := c.BuildConfigChangeControllerClients()
bcInstantiator := buildclient.NewOSClientBuildConfigInstantiatorClient(bcClient)
factory := buildcontrollerfactory.BuildConfigControllerFactory{
Client: bcClient,
KubeClient: internalKubeClientset,
ExternalKubeClient: externalKubeClientset,
BuildConfigInstantiator: bcInstantiator,
}
factory.Create().Run()
}
// RunDeploymentController starts the deployment controller process.
func (c *MasterConfig) RunDeploymentController() {
// TODO these should be external
rcInformer := c.Informers.InternalKubernetesInformers().Core().InternalVersion().ReplicationControllers()
podInformer := c.Informers.InternalKubernetesInformers().Core().InternalVersion().Pods()
_, internalKubeClientset, externalKubeClientset := c.DeploymentControllerClients()
_, kclientConfig, err := configapi.GetInternalKubeClient(c.Options.MasterClients.OpenShiftLoopbackKubeConfig, c.Options.MasterClients.OpenShiftLoopbackClientConnectionOverrides)
if err != nil {
glog.Fatalf("Unable to initialize deployment controller: %v", err)
}
// TODO eliminate these environment variables once service accounts provide a kubeconfig that includes all of this info
env := clientcmd.EnvVars(
kclientConfig.Host,
kclientConfig.CAData,
kclientConfig.Insecure,
path.Join(serviceaccountadmission.DefaultAPITokenMountPath, kapi.ServiceAccountTokenKey),
)
controller := deploycontroller.NewDeploymentController(
rcInformer,
podInformer,
internalKubeClientset,
externalKubeClientset,
bootstrappolicy.DeployerServiceAccountName,
c.ImageFor("deployer"),
env,
c.ExternalVersionCodec,
)
go controller.Run(5, utilwait.NeverStop)
}
// RunDeploymentConfigController starts the deployment config controller process.
func (c *MasterConfig) RunDeploymentConfigController() {
dcInfomer := c.Informers.DeploymentConfigs().Informer()
rcInformer := c.Informers.InternalKubernetesInformers().Core().InternalVersion().ReplicationControllers()
podInformer := c.Informers.InternalKubernetesInformers().Core().InternalVersion().Pods()
osclient, kclientInternal, kclientExternal := c.DeploymentConfigControllerClients()
controller := deployconfigcontroller.NewDeploymentConfigController(dcInfomer, rcInformer, podInformer, osclient, kclientInternal, kclientExternal, c.ExternalVersionCodec)
go controller.Run(5, utilwait.NeverStop)
}
// RunDeploymentTriggerController starts the deployment trigger controller process.
func (c *MasterConfig) RunDeploymentTriggerController() {
dcInfomer := c.Informers.DeploymentConfigs().Informer()
rcInformer := c.Informers.InternalKubernetesInformers().Core().InternalVersion().ReplicationControllers().Informer()
streamInformer := c.Informers.ImageStreams().Informer()
osclient := c.DeploymentTriggerControllerClient()
controller := triggercontroller.NewDeploymentTriggerController(dcInfomer, rcInformer, streamInformer, osclient, c.ExternalVersionCodec)
go controller.Run(5, utilwait.NeverStop)
}
// RunSDNController runs openshift-sdn if the said network plugin is provided
func (c *MasterConfig) RunSDNController() {
oClient, kClient := c.SDNControllerClients()
if err := sdnplugin.StartMaster(c.Options.NetworkConfig, oClient, kClient, c.Informers); err != nil {
glog.Fatalf("SDN initialization failed: %v", err)
}
}
func (c *MasterConfig) RunServiceServingCertController(client kclientsetinternal.Interface) {
if c.Options.ControllerConfig.ServiceServingCert.Signer == nil {
return
}
ca, err := crypto.GetCA(c.Options.ControllerConfig.ServiceServingCert.Signer.CertFile, c.Options.ControllerConfig.ServiceServingCert.Signer.KeyFile, "")
if err != nil {
glog.Fatalf("service serving cert controller failed: %v", err)
}
servingCertController := servingcertcontroller.NewServiceServingCertController(client.Core(), client.Core(), ca, "cluster.local", 2*time.Minute)
go servingCertController.Run(1, make(chan struct{}))
servingCertUpdateController := servingcertcontroller.NewServiceServingCertUpdateController(client.Core(), client.Core(), ca, "cluster.local", 20*time.Minute)
go servingCertUpdateController.Run(5, make(chan struct{}))
}
// RunImageImportController starts the image import trigger controller process.
func (c *MasterConfig) RunImageImportController() {
osclient := c.ImageImportControllerClient()
var limiter flowcontrol.RateLimiter = nil
if c.Options.ImagePolicyConfig.MaxScheduledImageImportsPerMinute <= 0 {
limiter = flowcontrol.NewFakeAlwaysRateLimiter()
} else {
importRate := float32(c.Options.ImagePolicyConfig.MaxScheduledImageImportsPerMinute) / float32(time.Minute/time.Second)
importBurst := c.Options.ImagePolicyConfig.MaxScheduledImageImportsPerMinute * 2
limiter = flowcontrol.NewTokenBucketRateLimiter(importRate, importBurst)
}
factory := imagecontroller.ImportControllerFactory{
Client: osclient,
ResyncInterval: 10 * time.Minute,
MinimumCheckInterval: time.Duration(c.Options.ImagePolicyConfig.ScheduledImageImportMinimumIntervalSeconds) * time.Second,
ImportRateLimiter: limiter,
ScheduleEnabled: !c.Options.ImagePolicyConfig.DisableScheduledImport,
}
controller, scheduledController := factory.Create()
controller.Run()
if c.Options.ImagePolicyConfig.DisableScheduledImport {
glog.V(2).Infof("Scheduled image import is disabled - the 'scheduled' flag on image streams will be ignored")
} else {
scheduledController.RunUntil(utilwait.NeverStop)
}
}
// RunSecurityAllocationController starts the security allocation controller process.
func (c *MasterConfig) RunSecurityAllocationController() {
alloc := c.Options.ProjectConfig.SecurityAllocator
if alloc == nil {
glog.V(3).Infof("Security allocator is disabled - no UIDs assigned to projects")
return
}
// TODO: move range initialization to run_config
uidRange, err := uid.ParseRange(alloc.UIDAllocatorRange)
if err != nil {
glog.Fatalf("Unable to describe UID range: %v", err)
}
opts, err := c.RESTOptionsGetter.GetRESTOptions(schema.GroupResource{Resource: "securityuidranges"})
if err != nil {
glog.Fatalf("Unable to load storage options for security UID ranges")
}
var etcdAlloc *etcdallocator.Etcd
uidAllocator := uidallocator.New(uidRange, func(max int, rangeSpec string) allocator.Interface {
mem := allocator.NewContiguousAllocationMap(max, rangeSpec)
etcdAlloc = etcdallocator.NewEtcd(mem, "/ranges/uids", kapi.Resource("uidallocation"), opts.StorageConfig)
return etcdAlloc
})
mcsRange, err := mcs.ParseRange(alloc.MCSAllocatorRange)
if err != nil {
glog.Fatalf("Unable to describe MCS category range: %v", err)
}
kclient := c.SecurityAllocationControllerClient()
repair := securitycontroller.NewRepair(time.Minute, kclient.Core().Namespaces(), uidRange, etcdAlloc)
if err := repair.RunOnce(); err != nil {
// TODO: v scary, may need to use direct etcd calls?
// If the security controller fails during RunOnce it could mean a
// couple of things:
// 1. an unexpected etcd error occurred getting an allocator or the namespaces
// 2. the allocation blocks were full - would result in an admission controller that is unable
// to create the strategies correctly which would likely mean that the cluster
// would not admit pods the the majority of users.
// 3. an unexpected error persisting an allocation for a namespace has occurred - same as above
// In all cases we do not want to continue normal operations, this should be fatal.
glog.Fatalf("Unable to initialize namespaces: %v", err)
}
factory := securitycontroller.AllocationFactory{
UIDAllocator: uidAllocator,
MCSAllocator: securitycontroller.DefaultMCSAllocation(uidRange, mcsRange, alloc.MCSLabelsPerProject),
Client: kclient.Core().Namespaces(),
// TODO: reuse namespace cache
}
controller := factory.Create()
controller.Run()
}
// RunGroupCache starts the group cache
func (c *MasterConfig) RunGroupCache() {
c.GroupCache.Run()
}
// RunResourceQuotaManager starts resource quota controller for OpenShift resources
func (c *MasterConfig) RunResourceQuotaManager(cm *cmapp.CMServer) {
concurrentResourceQuotaSyncs := defaultConcurrentResourceQuotaSyncs
resourceQuotaSyncPeriod := defaultResourceQuotaSyncPeriod
replenishmentSyncPeriodFunc := controller.StaticResyncPeriodFunc(defaultReplenishmentSyncPeriod)
if cm != nil {
// TODO: should these be part of os master config?
concurrentResourceQuotaSyncs = int(cm.ConcurrentResourceQuotaSyncs)
resourceQuotaSyncPeriod = cm.ResourceQuotaSyncPeriod.Duration
replenishmentSyncPeriodFunc = kctrlmgr.ResyncPeriod(cm)
}
osClient, _, kClientExternal := c.ResourceQuotaManagerClients()
resourceQuotaRegistry := quota.NewAllResourceQuotaRegistry(c.Informers, osClient, kClientExternal)
resourceQuotaControllerOptions := &kresourcequota.ResourceQuotaControllerOptions{
KubeClient: kClientExternal,
ResourceQuotaInformer: c.Informers.KubernetesInformers().Core().V1().ResourceQuotas(),
ResyncPeriod: controller.StaticResyncPeriodFunc(resourceQuotaSyncPeriod),
Registry: resourceQuotaRegistry,
GroupKindsToReplenish: quota.AllEvaluatedGroupKinds,
ControllerFactory: quotacontroller.NewAllResourceReplenishmentControllerFactory(c.Informers, osClient),
ReplenishmentResyncPeriod: replenishmentSyncPeriodFunc,
}
go kresourcequota.NewResourceQuotaController(resourceQuotaControllerOptions).Run(concurrentResourceQuotaSyncs, utilwait.NeverStop)
}
var initClusterQuotaMapping sync.Once
func (c *MasterConfig) RunClusterQuotaMappingController() {
initClusterQuotaMapping.Do(func() {
go c.ClusterQuotaMappingController.Run(5, utilwait.NeverStop)
})
}
func (c *MasterConfig) RunClusterQuotaReconciliationController() {
osClient, _, kClientExternal := c.ResourceQuotaManagerClients()
resourceQuotaRegistry := quota.NewAllResourceQuotaRegistry(c.Informers, osClient, kClientExternal)
groupKindsToReplenish := quota.AllEvaluatedGroupKinds
options := clusterquotareconciliation.ClusterQuotaReconcilationControllerOptions{
ClusterQuotaInformer: c.Informers.ClusterResourceQuotas(),
ClusterQuotaMapper: c.ClusterQuotaMappingController.GetClusterQuotaMapper(),
ClusterQuotaClient: osClient,
Registry: resourceQuotaRegistry,
ResyncPeriod: defaultResourceQuotaSyncPeriod,
ControllerFactory: quotacontroller.NewAllResourceReplenishmentControllerFactory(c.Informers, osClient),
ReplenishmentResyncPeriod: controller.StaticResyncPeriodFunc(defaultReplenishmentSyncPeriod),
GroupKindsToReplenish: groupKindsToReplenish,
}
controller := clusterquotareconciliation.NewClusterQuotaReconcilationController(options)
c.ClusterQuotaMappingController.GetClusterQuotaMapper().AddListener(controller)
go controller.Run(5, utilwait.NeverStop)
}
// RunIngressIPController starts the ingress ip controller if IngressIPNetworkCIDR is configured.
func (c *MasterConfig) RunIngressIPController(internalKubeClientset kclientsetinternal.Interface, externalKubeClientset kclientsetexternal.Interface) {
if len(c.Options.NetworkConfig.IngressIPNetworkCIDR) == 0 {
return
}
_, ipNet, err := net.ParseCIDR(c.Options.NetworkConfig.IngressIPNetworkCIDR)
if err != nil {
// should have been caught with validation
glog.Fatalf("Unable to start ingress ip controller: %v", err)
}
if ipNet.IP.IsUnspecified() {
return
}
ingressIPController := ingressip.NewIngressIPController(internalKubeClientset, externalKubeClientset, ipNet, defaultIngressIPSyncPeriod)
go ingressIPController.Run(utilwait.NeverStop)
}
// RunUnidlingController starts the unidling controller
func (c *MasterConfig) RunUnidlingController() {
oc, kc, extensionsClient := c.UnidlingControllerClients()
resyncPeriod := 2 * time.Hour
scaleNamespacer := osclient.NewDelegatingScaleNamespacer(oc, extensionsClient)
dcCoreClient := deployclient.New(oc.RESTClient)
cont := unidlingcontroller.NewUnidlingController(scaleNamespacer, kc.Core(), kc.Core(), dcCoreClient, kc.Core(), resyncPeriod)
cont.Run(utilwait.NeverStop)
}
func (c *MasterConfig) RunTemplateController() {
go templatecontroller.NewTemplateInstanceController(c.PrivilegedLoopbackClientConfig).Run(utilwait.NeverStop)
}