Repository: nginx/kubernetes-ingress

Issue:
[Bug]: opentracing configuration in configmap attempts to be utilized even when set to disabled
### Version

3.7.1

### What Kubernetes platforms are you running on?

EKS Amazon

### Steps to reproduce

Apply the following items in the nginx-ingress configmap
```
  opentracing: "False"
  opentracing-tracer: /usr/local/lib/libzipkin_opentracing_plugin.so
  opentracing-tracer-config: '{"collector_host":null,"sample_rate":1,"service_name":"nginx-ingress"}'
```

It is expected that the first setting `opentracing: "False"` should completely disable the feature, but instead the subsequent two opentracing fields are consumed and applied to the live nginx.conf. Since the tracer-config is invalid, it results in crashloop due to nginx.conf not being valid.

I would expect that disabling opentracing prevents the tracer-config from being used in nginx.conf. Instead I need to remove all of these items from the configmap rather than just switching the disable setting.

Discussion:
@github-actions: Hi @tstraley thanks for reporting! 

 Be sure to check out the [docs](https://docs.nginx.com/nginx-ingress-controller) and the [Contributing Guidelines](https://github.com/nginx/kubernetes-ingress/blob/main/CONTRIBUTING.md) while you wait for a human to take a look at this :slightly_smiling_face:

 Cheers!@vepatel: was able to easily reproduce, will be fixed in future release!@vepatel: @tstraley https://github.com/nginx/kubernetes-ingress/pull/7482#issue-2900421110

Solution patch:
diff --git a/internal/configs/configmaps.go b/internal/configs/configmaps.go
index 5b7d69500..60bd2590f 100644
--- a/internal/configs/configmaps.go
+++ b/internal/configs/configmaps.go
@@ -547,6 +547,11 @@ func ParseConfigMap(ctx context.Context, cfgm *v1.ConfigMap, nginxPlus bool, has
 			nl.Error(l, err)
 			eventLog.Event(cfgm, v1.EventTypeWarning, nl.EventReasonInvalidValue, err.Error())
 			configOk = false
+		} else if !openTracing {
+			cfgParams.MainOpenTracingEnabled = false
+			cfgParams.MainOpenTracingLoadModule = false
+			cfgParams.MainOpenTracingTracer = ""
+			cfgParams.MainOpenTracingTracerConfig = ""
 		} else {
 			if cfgParams.MainOpenTracingLoadModule {
 				cfgParams.MainOpenTracingEnabled = openTracing



Test patch:
diff --git a/internal/configs/configmaps_test.go b/internal/configs/configmaps_test.go
index 3a1c43d8d..7890e8665 100644
--- a/internal/configs/configmaps_test.go
+++ b/internal/configs/configmaps_test.go
@@ -1166,3 +1166,90 @@ func TestParseZoneSyncResolverIPV6MapResolverIPV6(t *testing.T) {
 func makeEventLogger() record.EventRecorder {
 	return record.NewFakeRecorder(1024)
 }
+
+func TestOpenTracingConfiguration(t *testing.T) {
+	t.Parallel()
+	tests := []struct {
+		configMap    *v1.ConfigMap
+		enabled      bool
+		loadModule   bool
+		tracer       string
+		tracerConfig string
+		msg          string
+	}{
+		{
+			configMap: &v1.ConfigMap{
+				Data: map[string]string{
+					"opentracing":               "true",
+					"opentracing-tracer":        "/usr/local/lib/libjaegertracing.so",
+					"opentracing-tracer-config": "/etc/nginx/opentracing.json",
+				},
+			},
+			enabled:      true,
+			loadModule:   true,
+			tracer:       "/usr/local/lib/libjaegertracing.so",
+			tracerConfig: "/etc/nginx/opentracing.json",
+			msg:          "opentracing enabled",
+		},
+		{
+			configMap: &v1.ConfigMap{
+				Data: map[string]string{
+					"opentracing":               "false",
+					"opentracing-tracer":        "/usr/local/lib/libjaegertracing.so",
+					"opentracing-tracer-config": "/etc/nginx/opentracing.json",
+				},
+			},
+			enabled:      false,
+			loadModule:   false,
+			tracer:       "",
+			tracerConfig: "",
+			msg:          "opentracing disabled",
+		},
+		{
+			configMap: &v1.ConfigMap{
+				Data: map[string]string{
+					"opentracing": "false",
+				},
+			},
+			enabled:      false,
+			loadModule:   false,
+			tracer:       "",
+			tracerConfig: "",
+			msg:          "opentracing disabled",
+		},
+	}
+	nginxPlus := false
+	hasAppProtect := false
+	hasAppProtectDos := false
+	hasTLSPassthrough := false
+
+	for _, test := range tests {
+		t.Run(test.msg, func(t *testing.T) {
+			result, configOk := ParseConfigMap(context.Background(), test.configMap, nginxPlus,
+				hasAppProtect, hasAppProtectDos, hasTLSPassthrough, makeEventLogger())
+
+			if !configOk {
+				t.Errorf("Expected valid config, got invalid")
+			}
+			if result.MainOpenTracingEnabled != test.enabled {
+				t.Errorf("MainOpenTracingEnabled: want %v, got %v",
+					test.enabled, result.MainOpenTracingEnabled)
+			}
+
+			if result.MainOpenTracingLoadModule != test.loadModule {
+				t.Errorf("MainOpenTracingLoadModule: want %v, got %v",
+					test.loadModule, result.MainOpenTracingLoadModule)
+			}
+
+			if result.MainOpenTracingTracer != test.tracer {
+				t.Errorf("MainOpenTracingTracer: want %q, got %q",
+					test.tracer, result.MainOpenTracingTracer)
+			}
+
+			if result.MainOpenTracingTracerConfig != test.tracerConfig {
+				t.Errorf("MainOpenTracingTracerConfig: want %q, got %q",
+					test.tracerConfig, result.MainOpenTracingTracerConfig)
+			}
+		})
+	}
+}