-
Notifications
You must be signed in to change notification settings - Fork 344
/
collector.go
97 lines (87 loc) · 2.71 KB
/
collector.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
package service
import (
"fmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/util"
)
// NewCollectorServices returns a new Kubernetes service for Jaeger Collector backed by the pods matching the selector
func NewCollectorServices(jaeger *v1.Jaeger, selector map[string]string) []*corev1.Service {
return []*corev1.Service{
headlessCollectorService(jaeger, selector),
clusteripCollectorService(jaeger, selector),
}
}
func headlessCollectorService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Service {
svc := collectorService(jaeger, selector)
svc.Name = GetNameForHeadlessCollectorService(jaeger)
svc.Annotations = map[string]string{
"prometheus.io/scrape": "false",
}
svc.Spec.ClusterIP = "None"
return svc
}
func clusteripCollectorService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Service {
return collectorService(jaeger, selector)
}
func collectorService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Service {
trueVar := true
return &corev1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: GetNameForCollectorService(jaeger),
Namespace: jaeger.Namespace,
Labels: map[string]string{
"app": "jaeger",
"app.kubernetes.io/name": GetNameForCollectorService(jaeger),
"app.kubernetes.io/instance": jaeger.Name,
"app.kubernetes.io/component": "service-collector",
"app.kubernetes.io/part-of": "jaeger",
"app.kubernetes.io/managed-by": "jaeger-operator",
},
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
APIVersion: jaeger.APIVersion,
Kind: jaeger.Kind,
Name: jaeger.Name,
UID: jaeger.UID,
Controller: &trueVar,
},
},
},
Spec: corev1.ServiceSpec{
Selector: selector,
ClusterIP: "",
Ports: []corev1.ServicePort{
{
Name: "zipkin",
Port: 9411,
},
{
Name: "grpc",
Port: 14250,
},
{
Name: "c-tchan-trft",
Port: 14267,
},
{
Name: "c-binary-trft",
Port: 14268,
},
},
},
}
}
// GetNameForCollectorService returns the service name for the collector in this Jaeger instance
func GetNameForCollectorService(jaeger *v1.Jaeger) string {
return util.DNSName(fmt.Sprintf("%s-collector", jaeger.Name))
}
// GetNameForHeadlessCollectorService returns the headless service name for the collector in this Jaeger instance
func GetNameForHeadlessCollectorService(jaeger *v1.Jaeger) string {
return util.DNSName(fmt.Sprintf("%s-collector-headless", jaeger.Name))
}