diff --git a/pkg/storage/cassandra_dependencies.go b/pkg/storage/cassandra_dependencies.go index ba9f09f2e2..bb4d0a3b86 100644 --- a/pkg/storage/cassandra_dependencies.go +++ b/pkg/storage/cassandra_dependencies.go @@ -36,17 +36,33 @@ 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 == "" { @@ -54,8 +70,22 @@ func cassandraDeps(jaeger *v1.Jaeger) []batchv1.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", @@ -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) @@ -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, }, diff --git a/pkg/storage/cassandra_dependencies_test.go b/pkg/storage/cassandra_dependencies_test.go index 17d07dd816..c03d0a0099 100644 --- a/pkg/storage/cassandra_dependencies_test.go +++ b/pkg/storage/cassandra_dependencies_test.go @@ -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) +}