Skip to content

Commit

Permalink
Merge branch 'master' into instrument-op
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvp8510 authored Jun 25, 2021
2 parents b0a3732 + b98361c commit 083af9a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
69 changes: 40 additions & 29 deletions pkg/storage/cassandra_dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,56 @@ func cassandraDeps(jaeger *v1.Jaeger) []batchv1.Job {
jaeger.Spec.Storage.CassandraCreateSchema.Mode = "prod"
}

envVars := []corev1.EnvVar{{
Name: "MODE",
Value: jaeger.Spec.Storage.CassandraCreateSchema.Mode,
}, {
Name: "DATACENTER",
Value: jaeger.Spec.Storage.CassandraCreateSchema.Datacenter,
}}

host := jaeger.Spec.Storage.Options.Map()["cassandra.servers"]
if host == "" {
jaeger.Logger().Info("Cassandra hostname not specified. Using 'cassandra' for the cassandra-create-schema job.")
host = "cassandra" // this is the default in the image
}
envVars = append(envVars, corev1.EnvVar{
Name: "CQLSH_HOST",
Value: host,
})

port := jaeger.Spec.Storage.Options.Map()["cassandra.port"]
if port == "" {
jaeger.Logger().Info("Cassandra port not specified. Using '9042' for the cassandra-create-schema job.")
port = "9042" // this is the default in the image
}
envVars = append(envVars, corev1.EnvVar{
Name: "CQLSH_PORT",
Value: port,
})

keyspace := jaeger.Spec.Storage.Options.Map()["cassandra.keyspace"]
if keyspace == "" {
jaeger.Logger().Info("Cassandra keyspace not specified. Using 'jaeger_v1_test' for the cassandra-create-schema job.")
keyspace = "jaeger_v1_test" // this is default in the image
}

username := jaeger.Spec.Storage.Options.Map()["cassandra.username"]
password := jaeger.Spec.Storage.Options.Map()["cassandra.password"]
envVars = append(envVars, corev1.EnvVar{
Name: "KEYSPACE",
Value: keyspace,
})

envFromSource := util.CreateEnvsFromSecret(jaeger.Spec.Storage.SecretName)
if len(envFromSource) == 0 {
envVars = append(envVars, corev1.EnvVar{
Name: "CASSANDRA_USERNAME",
Value: jaeger.Spec.Storage.Options.Map()["cassandra.username"],
})
envVars = append(envVars, corev1.EnvVar{
Name: "CASSANDRA_PASSWORD",
Value: jaeger.Spec.Storage.Options.Map()["cassandra.password"],
})
}

annotations := map[string]string{
"prometheus.io/scrape": "false",
Expand Down Expand Up @@ -93,6 +123,10 @@ func cassandraDeps(jaeger *v1.Jaeger) []batchv1.Job {
traceTTLSeconds = fmt.Sprintf("%.0f", dur.Seconds())
}
}
envVars = append(envVars, corev1.EnvVar{
Name: "TRACE_TTL",
Value: traceTTLSeconds,
})

if jaeger.Spec.Storage.CassandraCreateSchema.Timeout != "" {
dur, err := time.ParseDuration(jaeger.Spec.Storage.CassandraCreateSchema.Timeout)
Expand Down Expand Up @@ -142,33 +176,10 @@ func cassandraDeps(jaeger *v1.Jaeger) []batchv1.Job {
ActiveDeadlineSeconds: podTimeout,
SecurityContext: jaeger.Spec.SecurityContext,
Containers: []corev1.Container{{
Image: util.ImageName(jaeger.Spec.Storage.CassandraCreateSchema.Image, "jaeger-cassandra-schema-image"),
Name: truncatedName,
Env: []corev1.EnvVar{{
Name: "CQLSH_HOST",
Value: host,
}, {
Name: "CQLSH_PORT",
Value: port,
}, {
Name: "MODE",
Value: jaeger.Spec.Storage.CassandraCreateSchema.Mode,
}, {
Name: "DATACENTER",
Value: jaeger.Spec.Storage.CassandraCreateSchema.Datacenter,
}, {
Name: "TRACE_TTL",
Value: traceTTLSeconds,
}, {
Name: "KEYSPACE",
Value: keyspace,
}, {
Name: "CASSANDRA_USERNAME",
Value: username,
}, {
Name: "CASSANDRA_PASSWORD",
Value: password,
}},
Image: util.ImageName(jaeger.Spec.Storage.CassandraCreateSchema.Image, "jaeger-cassandra-schema-image"),
Name: truncatedName,
Env: envVars,
EnvFrom: envFromSource,
}},
RestartPolicy: corev1.RestartPolicyOnFailure,
},
Expand Down
11 changes: 11 additions & 0 deletions pkg/storage/cassandra_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,14 @@ func TestCassandraCreateSchemaSecurityContext(t *testing.T) {
assert.Len(t, b, 1)
assert.Equal(t, b[0].Spec.Template.Spec.SecurityContext, expectedSecurityContext)
}

func TestCassandraCreateSchemaSecret(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestCassandraCreateSchemaSecret"})
secret := "cassandra-test-secret"
jaeger.Spec.Storage.SecretName = secret

b := cassandraDeps(jaeger)

assert.Len(t, b, 1)
assert.Equal(t, secret, b[0].Spec.Template.Spec.Containers[0].EnvFrom[0].SecretRef.LocalObjectReference.Name)
}

0 comments on commit 083af9a

Please sign in to comment.