-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.go
54 lines (45 loc) · 1.75 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
package monitoring
import (
"context"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// 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
clustersClient := cattleContext.Management.Clusters(metav1.NamespaceAll)
projectsClient := cattleContext.Management.Projects(clusterName)
// app handler
ah := &appHandler{
cattleTemplateVersionsGetter: cattleContext.Management,
cattleProjectsGetter: cattleContext.Management,
cattleAppsGetter: cattleContext.Project,
cattleCoreClient: cattleContext.Core,
agentCoreClient: agentContext.Core,
agentRBACClient: agentContext.RBAC,
agentWorkloadsClient: agentContext.Apps,
}
// cluster handler
ch := &clusterHandler{
ctx: ctx,
clusterName: clusterName,
cattleClustersClient: clustersClient,
app: ah,
clusterGraph: cattleContext.Management.ClusterMonitorGraphs(""),
monitorMetrics: cattleContext.Management.MonitorMetrics(""),
}
clustersClient.AddHandler(ctx, "user-cluster-monitoring", ch.sync)
// project handler
ph := &projectHandler{
ctx: ctx,
clusterName: clusterName,
cattleClustersClient: clustersClient,
cattleProjectsClient: projectsClient,
app: ah,
projectGraph: cattleContext.Management.ProjectMonitorGraphs(""),
}
projectsClient.Controller().AddClusterScopedHandler(ctx, "user-project-monitoring", clusterName, ph.sync)
}