-
Notifications
You must be signed in to change notification settings - Fork 473
/
add.go
123 lines (104 loc) · 4.68 KB
/
add.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
// Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package controller
import (
"fmt"
"github.com/gardener/gardener/pkg/controllermanager/apis/config"
"github.com/gardener/gardener/pkg/controllermanager/controller/bastion"
"github.com/gardener/gardener/pkg/controllermanager/controller/certificatesigningrequest"
"github.com/gardener/gardener/pkg/controllermanager/controller/cloudprofile"
"github.com/gardener/gardener/pkg/controllermanager/controller/controllerdeployment"
"github.com/gardener/gardener/pkg/controllermanager/controller/controllerregistration"
"github.com/gardener/gardener/pkg/controllermanager/controller/event"
"github.com/gardener/gardener/pkg/controllermanager/controller/exposureclass"
"github.com/gardener/gardener/pkg/controllermanager/controller/managedseedset"
"github.com/gardener/gardener/pkg/controllermanager/controller/project"
"github.com/gardener/gardener/pkg/controllermanager/controller/quota"
"github.com/gardener/gardener/pkg/controllermanager/controller/secretbinding"
"github.com/gardener/gardener/pkg/controllermanager/controller/seed"
"github.com/gardener/gardener/pkg/controllermanager/controller/shoot"
kubernetesclientset "k8s.io/client-go/kubernetes"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
// AddControllersToManager adds all controller-manager controllers to the given manager.
func AddControllersToManager(mgr manager.Manager, cfg *config.ControllerManagerConfiguration) error {
kubernetesClient, err := kubernetesclientset.NewForConfig(mgr.GetConfig())
if err != nil {
return fmt.Errorf("failed creating Kubernetes client: %w", err)
}
if err := (&bastion.Reconciler{
Config: *cfg.Controllers.Bastion,
Clock: clock.RealClock{},
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding Bastion controller: %w", err)
}
if err := (&certificatesigningrequest.Reconciler{
CertificatesClient: kubernetesClient.CertificatesV1().CertificateSigningRequests(),
Config: *cfg.Controllers.CertificateSigningRequest,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding CertificateSigningRequest controller: %w", err)
}
if err := (&cloudprofile.Reconciler{
Config: *cfg.Controllers.CloudProfile,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding CloudProfile controller: %w", err)
}
if err := (&controllerdeployment.Reconciler{
Config: *cfg.Controllers.ControllerDeployment,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding ControllerDeployment controller: %w", err)
}
if err := controllerregistration.AddToManager(mgr, *cfg); err != nil {
return fmt.Errorf("failed adding ControllerRegistration controller: %w", err)
}
if config := cfg.Controllers.Event; config != nil {
if err := (&event.Reconciler{
Config: *config,
Clock: clock.RealClock{},
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding Event controller: %w", err)
}
}
if err := (&exposureclass.Reconciler{
Config: *cfg.Controllers.ExposureClass,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding ExposureClass controller: %w", err)
}
if err := (&managedseedset.Reconciler{
Config: *cfg.Controllers.ManagedSeedSet,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding ManagedSeedSet controller: %w", err)
}
if err := project.AddToManager(mgr, *cfg); err != nil {
return fmt.Errorf("failed adding Project controller: %w", err)
}
if err := ("a.Reconciler{
Config: *cfg.Controllers.Quota,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding Quota controller: %w", err)
}
if err := (&secretbinding.Reconciler{
Config: *cfg.Controllers.SecretBinding,
}).AddToManager(mgr); err != nil {
return fmt.Errorf("failed adding SecretBinding controller: %w", err)
}
if err := seed.AddToManager(mgr, *cfg); err != nil {
return fmt.Errorf("failed adding Seed controller: %w", err)
}
if err := shoot.AddToManager(mgr, *cfg); err != nil {
return fmt.Errorf("failed adding Shoot controller: %w", err)
}
return nil
}