-
Notifications
You must be signed in to change notification settings - Fork 344
/
query.go
131 lines (118 loc) · 3.39 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
package deployment
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
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/ingress"
"github.com/jaegertracing/jaeger-operator/pkg/service"
)
// Query builds pods for jaegertracing/jaeger-query
type Query struct {
jaeger *v1alpha1.Jaeger
}
// NewQuery builds a new Query struct based on the given spec
func NewQuery(jaeger *v1alpha1.Jaeger) *Query {
if jaeger.Spec.Query.Size <= 0 {
jaeger.Spec.Query.Size = 1
}
if jaeger.Spec.Query.Image == "" {
jaeger.Spec.Query.Image = fmt.Sprintf("%s:%s", viper.GetString("jaeger-query-image"), viper.GetString("jaeger-version"))
}
return &Query{jaeger: jaeger}
}
// Get returns a deployment specification for the current instance
func (q *Query) Get() *appsv1.Deployment {
logrus.Debug("Assembling a query deployment")
selector := q.selector()
trueVar := true
replicas := int32(q.jaeger.Spec.Query.Size)
annotations := map[string]string{
"prometheus.io/scrape": "true",
"prometheus.io/port": "16686",
}
return &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,
OwnerReferences: []metav1.OwnerReference{
metav1.OwnerReference{
APIVersion: q.jaeger.APIVersion,
Kind: q.jaeger.Kind,
Name: q.jaeger.Name,
UID: q.jaeger.UID,
Controller: &trueVar,
},
},
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: selector,
},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: selector,
Annotations: annotations,
},
Spec: v1.PodSpec{
Containers: []v1.Container{{
Image: q.jaeger.Spec.Query.Image,
Name: "jaeger-query",
Args: allArgs(q.jaeger.Spec.Query.Options, q.jaeger.Spec.Storage.Options),
Env: []v1.EnvVar{
v1.EnvVar{
Name: "SPAN_STORAGE_TYPE",
Value: q.jaeger.Spec.Storage.Type,
},
},
Ports: []v1.ContainerPort{
{
ContainerPort: 16686,
Name: "query",
},
},
ReadinessProbe: &v1.Probe{
Handler: v1.Handler{
HTTPGet: &v1.HTTPGetAction{
Path: "/",
Port: intstr.FromInt(16687),
},
},
InitialDelaySeconds: 5,
},
},
},
},
},
},
}
}
// Services returns a list of services to be deployed along with the query deployment
func (q *Query) Services() []*v1.Service {
selector := q.selector()
return []*v1.Service{
service.NewQueryService(q.jaeger, selector),
}
}
// Ingresses returns a list of ingress rules to be deployed along with the all-in-one deployment
func (q *Query) Ingresses() []*v1beta1.Ingress {
if q.jaeger.Spec.Query.Ingress.Enabled == nil || *q.jaeger.Spec.Query.Ingress.Enabled == true {
return []*v1beta1.Ingress{
ingress.NewQueryIngress(q.jaeger),
}
}
return []*v1beta1.Ingress{}
}
func (q *Query) selector() map[string]string {
return map[string]string{"app": "jaeger", "jaeger": q.jaeger.Name, "jaeger-component": "query"}
}