forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.go
93 lines (80 loc) · 4.02 KB
/
register.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
package monitoring
import (
"context"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
)
// Register initializes the controllers and registers
func Register(ctx context.Context, agentContext *config.UserContext) {
clusterName := agentContext.ClusterName
logrus.Infof("Registering monitoring for cluster %q", clusterName)
cattleContext := agentContext.Management
mgmtContext := cattleContext.Management
cattleClustersClient := mgmtContext.Clusters(metav1.NamespaceAll)
cattleProjectsClient := mgmtContext.Projects(clusterName)
// app handler
ah := &appHandler{
cattleAppClient: cattleContext.Project.Apps(metav1.NamespaceAll),
cattleProjectClient: cattleProjectsClient,
cattleSecretClient: cattleContext.Core.Secrets(metav1.NamespaceAll),
cattleTemplateVersionClient: mgmtContext.CatalogTemplateVersions(metav1.NamespaceAll),
cattleClusterGraphClient: mgmtContext.ClusterMonitorGraphs(metav1.NamespaceAll),
cattleProjectGraphClient: mgmtContext.ProjectMonitorGraphs(metav1.NamespaceAll),
cattleMonitorMetricClient: mgmtContext.MonitorMetrics(metav1.NamespaceAll),
agentDeploymentClient: agentContext.Apps.Deployments(metav1.NamespaceAll),
agentDaemonSetClient: agentContext.Apps.DaemonSets(metav1.NamespaceAll),
agentStatefulSetClient: agentContext.Apps.StatefulSets(metav1.NamespaceAll),
agentServiceAccountClient: agentContext.Core.ServiceAccounts(metav1.NamespaceAll),
agentSecretClient: agentContext.Core.Secrets(metav1.NamespaceAll),
agentNodeClient: agentContext.Core.Nodes(metav1.NamespaceAll),
agentNamespaceClient: agentContext.Core.Namespaces(metav1.NamespaceAll),
}
// operator handler
oh := &operatorHandler{
clusterName: clusterName,
cattleClusterClient: cattleClustersClient,
app: ah,
}
cattleClustersClient.AddHandler(ctx, "prometheus-operator-handler", oh.syncCluster)
cattleProjectsClient.Controller().AddClusterScopedHandler(ctx, "prometheus-operator-handler", clusterName, oh.syncProject)
// cluster handler
ch := &clusterHandler{
clusterName: clusterName,
cattleClustersClient: cattleClustersClient,
app: ah,
}
cattleClustersClient.AddHandler(ctx, "cluster-monitoring-handler", ch.sync)
// project handler
ph := &projectHandler{
clusterName: clusterName,
cattleClusterClient: cattleClustersClient,
cattleProjectClient: cattleProjectsClient,
app: ah,
}
cattleProjectsClient.Controller().AddClusterScopedHandler(ctx, "project-monitoring-handler", clusterName, ph.sync)
}
func RegisterAgent(ctx context.Context, agentContext *config.UserOnlyContext) {
cp := &ControlPlaneEndpointController{
Endpoints: agentContext.Core.Endpoints("cattle-prometheus"),
EndpointLister: agentContext.Core.Endpoints("cattle-prometheus").Controller().Lister(),
EndpointsController: agentContext.Core.Endpoints("cattle-prometheus").Controller(),
NodeLister: agentContext.Core.Nodes("").Controller().Lister(),
ServiceLister: agentContext.Core.Services("cattle-prometheus").Controller().Lister(),
}
agentContext.Core.Nodes("").AddHandler(ctx, "control-plane-endpoint", cp.sync)
agentContext.Core.Endpoints("cattle-prometheus").AddHandler(ctx, "control-plane-endpoint", cp.syncEndpoints)
promIndexes := cache.Indexers{
promByMemberNamespaceIndex: promsByMemberNamespace,
}
promInformer := agentContext.Monitoring.Prometheuses("").Controller().Informer()
promInformer.AddIndexers(promIndexes)
cr := ConfigRefreshHandler{
prometheusClient: agentContext.Monitoring.Prometheuses(""),
nsLister: agentContext.Core.Namespaces("").Controller().Lister(),
prometheusIndexer: promInformer.GetIndexer(),
}
agentContext.Core.Namespaces("").AddHandler(ctx, "project-monitoring-config-refresh", cr.syncNamespace)
agentContext.Monitoring.Prometheuses("").AddHandler(ctx, "project-monitoring-config-refresh", cr.syncPrometheus)
}