-
Notifications
You must be signed in to change notification settings - Fork 344
/
query.go
245 lines (218 loc) · 7.22 KB
/
query.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package deployment
import (
"fmt"
"sort"
"strconv"
"github.com/operator-framework/operator-lib/proxy"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
v1 "github.com/jaegertracing/jaeger-operator/apis/v1"
"github.com/jaegertracing/jaeger-operator/pkg/account"
"github.com/jaegertracing/jaeger-operator/pkg/config/ca"
configmap "github.com/jaegertracing/jaeger-operator/pkg/config/ui"
"github.com/jaegertracing/jaeger-operator/pkg/service"
"github.com/jaegertracing/jaeger-operator/pkg/storage"
"github.com/jaegertracing/jaeger-operator/pkg/util"
)
// Query builds pods for jaegertracing/jaeger-query
type Query struct {
jaeger *v1.Jaeger
}
// NewQuery builds a new Query struct based on the given spec
func NewQuery(jaeger *v1.Jaeger) *Query {
return &Query{jaeger: jaeger}
}
// Get returns a deployment specification for the current instance
func (q *Query) Get() *appsv1.Deployment {
q.jaeger.Logger().V(-1).Info("Assembling a query deployment")
labels := q.labels()
trueVar := true
falseVar := false
args := q.jaeger.Spec.Query.Options.ToArgs()
adminPort := util.GetAdminPort(args, 16687)
baseCommonSpec := v1.JaegerCommonSpec{
Annotations: map[string]string{
"prometheus.io/scrape": "true",
"prometheus.io/port": strconv.Itoa(int(adminPort)),
"linkerd.io/inject": "disabled",
},
Labels: labels,
}
jaegerDisabled := false
if q.jaeger.Spec.Query.TracingEnabled != nil && !*q.jaeger.Spec.Query.TracingEnabled {
jaegerDisabled = true
} else {
// note that we are explicitly using a string here, not the value from `inject.Annotation`
// this has two reasons:
// 1) as it is, it would cause a circular dependency, so, we'd have to extract that constant to somewhere else
// 2) this specific string is part of the "public API" of the operator: we should not change
// it at will. So, we leave this configured just like any other application would
baseCommonSpec.Annotations["sidecar.jaegertracing.io/inject"] = q.jaeger.Name
}
commonSpec := util.Merge([]v1.JaegerCommonSpec{q.jaeger.Spec.Query.JaegerCommonSpec, q.jaeger.Spec.JaegerCommonSpec, baseCommonSpec})
_, ok := commonSpec.Annotations["sidecar.istio.io/inject"]
if !ok {
commonSpec.Annotations["sidecar.istio.io/inject"] = "false"
}
options := util.AllArgs(q.jaeger.Spec.Query.Options,
q.jaeger.Spec.Storage.Options.Filter(q.jaeger.Spec.Storage.Type.OptionsPrefix()))
configmap.Update(q.jaeger, commonSpec, &options)
ca.Update(q.jaeger, commonSpec)
storage.UpdateGRPCPlugin(q.jaeger, commonSpec)
var envFromSource []corev1.EnvFromSource
if len(q.jaeger.Spec.Storage.SecretName) > 0 {
envFromSource = append(envFromSource, corev1.EnvFromSource{
SecretRef: &corev1.SecretEnvSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: q.jaeger.Spec.Storage.SecretName,
},
},
})
}
// ensure we have a consistent order of the arguments
// see https://github.com/jaegertracing/jaeger-operator/issues/334
sort.Strings(options)
priorityClassName := q.jaeger.Spec.Query.PriorityClassName
strategy := appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
}
if q.jaeger.Spec.Query.Strategy != nil {
strategy = *q.jaeger.Spec.Query.Strategy
}
livenessProbe := &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(int(adminPort)),
},
},
InitialDelaySeconds: 5,
PeriodSeconds: 15,
FailureThreshold: 5,
}
if q.jaeger.Spec.Query.LivenessProbe != nil {
livenessProbe = q.jaeger.Spec.Query.LivenessProbe
}
var nodeSelector map[string]string
if q.jaeger.Spec.Query.NodeSelector != nil {
nodeSelector = q.jaeger.Spec.Query.NodeSelector
}
envVars := []corev1.EnvVar{
{
Name: "SPAN_STORAGE_TYPE",
Value: string(q.jaeger.Spec.Storage.Type),
},
{
Name: "METRICS_STORAGE_TYPE",
Value: string(q.jaeger.Spec.Query.MetricsStorage.Type),
},
{
Name: "JAEGER_DISABLED",
Value: strconv.FormatBool(jaegerDisabled),
},
}
if q.jaeger.Spec.Query.MetricsStorage.Type == "prometheus" {
envVars = append(envVars, corev1.EnvVar{
Name: "PROMETHEUS_SERVER_URL",
Value: q.jaeger.Spec.Query.MetricsStorage.ServerUrl,
})
}
envVars = append(envVars, proxy.ReadProxyVarsFromEnv()...)
deployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-query", q.jaeger.Name),
Namespace: q.jaeger.Namespace,
Labels: commonSpec.Labels,
Annotations: baseCommonSpec.Annotations,
OwnerReferences: []metav1.OwnerReference{{
APIVersion: q.jaeger.APIVersion,
Kind: q.jaeger.Kind,
Name: q.jaeger.Name,
UID: q.jaeger.UID,
Controller: &trueVar,
}},
},
Spec: appsv1.DeploymentSpec{
Replicas: q.jaeger.Spec.Query.Replicas,
Selector: &metav1.LabelSelector{
MatchLabels: commonSpec.Labels,
},
Strategy: strategy,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
},
Spec: corev1.PodSpec{
ImagePullSecrets: q.jaeger.Spec.ImagePullSecrets,
Containers: []corev1.Container{{
Image: util.ImageName(q.jaeger.Spec.Query.Image, "jaeger-query-image"),
Name: "jaeger-query",
Args: options,
Env: envVars,
VolumeMounts: commonSpec.VolumeMounts,
EnvFrom: envFromSource,
Ports: []corev1.ContainerPort{
{
ContainerPort: 16685,
Name: "grpc-query",
},
{
ContainerPort: 16686,
Name: "query",
},
{
ContainerPort: adminPort,
Name: "admin-http",
},
},
LivenessProbe: livenessProbe,
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(int(adminPort)),
},
},
InitialDelaySeconds: 1,
},
Resources: commonSpec.Resources,
ImagePullPolicy: commonSpec.ImagePullPolicy,
SecurityContext: commonSpec.ContainerSecurityContext,
}},
PriorityClassName: priorityClassName,
Volumes: commonSpec.Volumes,
ServiceAccountName: account.JaegerServiceAccountFor(q.jaeger, account.QueryComponent),
Affinity: commonSpec.Affinity,
Tolerations: commonSpec.Tolerations,
SecurityContext: commonSpec.SecurityContext,
EnableServiceLinks: &falseVar,
InitContainers: storage.GetGRPCPluginInitContainers(q.jaeger, commonSpec),
},
},
},
}
if nodeSelector != nil {
deployment.Spec.Template.Spec.NodeSelector = nodeSelector
}
return deployment
}
// Services returns a list of services to be deployed along with the query deployment
func (q *Query) Services() []*corev1.Service {
labels := q.labels()
return []*corev1.Service{
service.NewQueryService(q.jaeger, labels),
}
}
func (q *Query) labels() map[string]string {
return util.Labels(q.name(), "query", *q.jaeger)
}
func (q *Query) name() string {
return fmt.Sprintf("%s-query", q.jaeger.Name)
}