forked from grafana/grafana-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafanaAlertService.go
57 lines (51 loc) · 1.38 KB
/
grafanaAlertService.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
package model
import (
"github.com/grafana-operator/grafana-operator/v4/api/integreatly/v1alpha1"
"github.com/grafana-operator/grafana-operator/v4/controllers/constants"
v1 "k8s.io/api/core/v1"
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func getAlertServiceName() string {
return "grafana-alert"
}
func getAlertServiceLabels(cr *v1alpha1.Grafana) map[string]string {
if cr.Spec.Service == nil {
return nil
}
return cr.Spec.Service.Labels
}
func GrafanaAlertService(cr *v1alpha1.Grafana) *v1.Service {
return &v1.Service{
ObjectMeta: v12.ObjectMeta{
Name: getAlertServiceName(),
Namespace: cr.Namespace,
Labels: getAlertServiceLabels(cr),
},
Spec: v1.ServiceSpec{
ClusterIP: "None",
Ports: []v1.ServicePort{
{
Name: "grafana-alert",
Port: 9094,
TargetPort: intstr.FromString("grafana-alert"),
},
},
Selector: map[string]string{
"app": constants.GrafanaPodLabel,
},
Type: v1.ServiceTypeClusterIP,
},
}
}
func GrafanaAlertServiceReconciled(cr *v1alpha1.Grafana, currentState *v1.Service) *v1.Service {
reconciled := currentState.DeepCopy()
return reconciled
}
func GrafanaAlertServiceSelector(cr *v1alpha1.Grafana) client.ObjectKey {
return client.ObjectKey{
Namespace: cr.Namespace,
Name: getAlertServiceName(),
}
}