diff --git a/deploy/crds/jaegertracing.io_jaegers_crd.yaml b/deploy/crds/jaegertracing.io_jaegers_crd.yaml index 581fd8627..c1ed0fa6a 100644 --- a/deploy/crds/jaegertracing.io_jaegers_crd.yaml +++ b/deploy/crds/jaegertracing.io_jaegers_crd.yaml @@ -1696,6 +1696,8 @@ spec: type: string type: object type: array + tracingEnabled: + type: boolean volumeMounts: items: properties: @@ -5614,6 +5616,8 @@ spec: type: string type: object type: array + tracingEnabled: + type: boolean volumeMounts: items: properties: diff --git a/pkg/apis/jaegertracing/v1/jaeger_types.go b/pkg/apis/jaegertracing/v1/jaeger_types.go index c9d077a01..339c7e682 100644 --- a/pkg/apis/jaegertracing/v1/jaeger_types.go +++ b/pkg/apis/jaegertracing/v1/jaeger_types.go @@ -251,6 +251,12 @@ type JaegerQuerySpec struct { // The default, if omitted, is ClusterIP. // See https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types ServiceType v1.ServiceType `json:"serviceType,omitempty"` + + // +optional + // TracingEnabled if set to false adds the JAEGER_DISABLED environment flag and removes the injected + // agent container from the query component to disable tracing requests to the query service. + // The default, if ommited, is true + TracingEnabled *bool `json:"tracingEnabled,omitempty"` } // JaegerUISpec defines the options to be used to configure the UI @@ -341,6 +347,12 @@ type JaegerAllInOneSpec struct { // +optional JaegerCommonSpec `json:",inline,omitempty"` + + // +optional + // TracingEnabled if set to false adds the JAEGER_DISABLED environment flag and removes the injected + // agent container from the query component to disable tracing requests to the query service. + // The default, if ommited, is true + TracingEnabled *bool `json:"tracingEnabled,omitempty"` } // AutoScaleSpec defines the common elements used for create HPAs diff --git a/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go b/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go index 09284b731..6e637a113 100644 --- a/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go +++ b/pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go @@ -162,6 +162,11 @@ func (in *JaegerAllInOneSpec) DeepCopyInto(out *JaegerAllInOneSpec) { in.Options.DeepCopyInto(&out.Options) in.Config.DeepCopyInto(&out.Config) in.JaegerCommonSpec.DeepCopyInto(&out.JaegerCommonSpec) + if in.TracingEnabled != nil { + in, out := &in.TracingEnabled, &out.TracingEnabled + *out = new(bool) + **out = **in + } return } @@ -540,6 +545,11 @@ func (in *JaegerQuerySpec) DeepCopyInto(out *JaegerQuerySpec) { } in.Options.DeepCopyInto(&out.Options) in.JaegerCommonSpec.DeepCopyInto(&out.JaegerCommonSpec) + if in.TracingEnabled != nil { + in, out := &in.TracingEnabled, &out.TracingEnabled + *out = new(bool) + **out = **in + } return } diff --git a/pkg/apis/jaegertracing/v1/zz_generated.openapi.go b/pkg/apis/jaegertracing/v1/zz_generated.openapi.go index f6382b5cb..d26aba21f 100644 --- a/pkg/apis/jaegertracing/v1/zz_generated.openapi.go +++ b/pkg/apis/jaegertracing/v1/zz_generated.openapi.go @@ -460,6 +460,13 @@ func schema_pkg_apis_jaegertracing_v1_JaegerAllInOneSpec(ref common.ReferenceCal Format: "", }, }, + "tracingEnabled": { + SchemaProps: spec.SchemaProps{ + Description: "TracingEnabled if set to false adds the JAEGER_DISABLED environment flag and removes the injected agent container from the query component to disable tracing requests to the query service. The default, if ommited, is true", + Type: []string{"boolean"}, + Format: "", + }, + }, }, }, }, @@ -1673,6 +1680,13 @@ func schema_pkg_apis_jaegertracing_v1_JaegerQuerySpec(ref common.ReferenceCallba Format: "", }, }, + "tracingEnabled": { + SchemaProps: spec.SchemaProps{ + Description: "TracingEnabled if set to false adds the JAEGER_DISABLED environment flag and removes the injected agent container from the query component to disable tracing requests to the query service. The default, if ommited, is true", + Type: []string{"boolean"}, + Format: "", + }, + }, }, }, }, diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index 66ebcb0c2..855cfe637 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -43,6 +43,11 @@ func (a *AllInOne) Get() *appsv1.Deployment { adminPort := util.GetAdminPort(args, 14269) + jaegerDisabled := false + if a.jaeger.Spec.AllInOne.TracingEnabled != nil && *a.jaeger.Spec.AllInOne.TracingEnabled == false { + jaegerDisabled = true + } + baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ "prometheus.io/scrape": "true", @@ -140,6 +145,10 @@ func (a *AllInOne) Get() *appsv1.Deployment { Name: "COLLECTOR_ZIPKIN_HTTP_PORT", Value: "9411", }, + { + Name: "JAEGER_DISABLED", + Value: strconv.FormatBool(jaegerDisabled), + }, }, VolumeMounts: commonSpec.VolumeMounts, EnvFrom: envFromSource, diff --git a/pkg/deployment/all_in_one_test.go b/pkg/deployment/all_in_one_test.go index a092f873d..f844a9f26 100644 --- a/pkg/deployment/all_in_one_test.go +++ b/pkg/deployment/all_in_one_test.go @@ -41,6 +41,10 @@ func TestDefaultAllInOneImage(t *testing.T) { Name: "COLLECTOR_ZIPKIN_HTTP_PORT", Value: "9411", }, + { + Name: "JAEGER_DISABLED", + Value: "false", + }, } assert.Equal(t, envvars, d.Spec.Template.Spec.Containers[0].Env) } @@ -352,3 +356,21 @@ func TestAllInOneServiceLinks(t *testing.T) { falseVar := false assert.Equal(t, &falseVar, dep.Spec.Template.Spec.EnableServiceLinks) } + +func TestAllInOneTracingDisabled(t *testing.T) { + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestAllInOneTracingDisabled"}) + falseVar := false + jaeger.Spec.AllInOne.TracingEnabled = &falseVar + d := NewAllInOne(jaeger).Get() + assert.Equal(t, "true", getEnvVarByName(d.Spec.Template.Spec.Containers[0].Env, "JAEGER_DISABLED").Value) +} + +func getEnvVarByName(vars []corev1.EnvVar, name string) corev1.EnvVar { + envVar := corev1.EnvVar{} + for _, v := range vars { + if v.Name == name { + envVar = v + } + } + return envVar +} diff --git a/pkg/deployment/query.go b/pkg/deployment/query.go index 11c50ed20..fdb9ce515 100644 --- a/pkg/deployment/query.go +++ b/pkg/deployment/query.go @@ -45,17 +45,22 @@ func (q *Query) Get() *appsv1.Deployment { "prometheus.io/port": strconv.Itoa(int(adminPort)), "sidecar.istio.io/inject": "false", "linkerd.io/inject": "disabled", - - // note that we are explicitly using a string here, not the value from `inject.Annotation` - // this has two reasons: - // 1) as it is, it would cause a circular dependency, so, we'd have to extract that constant to somewhere else - // 2) this specific string is part of the "public API" of the operator: we should not change - // it at will. So, we leave this configured just like any other application would - "sidecar.jaegertracing.io/inject": q.jaeger.Name, }, Labels: labels, } + jaegerDisabled := false + if q.jaeger.Spec.Query.TracingEnabled != nil && *q.jaeger.Spec.Query.TracingEnabled == false { + jaegerDisabled = true + } else { + // note that we are explicitly using a string here, not the value from `inject.Annotation` + // this has two reasons: + // 1) as it is, it would cause a circular dependency, so, we'd have to extract that constant to somewhere else + // 2) this specific string is part of the "public API" of the operator: we should not change + // it at will. So, we leave this configured just like any other application would + baseCommonSpec.Annotations["sidecar.jaegertracing.io/inject"] = q.jaeger.Name + } + commonSpec := util.Merge([]v1.JaegerCommonSpec{q.jaeger.Spec.Query.JaegerCommonSpec, q.jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) options := allArgs(q.jaeger.Spec.Query.Options, @@ -112,10 +117,16 @@ func (q *Query) Get() *appsv1.Deployment { Image: util.ImageName(q.jaeger.Spec.Query.Image, "jaeger-query-image"), Name: "jaeger-query", Args: options, - Env: []corev1.EnvVar{{ - Name: "SPAN_STORAGE_TYPE", - Value: string(q.jaeger.Spec.Storage.Type), - }}, + Env: []corev1.EnvVar{ + { + Name: "SPAN_STORAGE_TYPE", + Value: string(q.jaeger.Spec.Storage.Type), + }, + { + Name: "JAEGER_DISABLED", + Value: strconv.FormatBool(jaegerDisabled), + }, + }, VolumeMounts: commonSpec.VolumeMounts, EnvFrom: envFromSource, Ports: []corev1.ContainerPort{ diff --git a/pkg/deployment/query_test.go b/pkg/deployment/query_test.go index f924e4c88..549107fb6 100644 --- a/pkg/deployment/query_test.go +++ b/pkg/deployment/query_test.go @@ -322,3 +322,12 @@ func TestQueryServiceLinks(t *testing.T) { falseVar := false assert.Equal(t, &falseVar, dep.Spec.Template.Spec.EnableServiceLinks) } + +func TestQueryTracingDisabled(t *testing.T) { + jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestQueryJaegerDisabled"}) + falseVar := false + jaeger.Spec.Query.TracingEnabled = &falseVar + query := NewQuery(jaeger) + dep := query.Get() + assert.Equal(t, "true", getEnvVarByName(dep.Spec.Template.Spec.Containers[0].Env, "JAEGER_DISABLED").Value) +} diff --git a/pkg/strategy/production.go b/pkg/strategy/production.go index 8bee3da41..7e1477732 100644 --- a/pkg/strategy/production.go +++ b/pkg/strategy/production.go @@ -125,7 +125,10 @@ func newProductionStrategy(ctx context.Context, jaeger *v1.Jaeger) S { // prepare the deployments, which may get changed by the elasticsearch routine cDep := collector.Get() - queryDep := inject.Sidecar(jaeger, inject.OAuthProxy(jaeger, query.Get())) + queryDep := inject.OAuthProxy(jaeger, query.Get()) + if jaeger.Spec.Query.TracingEnabled == nil || *jaeger.Spec.Query.TracingEnabled == true { + queryDep = inject.Sidecar(jaeger, queryDep) + } c.dependencies = storage.Dependencies(jaeger) // assembles the pieces for an elasticsearch self-provisioned deployment via the elasticsearch operator diff --git a/pkg/strategy/production_test.go b/pkg/strategy/production_test.go index 57a01d0d6..3227764a7 100644 --- a/pkg/strategy/production_test.go +++ b/pkg/strategy/production_test.go @@ -198,6 +198,18 @@ func TestAgentSidecarIsInjectedIntoQueryForStreamingForProduction(t *testing.T) } } +func TestAgentSidecarNotInjectedTracingEnabledFalseForProduction(t *testing.T) { + j := v1.NewJaeger(types.NamespacedName{Name: "TestAgentSidecarNotInjectedTracingEnabledFalseForProduction"}) + falseVar := false + j.Spec.Query.TracingEnabled = &falseVar + c := newProductionStrategy(context.Background(), j) + for _, dep := range c.Deployments() { + if strings.HasSuffix(dep.Name, "-query") { + assert.Equal(t, 1, len(dep.Spec.Template.Spec.Containers)) + } + } +} + func TestElasticsearchInject(t *testing.T) { j := v1.NewJaeger(types.NamespacedName{Name: t.Name()}) j.Spec.Storage.Type = v1.JaegerESStorage diff --git a/pkg/strategy/streaming.go b/pkg/strategy/streaming.go index 57af77625..f6c7226eb 100644 --- a/pkg/strategy/streaming.go +++ b/pkg/strategy/streaming.go @@ -138,7 +138,10 @@ func newStreamingStrategy(ctx context.Context, jaeger *v1.Jaeger) S { // prepare the deployments, which may get changed by the elasticsearch routine cDep := collector.Get() - queryDep := inject.Sidecar(jaeger, inject.OAuthProxy(jaeger, query.Get())) + queryDep := inject.OAuthProxy(jaeger, query.Get()) + if jaeger.Spec.Query.TracingEnabled == nil || *jaeger.Spec.Query.TracingEnabled == true { + queryDep = inject.Sidecar(jaeger, queryDep) + } var ingesterDep *appsv1.Deployment if d := ingester.Get(); d != nil { ingesterDep = d diff --git a/pkg/strategy/streaming_test.go b/pkg/strategy/streaming_test.go index 67415fbd4..1eee0cb23 100644 --- a/pkg/strategy/streaming_test.go +++ b/pkg/strategy/streaming_test.go @@ -249,6 +249,18 @@ func TestAgentSidecarIsInjectedIntoQueryForStreaming(t *testing.T) { } } +func TestAgentSidecarNotInjectedTracingEnabledFalseForStreaming(t *testing.T) { + j := v1.NewJaeger(types.NamespacedName{Name: "TestAgentSidecarNotInjectedTracingEnabledFalseForStreaming"}) + falseVar := false + j.Spec.Query.TracingEnabled = &falseVar + c := newStreamingStrategy(context.Background(), j) + for _, dep := range c.Deployments() { + if strings.HasSuffix(dep.Name, "-query") { + assert.Equal(t, 1, len(dep.Spec.Template.Spec.Containers)) + } + } +} + func TestAutoProvisionedKafkaInjectsIntoInstance(t *testing.T) { name := "my-instance" jaeger := v1.NewJaeger(types.NamespacedName{Name: name, Namespace: "project"})