-
Notifications
You must be signed in to change notification settings - Fork 3k
/
controllers.go
139 lines (123 loc) · 5.45 KB
/
controllers.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
package user
import (
"context"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
"github.com/rancher/norman/store/crd"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/controllers/management/compose/common"
"github.com/rancher/rancher/pkg/controllers/user/alert"
"github.com/rancher/rancher/pkg/controllers/user/approuter"
"github.com/rancher/rancher/pkg/controllers/user/certsexpiration"
"github.com/rancher/rancher/pkg/controllers/user/clusterauthtoken"
"github.com/rancher/rancher/pkg/controllers/user/dnsrecord"
"github.com/rancher/rancher/pkg/controllers/user/endpoints"
"github.com/rancher/rancher/pkg/controllers/user/externalservice"
"github.com/rancher/rancher/pkg/controllers/user/globaldns"
"github.com/rancher/rancher/pkg/controllers/user/healthsyncer"
"github.com/rancher/rancher/pkg/controllers/user/helm"
"github.com/rancher/rancher/pkg/controllers/user/ingress"
"github.com/rancher/rancher/pkg/controllers/user/ingresshostgen"
"github.com/rancher/rancher/pkg/controllers/user/logging"
"github.com/rancher/rancher/pkg/controllers/user/monitoring"
"github.com/rancher/rancher/pkg/controllers/user/networkpolicy"
"github.com/rancher/rancher/pkg/controllers/user/noderemove"
"github.com/rancher/rancher/pkg/controllers/user/nodesyncer"
"github.com/rancher/rancher/pkg/controllers/user/nslabels"
"github.com/rancher/rancher/pkg/controllers/user/pipeline"
"github.com/rancher/rancher/pkg/controllers/user/rbac"
"github.com/rancher/rancher/pkg/controllers/user/rbac/podsecuritypolicy"
"github.com/rancher/rancher/pkg/controllers/user/resourcequota"
"github.com/rancher/rancher/pkg/controllers/user/secret"
"github.com/rancher/rancher/pkg/controllers/user/servicemonitor"
"github.com/rancher/rancher/pkg/controllers/user/systemimage"
"github.com/rancher/rancher/pkg/controllers/user/targetworkloadservice"
"github.com/rancher/rancher/pkg/controllers/user/workload"
pkgmonitoring "github.com/rancher/rancher/pkg/monitoring"
managementv3 "github.com/rancher/types/apis/management.cattle.io/v3"
projectclient "github.com/rancher/types/client/project/v3"
"github.com/rancher/types/config"
"github.com/rancher/types/factory"
)
func Register(ctx context.Context, cluster *config.UserContext, clusterRec *managementv3.Cluster, kubeConfigGetter common.KubeConfigGetter, clusterManager healthsyncer.ClusterControllerLifecycle) error {
rbac.Register(ctx, cluster)
healthsyncer.Register(ctx, cluster, clusterManager)
helm.Register(ctx, cluster, kubeConfigGetter)
logging.Register(ctx, cluster)
networkpolicy.Register(ctx, cluster)
noderemove.Register(ctx, cluster)
nodesyncer.Register(ctx, cluster, kubeConfigGetter)
pipeline.Register(ctx, cluster)
podsecuritypolicy.RegisterCluster(ctx, cluster)
podsecuritypolicy.RegisterBindings(ctx, cluster)
podsecuritypolicy.RegisterNamespace(ctx, cluster)
podsecuritypolicy.RegisterServiceAccount(ctx, cluster)
podsecuritypolicy.RegisterTemplate(ctx, cluster)
secret.Register(ctx, cluster)
systemimage.Register(ctx, cluster)
endpoints.Register(ctx, cluster)
approuter.Register(ctx, cluster)
resourcequota.Register(ctx, cluster)
globaldns.Register(ctx, cluster)
alert.Register(ctx, cluster)
monitoring.Register(ctx, cluster)
certsexpiration.Register(ctx, cluster)
if clusterRec.Spec.LocalClusterAuthEndpoint.Enabled {
err := clusterauthtoken.CRDSetup(ctx, cluster.UserOnlyContext())
if err != nil {
return err
}
clusterauthtoken.Register(ctx, cluster)
}
if clusterRec.Spec.Internal {
err := RegisterUserOnly(ctx, cluster.UserOnlyContext())
if err != nil {
return err
}
}
return nil
}
func RegisterFollower(ctx context.Context, cluster *config.UserContext, kubeConfigGetter common.KubeConfigGetter, clusterManager healthsyncer.ClusterControllerLifecycle) error {
cluster.Core.Namespaces("").Controller()
cluster.Core.Services("").Controller()
cluster.RBAC.ClusterRoleBindings("").Controller()
cluster.RBAC.RoleBindings("").Controller()
cluster.Core.Endpoints("").Controller()
return nil
}
func RegisterUserOnly(ctx context.Context, cluster *config.UserOnlyContext) error {
if err := createUserClusterCRDs(ctx, cluster); err != nil {
return err
}
dnsrecord.Register(ctx, cluster)
externalservice.Register(ctx, cluster)
ingress.Register(ctx, cluster)
ingresshostgen.Register(ctx, cluster)
nslabels.Register(ctx, cluster)
targetworkloadservice.Register(ctx, cluster)
workload.Register(ctx, cluster)
servicemonitor.Register(ctx, cluster)
monitoring.RegisterAgent(ctx, cluster)
return nil
}
func createUserClusterCRDs(ctx context.Context, c *config.UserOnlyContext) error {
overrided := struct {
types.Namespaced
}{}
schemas := factory.Schemas(&pkgmonitoring.APIVersion).
MustImport(&pkgmonitoring.APIVersion, monitoringv1.Prometheus{}, overrided).
MustImport(&pkgmonitoring.APIVersion, monitoringv1.PrometheusRule{}, overrided).
MustImport(&pkgmonitoring.APIVersion, monitoringv1.ServiceMonitor{}, overrided).
MustImport(&pkgmonitoring.APIVersion, monitoringv1.Alertmanager{}, overrided)
f, err := crd.NewFactoryFromClient(c.RESTConfig)
if err != nil {
return err
}
_, err = f.CreateCRDs(ctx, config.UserStorageContext,
schemas.Schema(&pkgmonitoring.APIVersion, projectclient.PrometheusType),
schemas.Schema(&pkgmonitoring.APIVersion, projectclient.PrometheusRuleType),
schemas.Schema(&pkgmonitoring.APIVersion, projectclient.AlertmanagerType),
schemas.Schema(&pkgmonitoring.APIVersion, projectclient.ServiceMonitorType),
)
f.BatchWait()
return err
}