diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index 7771912ebf..a95e56b16c 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -113,6 +113,27 @@ func (a *AllInOne) Get() *appsv1.Deployment { strategy = *a.jaeger.Spec.AllInOne.Strategy } + envVars := []corev1.EnvVar{ + { + Name: "SPAN_STORAGE_TYPE", + Value: string(a.jaeger.Spec.Storage.Type), + }, + { + Name: "METRICS_STORAGE_TYPE", + Value: string(a.jaeger.Spec.AllInOne.MetricsStorage.Type), + }, + { + Name: "COLLECTOR_ZIPKIN_HOST_PORT", + Value: ":9411", + }, + { + Name: "JAEGER_DISABLED", + Value: strconv.FormatBool(jaegerDisabled), + }, + } + + envVars = updateOTLPEnvVars(envVars, options) + return &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ APIVersion: "apps/v1", @@ -144,27 +165,10 @@ func (a *AllInOne) Get() *appsv1.Deployment { Spec: corev1.PodSpec{ ImagePullSecrets: commonSpec.ImagePullSecrets, Containers: []corev1.Container{{ - Image: util.ImageName(a.jaeger.Spec.AllInOne.Image, "jaeger-all-in-one-image"), - Name: "jaeger", - Args: options, - Env: []corev1.EnvVar{ - { - Name: "SPAN_STORAGE_TYPE", - Value: string(a.jaeger.Spec.Storage.Type), - }, - { - Name: "METRICS_STORAGE_TYPE", - Value: string(a.jaeger.Spec.AllInOne.MetricsStorage.Type), - }, - { - Name: "COLLECTOR_ZIPKIN_HOST_PORT", - Value: ":9411", - }, - { - Name: "JAEGER_DISABLED", - Value: strconv.FormatBool(jaegerDisabled), - }, - }, + Image: util.ImageName(a.jaeger.Spec.AllInOne.Image, "jaeger-all-in-one-image"), + Name: "jaeger", + Args: options, + Env: envVars, VolumeMounts: commonSpec.VolumeMounts, EnvFrom: envFromSource, Ports: []corev1.ContainerPort{ @@ -211,6 +215,14 @@ func (a *AllInOne) Get() *appsv1.Deployment { ContainerPort: 14250, Name: "grpc", }, + { + ContainerPort: 4317, + Name: "otlp-grpc", + }, + { + ContainerPort: 4318, + Name: "otlp-http", + }, }, LivenessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ diff --git a/pkg/deployment/all_in_one_test.go b/pkg/deployment/all_in_one_test.go index d475db260c..1e330d26f3 100644 --- a/pkg/deployment/all_in_one_test.go +++ b/pkg/deployment/all_in_one_test.go @@ -49,6 +49,10 @@ func TestDefaultAllInOneImage(t *testing.T) { Name: "JAEGER_DISABLED", Value: "false", }, + { + Name: "COLLECTOR_OTLP_ENABLED", + Value: "true", + }, } assert.Equal(t, envvars, d.Spec.Template.Spec.Containers[0].Env) } diff --git a/pkg/deployment/collector.go b/pkg/deployment/collector.go index 446ee31297..28f50cdc98 100644 --- a/pkg/deployment/collector.go +++ b/pkg/deployment/collector.go @@ -111,6 +111,19 @@ func (c *Collector) Get() *appsv1.Deployment { strategy = *c.jaeger.Spec.Collector.Strategy } + envVars := []corev1.EnvVar{ + { + Name: "SPAN_STORAGE_TYPE", + Value: string(storageType), + }, + { + Name: "COLLECTOR_ZIPKIN_HOST_PORT", + Value: ":9411", + }, + } + + envVars = updateOTLPEnvVars(envVars, options) + return &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ APIVersion: "apps/v1", @@ -143,19 +156,10 @@ func (c *Collector) Get() *appsv1.Deployment { Spec: corev1.PodSpec{ ImagePullSecrets: c.jaeger.Spec.ImagePullSecrets, Containers: []corev1.Container{{ - Image: util.ImageName(c.jaeger.Spec.Collector.Image, "jaeger-collector-image"), - Name: "jaeger-collector", - Args: options, - Env: []corev1.EnvVar{ - { - Name: "SPAN_STORAGE_TYPE", - Value: string(storageType), - }, - { - Name: "COLLECTOR_ZIPKIN_HOST_PORT", - Value: ":9411", - }, - }, + Image: util.ImageName(c.jaeger.Spec.Collector.Image, "jaeger-collector-image"), + Name: "jaeger-collector", + Args: options, + Env: envVars, VolumeMounts: commonSpec.VolumeMounts, EnvFrom: envFromSource, Ports: []corev1.ContainerPort{ @@ -179,6 +183,14 @@ func (c *Collector) Get() *appsv1.Deployment { ContainerPort: 14250, Name: "grpc", }, + { + ContainerPort: 4317, + Name: "otlp-grpc", + }, + { + ContainerPort: 4318, + Name: "otlp-http", + }, }, LivenessProbe: &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ diff --git a/pkg/deployment/collector_test.go b/pkg/deployment/collector_test.go index 2a69dc2e5f..0c297d68ae 100644 --- a/pkg/deployment/collector_test.go +++ b/pkg/deployment/collector_test.go @@ -86,6 +86,10 @@ func TestDefaultCollectorImage(t *testing.T) { Name: "COLLECTOR_ZIPKIN_HOST_PORT", Value: ":9411", }, + { + Name: "COLLECTOR_OTLP_ENABLED", + Value: "true", + }, } assert.Equal(t, envvars, containers[0].Env) } @@ -379,6 +383,10 @@ func TestCollectorWithDirectStorageType(t *testing.T) { Name: "COLLECTOR_ZIPKIN_HOST_PORT", Value: ":9411", }, + { + Name: "COLLECTOR_OTLP_ENABLED", + Value: "true", + }, } assert.Equal(t, envvars, dep.Spec.Template.Spec.Containers[0].Env) assert.Len(t, dep.Spec.Template.Spec.Containers[0].Args, 2) @@ -418,6 +426,10 @@ func TestCollectorWithKafkaStorageType(t *testing.T) { Name: "COLLECTOR_ZIPKIN_HOST_PORT", Value: ":9411", }, + { + Name: "COLLECTOR_OTLP_ENABLED", + Value: "true", + }, } assert.Equal(t, envvars, dep.Spec.Template.Spec.Containers[0].Env) assert.Len(t, dep.Spec.Template.Spec.Containers[0].Args, 3) @@ -453,6 +465,10 @@ func TestCollectorWithIngesterNoOptionsStorageType(t *testing.T) { Name: "COLLECTOR_ZIPKIN_HOST_PORT", Value: ":9411", }, + { + Name: "COLLECTOR_OTLP_ENABLED", + Value: "true", + }, } assert.Equal(t, envvars, dep.Spec.Template.Spec.Containers[0].Env) assert.Len(t, dep.Spec.Template.Spec.Containers[0].Args, 2) diff --git a/pkg/deployment/otlp.go b/pkg/deployment/otlp.go new file mode 100644 index 0000000000..5a90bd15cd --- /dev/null +++ b/pkg/deployment/otlp.go @@ -0,0 +1,29 @@ +package deployment + +import ( + "github.com/jaegertracing/jaeger-operator/pkg/util" + corev1 "k8s.io/api/core/v1" +) + +const collectorOTLPEnvVarName = "COLLECTOR_OTLP_ENABLED" + +func updateOTLPEnvVars(envs []corev1.EnvVar, options []string) []corev1.EnvVar { + noExplicitFlag := len(util.FindItem("--collector.otlp.enabled=", options)) == 0 + noExplicitEnvVar := findEnvVar(envs, collectorOTLPEnvVarName) == nil + if noExplicitFlag && noExplicitEnvVar { + envs = append(envs, corev1.EnvVar{ + Name: collectorOTLPEnvVarName, + Value: "true", + }) + } + return envs +} + +func findEnvVar(envs []corev1.EnvVar, name string) *corev1.EnvVar { + for _, env := range envs { + if env.Name == name { + return &env + } + } + return nil +} diff --git a/pkg/service/collector.go b/pkg/service/collector.go index 6155719942..621bc257b1 100644 --- a/pkg/service/collector.go +++ b/pkg/service/collector.go @@ -76,6 +76,14 @@ func collectorService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Ser Name: "http-c-binary-trft", Port: 14268, }, + { + Name: "otlp-grpc", + Port: 4317, + }, + { + Name: "otlp-http", + Port: 4318, + }, }, }, }