-
Notifications
You must be signed in to change notification settings - Fork 344
/
collector.go
166 lines (149 loc) · 4.61 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package deployment
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1"
"github.com/jaegertracing/jaeger-operator/pkg/config/sampling"
"github.com/jaegertracing/jaeger-operator/pkg/service"
"github.com/jaegertracing/jaeger-operator/pkg/storage"
"github.com/jaegertracing/jaeger-operator/pkg/util"
)
// Collector builds pods for jaegertracing/jaeger-collector
type Collector struct {
jaeger *v1alpha1.Jaeger
}
// NewCollector builds a new Collector struct based on the given spec
func NewCollector(jaeger *v1alpha1.Jaeger) *Collector {
if jaeger.Spec.Collector.Size <= 0 {
jaeger.Spec.Collector.Size = 1
}
if jaeger.Spec.Collector.Image == "" {
jaeger.Spec.Collector.Image = fmt.Sprintf("%s:%s", viper.GetString("jaeger-collector-image"), viper.GetString("jaeger-version"))
}
return &Collector{jaeger: jaeger}
}
// Get returns a collector pod
func (c *Collector) Get() *appsv1.Deployment {
logrus.Debugf("Assembling a collector deployment for %v", c.jaeger)
selector := c.selector()
trueVar := true
replicas := int32(c.jaeger.Spec.Collector.Size)
baseCommonSpec := v1alpha1.JaegerCommonSpec{
Annotations: map[string]string{
"prometheus.io/scrape": "true",
"prometheus.io/port": "14268",
"sidecar.istio.io/inject": "false",
},
}
commonSpec := util.Merge([]v1alpha1.JaegerCommonSpec{c.jaeger.Spec.Collector.JaegerCommonSpec, c.jaeger.Spec.JaegerCommonSpec, baseCommonSpec})
var envFromSource []v1.EnvFromSource
if len(c.jaeger.Spec.Storage.SecretName) > 0 {
envFromSource = append(envFromSource, v1.EnvFromSource{
SecretRef: &v1.SecretEnvSource{
LocalObjectReference: v1.LocalObjectReference{
Name: c.jaeger.Spec.Storage.SecretName,
},
},
})
}
storageType := c.jaeger.Spec.Storage.Type
// If ingester options have been defined, then change storage type
// to Kafka, and the storage options will be used in the Ingester instead
if len(c.jaeger.Spec.Ingester.Options.Map()) > 0 {
storageType = "kafka"
}
options := allArgs(c.jaeger.Spec.Collector.Options,
c.jaeger.Spec.Storage.Options.Filter(storage.OptionsPrefix(storageType)),
c.jaeger.Spec.Ingester.Options.Filter(storage.OptionsPrefix(storageType)))
sampling.Update(c.jaeger, commonSpec, &options)
return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-collector", c.jaeger.Name),
Namespace: c.jaeger.Namespace,
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
APIVersion: c.jaeger.APIVersion,
Kind: c.jaeger.Kind,
Name: c.jaeger.Name,
UID: c.jaeger.UID,
Controller: &trueVar,
},
},
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: selector,
},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: selector,
Annotations: commonSpec.Annotations,
},
Spec: v1.PodSpec{
Containers: []v1.Container{{
Image: c.jaeger.Spec.Collector.Image,
Name: "jaeger-collector",
Args: options,
Env: []v1.EnvVar{
v1.EnvVar{
Name: "SPAN_STORAGE_TYPE",
Value: storageType,
},
v1.EnvVar{
Name: "COLLECTOR_ZIPKIN_HTTP_PORT",
Value: "9411",
},
},
VolumeMounts: commonSpec.VolumeMounts,
EnvFrom: envFromSource,
Ports: []v1.ContainerPort{
{
ContainerPort: 9411,
Name: "zipkin",
},
{
ContainerPort: 14267,
Name: "c-tchan-trft", // for collector
},
{
ContainerPort: 14268,
Name: "c-binary-trft",
},
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
HTTPGet: &v1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(14269),
},
},
InitialDelaySeconds: 1,
},
Resources: commonSpec.Resources,
}},
Volumes: commonSpec.Volumes,
},
},
},
}
}
// Services returns a list of services to be deployed along with the all-in-one deployment
func (c *Collector) Services() []*v1.Service {
selector := c.selector()
return []*v1.Service{
service.NewCollectorService(c.jaeger, selector),
}
}
func (c *Collector) selector() map[string]string {
return map[string]string{"app": "jaeger", "jaeger": c.jaeger.Name, "jaeger-component": "collector"}
}