forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.go
45 lines (40 loc) · 1.8 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
package servicemonitor
import (
"context"
util "github.com/rancher/rancher/pkg/controllers/user/workload"
"github.com/rancher/types/apis/core/v1"
rmonitoringv1 "github.com/rancher/types/apis/monitoring.coreos.com/v1"
"github.com/rancher/types/config"
)
const (
creatorIDAnnotation = "field.cattle.io/creatorId"
metricsAnnotation = "field.cattle.io/workloadMetrics"
metricsServiceLabel = "cattle.io/metrics"
metricsServiceSuffix = "-metrics"
servicesAnnotation = "field.cattle.io/serviceIDs"
)
/*
The MetricsServiceController maintains the relation between workload, service monitor and service.
The service monitor will create services that point to workloads or pods with selector. The service monitor
owns those service and should delete with the object.
*/
type MetricsServiceController struct {
serviceLister v1.ServiceLister
services v1.ServiceInterface
smLister rmonitoringv1.ServiceMonitorLister
smClient rmonitoringv1.ServiceMonitorInterface
workloadLister util.CommonController
}
func Register(ctx context.Context, workload *config.UserOnlyContext) {
c := &MetricsServiceController{
serviceLister: workload.Core.Services("").Controller().Lister(),
services: workload.Core.Services(""),
smLister: workload.Monitoring.ServiceMonitors("").Controller().Lister(),
smClient: workload.Monitoring.ServiceMonitors(""),
workloadLister: util.NewWorkloadController(ctx, workload, nil),
}
util.NewWorkloadController(ctx, workload, c.createService)
workload.Core.Services("").Controller().AddHandler(ctx, "workloadMetrics", c.ensureService)
workload.Monitoring.ServiceMonitors("").Controller().AddHandler(ctx, "ensureServiceMetrics", c.ensureServiceMonitor)
workload.Monitoring.ServiceMonitors("").Controller().AddHandler(ctx, "workloadMetrics", c.syncServiceMonitor)
}