@@ -62,39 +62,13 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt
6262 if getIndexOfEnv (dotNetSpec .Env , envDotNetOTelAutoHome ) > - 1 {
6363 return pod , errors .New ("OTEL_DOTNET_AUTO_HOME environment variable is already set in the .NET instrumentation spec" )
6464 }
65-
66- coreClrProfilerPath := ""
67- switch runtime {
68- case "" , dotNetRuntimeLinuxGlibc :
69- coreClrProfilerPath = dotNetCoreClrProfilerGlibcPath
70- case dotNetRuntimeLinuxMusl :
71- coreClrProfilerPath = dotNetCoreClrProfilerMuslPath
72- default :
65+ if runtime != "" && runtime != dotNetRuntimeLinuxGlibc && runtime != dotNetRuntimeLinuxMusl {
7366 return pod , fmt .Errorf ("provided instrumentation.opentelemetry.io/dotnet-runtime annotation value '%s' is not supported" , runtime )
7467 }
7568
7669 // inject .NET instrumentation spec env vars.
7770 container .Env = appendIfNotSet (container .Env , dotNetSpec .Env ... )
7871
79- const (
80- doNotConcatEnvValues = false
81- concatEnvValues = true
82- )
83-
84- setDotNetEnvVar (container , envDotNetCoreClrEnableProfiling , dotNetCoreClrEnableProfilingEnabled , doNotConcatEnvValues )
85-
86- setDotNetEnvVar (container , envDotNetCoreClrProfiler , dotNetCoreClrProfilerID , doNotConcatEnvValues )
87-
88- setDotNetEnvVar (container , envDotNetCoreClrProfilerPath , coreClrProfilerPath , doNotConcatEnvValues )
89-
90- setDotNetEnvVar (container , envDotNetStartupHook , dotNetStartupHookPath , concatEnvValues )
91-
92- setDotNetEnvVar (container , envDotNetAdditionalDeps , dotNetAdditionalDepsPath , concatEnvValues )
93-
94- setDotNetEnvVar (container , envDotNetOTelAutoHome , dotNetOTelAutoHomePath , doNotConcatEnvValues )
95-
96- setDotNetEnvVar (container , envDotNetSharedStore , dotNetSharedStorePath , concatEnvValues )
97-
9872 container .VolumeMounts = append (container .VolumeMounts , corev1.VolumeMount {
9973 Name : volume .Name ,
10074 MountPath : dotnetInstrMountPath ,
@@ -118,6 +92,30 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int, runt
11892 return pod , nil
11993}
12094
95+ func injectDefaultDotNetEnvVars (container * corev1.Container , runtime string ) {
96+ coreClrProfilerPath := ""
97+ switch runtime {
98+ case "" , dotNetRuntimeLinuxGlibc :
99+ coreClrProfilerPath = dotNetCoreClrProfilerGlibcPath
100+ case dotNetRuntimeLinuxMusl :
101+ coreClrProfilerPath = dotNetCoreClrProfilerMuslPath
102+ }
103+
104+ setDotNetEnvVar (container , envDotNetCoreClrEnableProfiling , dotNetCoreClrEnableProfilingEnabled , false )
105+
106+ setDotNetEnvVar (container , envDotNetCoreClrProfiler , dotNetCoreClrProfilerID , false )
107+
108+ setDotNetEnvVar (container , envDotNetCoreClrProfilerPath , coreClrProfilerPath , false )
109+
110+ setDotNetEnvVar (container , envDotNetStartupHook , dotNetStartupHookPath , true )
111+
112+ setDotNetEnvVar (container , envDotNetAdditionalDeps , dotNetAdditionalDepsPath , true )
113+
114+ setDotNetEnvVar (container , envDotNetOTelAutoHome , dotNetOTelAutoHomePath , false )
115+
116+ setDotNetEnvVar (container , envDotNetSharedStore , dotNetSharedStorePath , true )
117+ }
118+
121119// setDotNetEnvVar function sets env var to the container if not exist already.
122120// value of concatValues should be set to true if the env var supports multiple values separated by :.
123121// If it is set to false, the original container's env var value has priority.
@@ -130,6 +128,10 @@ func setDotNetEnvVar(container *corev1.Container, envVarName string, envVarValue
130128 })
131129 return
132130 }
131+ // Don't modify env var if it uses ValueFrom
132+ if container .Env [idx ].ValueFrom != nil {
133+ return
134+ }
133135 if concatValues {
134136 container .Env [idx ].Value = fmt .Sprintf ("%s:%s" , container .Env [idx ].Value , envVarValue )
135137 }
0 commit comments