Skip to content

Commit 6408654

Browse files
authored
sets opentracing to false based on configmap keys (#7482)
1 parent dc80468 commit 6408654

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

internal/configs/configmaps.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,11 @@ func ParseConfigMap(ctx context.Context, cfgm *v1.ConfigMap, nginxPlus bool, has
547547
nl.Error(l, err)
548548
eventLog.Event(cfgm, v1.EventTypeWarning, nl.EventReasonInvalidValue, err.Error())
549549
configOk = false
550+
} else if !openTracing {
551+
cfgParams.MainOpenTracingEnabled = false
552+
cfgParams.MainOpenTracingLoadModule = false
553+
cfgParams.MainOpenTracingTracer = ""
554+
cfgParams.MainOpenTracingTracerConfig = ""
550555
} else {
551556
if cfgParams.MainOpenTracingLoadModule {
552557
cfgParams.MainOpenTracingEnabled = openTracing

internal/configs/configmaps_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,3 +1166,90 @@ func TestParseZoneSyncResolverIPV6MapResolverIPV6(t *testing.T) {
11661166
func makeEventLogger() record.EventRecorder {
11671167
return record.NewFakeRecorder(1024)
11681168
}
1169+
1170+
func TestOpenTracingConfiguration(t *testing.T) {
1171+
t.Parallel()
1172+
tests := []struct {
1173+
configMap *v1.ConfigMap
1174+
enabled bool
1175+
loadModule bool
1176+
tracer string
1177+
tracerConfig string
1178+
msg string
1179+
}{
1180+
{
1181+
configMap: &v1.ConfigMap{
1182+
Data: map[string]string{
1183+
"opentracing": "true",
1184+
"opentracing-tracer": "/usr/local/lib/libjaegertracing.so",
1185+
"opentracing-tracer-config": "/etc/nginx/opentracing.json",
1186+
},
1187+
},
1188+
enabled: true,
1189+
loadModule: true,
1190+
tracer: "/usr/local/lib/libjaegertracing.so",
1191+
tracerConfig: "/etc/nginx/opentracing.json",
1192+
msg: "opentracing enabled",
1193+
},
1194+
{
1195+
configMap: &v1.ConfigMap{
1196+
Data: map[string]string{
1197+
"opentracing": "false",
1198+
"opentracing-tracer": "/usr/local/lib/libjaegertracing.so",
1199+
"opentracing-tracer-config": "/etc/nginx/opentracing.json",
1200+
},
1201+
},
1202+
enabled: false,
1203+
loadModule: false,
1204+
tracer: "",
1205+
tracerConfig: "",
1206+
msg: "opentracing disabled",
1207+
},
1208+
{
1209+
configMap: &v1.ConfigMap{
1210+
Data: map[string]string{
1211+
"opentracing": "false",
1212+
},
1213+
},
1214+
enabled: false,
1215+
loadModule: false,
1216+
tracer: "",
1217+
tracerConfig: "",
1218+
msg: "opentracing disabled",
1219+
},
1220+
}
1221+
nginxPlus := false
1222+
hasAppProtect := false
1223+
hasAppProtectDos := false
1224+
hasTLSPassthrough := false
1225+
1226+
for _, test := range tests {
1227+
t.Run(test.msg, func(t *testing.T) {
1228+
result, configOk := ParseConfigMap(context.Background(), test.configMap, nginxPlus,
1229+
hasAppProtect, hasAppProtectDos, hasTLSPassthrough, makeEventLogger())
1230+
1231+
if !configOk {
1232+
t.Errorf("Expected valid config, got invalid")
1233+
}
1234+
if result.MainOpenTracingEnabled != test.enabled {
1235+
t.Errorf("MainOpenTracingEnabled: want %v, got %v",
1236+
test.enabled, result.MainOpenTracingEnabled)
1237+
}
1238+
1239+
if result.MainOpenTracingLoadModule != test.loadModule {
1240+
t.Errorf("MainOpenTracingLoadModule: want %v, got %v",
1241+
test.loadModule, result.MainOpenTracingLoadModule)
1242+
}
1243+
1244+
if result.MainOpenTracingTracer != test.tracer {
1245+
t.Errorf("MainOpenTracingTracer: want %q, got %q",
1246+
test.tracer, result.MainOpenTracingTracer)
1247+
}
1248+
1249+
if result.MainOpenTracingTracerConfig != test.tracerConfig {
1250+
t.Errorf("MainOpenTracingTracerConfig: want %q, got %q",
1251+
test.tracerConfig, result.MainOpenTracingTracerConfig)
1252+
}
1253+
})
1254+
}
1255+
}

0 commit comments

Comments
 (0)