-
Notifications
You must be signed in to change notification settings - Fork 344
/
spark_dependencies.go
196 lines (173 loc) · 6.81 KB
/
spark_dependencies.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
package cronjob
import (
"strconv"
"strings"
"k8s.io/apimachinery/pkg/runtime"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/spf13/viper"
v1 "github.com/jaegertracing/jaeger-operator/apis/v1"
"github.com/jaegertracing/jaeger-operator/pkg/account"
"github.com/jaegertracing/jaeger-operator/pkg/config/ca"
"github.com/jaegertracing/jaeger-operator/pkg/util"
)
var supportedStorageTypes = map[v1.JaegerStorageType]bool{v1.JaegerESStorage: true, v1.JaegerCassandraStorage: true}
// SupportedStorage returns whether the given storage is supported
func SupportedStorage(storage v1.JaegerStorageType) bool {
return supportedStorageTypes[storage]
}
// CreateSparkDependencies creates a new cronjob for the Spark Dependencies task
func CreateSparkDependencies(jaeger *v1.Jaeger) runtime.Object {
logTLSNotSupported(jaeger)
envVars := []corev1.EnvVar{
{Name: "STORAGE", Value: string(jaeger.Spec.Storage.Type)},
{Name: "SPARK_MASTER", Value: jaeger.Spec.Storage.Dependencies.SparkMaster},
{Name: "JAVA_OPTS", Value: jaeger.Spec.Storage.Dependencies.JavaOpts},
}
envVars = append(envVars, getStorageEnvs(jaeger.Spec.Storage)...)
envFromSource := util.CreateEnvsFromSecret(jaeger.Spec.Storage.SecretName)
trueVar := true
one := int32(1)
// cron job names are restricted to 52 chars
name := util.Truncate("%s-spark-dependencies", 52, jaeger.Name)
baseCommonSpec := v1.JaegerCommonSpec{
Annotations: map[string]string{
"prometheus.io/scrape": "false",
"sidecar.istio.io/inject": "false",
"linkerd.io/inject": "disabled",
},
Labels: util.Labels(name, "spark-dependencies", *jaeger),
}
commonSpec := util.Merge([]v1.JaegerCommonSpec{jaeger.Spec.Storage.Dependencies.JaegerCommonSpec, jaeger.Spec.JaegerCommonSpec, baseCommonSpec})
ca.Update(jaeger, commonSpec)
// Cannot use util.ImageName to obtain the correct image, as the spark-dependencies
// image does not get tagged with the jaeger version, so the latest image must
// be used instead.
image := jaeger.Spec.Storage.Dependencies.Image
if image == "" {
// the version is not included, there is only one version - latest
image = viper.GetString("jaeger-spark-dependencies-image")
}
objectMeta := metav1.ObjectMeta{
Name: name,
Namespace: jaeger.Namespace,
Labels: commonSpec.Labels,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: jaeger.APIVersion,
Kind: jaeger.Kind,
Name: jaeger.Name,
UID: jaeger.UID,
Controller: &trueVar,
},
},
}
jobSpec := batchv1.JobSpec{
Parallelism: &one,
BackoffLimit: jaeger.Spec.Storage.Dependencies.BackoffLimit,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: image,
Name: name,
// let spark job use its default values
Env: util.RemoveEmptyVars(envVars),
EnvFrom: envFromSource,
Resources: commonSpec.Resources,
VolumeMounts: jaeger.Spec.Storage.Dependencies.JaegerCommonSpec.VolumeMounts,
},
},
ImagePullSecrets: commonSpec.ImagePullSecrets,
RestartPolicy: corev1.RestartPolicyNever,
Affinity: commonSpec.Affinity,
Tolerations: commonSpec.Tolerations,
SecurityContext: commonSpec.SecurityContext,
ServiceAccountName: account.JaegerServiceAccountFor(jaeger, account.DependenciesComponent),
Volumes: jaeger.Spec.Storage.Dependencies.JaegerCommonSpec.Volumes,
},
ObjectMeta: metav1.ObjectMeta{
Labels: commonSpec.Labels,
Annotations: commonSpec.Annotations,
},
},
}
var o runtime.Object
cronjobsVersion := viper.GetString(v1.FlagCronJobsVersion)
if cronjobsVersion == v1.FlagCronJobsVersionBatchV1Beta1 {
cj := &batchv1beta1.CronJob{
ObjectMeta: objectMeta,
Spec: batchv1beta1.CronJobSpec{
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
Schedule: jaeger.Spec.Storage.Dependencies.Schedule,
SuccessfulJobsHistoryLimit: jaeger.Spec.Storage.Dependencies.SuccessfulJobsHistoryLimit,
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: jobSpec,
},
},
}
o = cj
} else {
cj := &batchv1.CronJob{
ObjectMeta: objectMeta,
Spec: batchv1.CronJobSpec{
ConcurrencyPolicy: batchv1.ForbidConcurrent,
Schedule: jaeger.Spec.Storage.Dependencies.Schedule,
SuccessfulJobsHistoryLimit: jaeger.Spec.Storage.Dependencies.SuccessfulJobsHistoryLimit,
JobTemplate: batchv1.JobTemplateSpec{
Spec: jobSpec,
},
},
}
o = cj
}
return o
}
func getStorageEnvs(s v1.JaegerStorageSpec) []corev1.EnvVar {
sFlagsMap := s.Options.StringMap()
switch s.Type {
case v1.JaegerCassandraStorage:
keyspace := sFlagsMap["cassandra.keyspace"]
if keyspace == "" {
keyspace = "jaeger_v1_test"
}
return []corev1.EnvVar{
{Name: "CASSANDRA_CONTACT_POINTS", Value: sFlagsMap["cassandra.servers"]},
{Name: "CASSANDRA_KEYSPACE", Value: keyspace},
{Name: "CASSANDRA_USERNAME", Value: sFlagsMap["cassandra.username"]},
{Name: "CASSANDRA_PASSWORD", Value: sFlagsMap["cassandra.password"]},
{Name: "CASSANDRA_USE_SSL", Value: sFlagsMap["cassandra.tls"]},
{Name: "CASSANDRA_LOCAL_DC", Value: sFlagsMap["cassandra.local-dc"]},
{Name: "CASSANDRA_CLIENT_AUTH_ENABLED", Value: strconv.FormatBool(s.Dependencies.CassandraClientAuthEnabled)},
}
case v1.JaegerESStorage:
vars := []corev1.EnvVar{
{Name: "ES_NODES", Value: sFlagsMap["es.server-urls"]},
{Name: "ES_INDEX_PREFIX", Value: sFlagsMap["es.index-prefix"]},
{Name: "ES_INDEX_DATE_SEPARATOR", Value: sFlagsMap["es.index-date-separator"]},
{Name: "ES_USERNAME", Value: sFlagsMap["es.username"]},
{Name: "ES_PASSWORD", Value: sFlagsMap["es.password"]},
{Name: "ES_TIME_RANGE", Value: s.Dependencies.ElasticsearchTimeRange},
}
if s.Dependencies.ElasticsearchNodesWanOnly != nil {
vars = append(vars, corev1.EnvVar{Name: "ES_NODES_WAN_ONLY", Value: strconv.FormatBool(*s.Dependencies.ElasticsearchNodesWanOnly)})
}
if s.Dependencies.ElasticsearchClientNodeOnly != nil {
vars = append(vars, corev1.EnvVar{Name: "ES_CLIENT_NODE_ONLY", Value: strconv.FormatBool(*s.Dependencies.ElasticsearchClientNodeOnly)})
}
return vars
default:
return nil
}
}
func logTLSNotSupported(j *v1.Jaeger) {
sFlagsMap := j.Spec.Storage.Options.StringMap()
if strings.EqualFold(sFlagsMap["es.tls.enabled"], "true") || strings.EqualFold(sFlagsMap["es.tls"], "true") {
j.Logger().Warn("Spark dependencies does not support TLS with Elasticsearch, consider disabling dependencies")
}
if strings.EqualFold(sFlagsMap["es.tls.skip-host-verify"], "true") || sFlagsMap["es.tls.ca"] != "" {
j.Logger().Warn("Spark dependencies does not support insecure TLS nor specifying only CA cert, consider disabling dependencies")
}
}