@@ -17,6 +17,7 @@ package instrumentation
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "path/filepath"
20
21
"sort"
21
22
"strings"
22
23
"time"
@@ -44,6 +45,9 @@ const (
44
45
volumeName = "opentelemetry-auto-instrumentation"
45
46
initContainerName = "opentelemetry-auto-instrumentation"
46
47
sideCarName = "opentelemetry-auto-instrumentation"
48
+
49
+ exporterCertsVolumeName = volumeName + "-exporter-certs"
50
+ exporterCertsMountPath = "/otel-auto-instrumentation-exporter-certs"
47
51
)
48
52
49
53
// inject a new sidecar container to the given pod, based on the given OpenTelemetryCollector.
@@ -304,6 +308,7 @@ func (i *sdkInjector) injectCommonSDKConfig(ctx context.Context, otelinst v1alph
304
308
Value : chooseServiceName (pod , useLabelsForResourceAttributes , resourceMap , appIndex ),
305
309
})
306
310
}
311
+ configureExporter (otelinst .Spec .Exporter , & pod , container )
307
312
if otelinst .Spec .Exporter .Endpoint != "" {
308
313
idx = getIndexOfEnv (container .Env , constants .EnvOTELExporterOTLPEndpoint )
309
314
if idx == - 1 {
@@ -413,6 +418,85 @@ func (i *sdkInjector) injectCommonSDKConfig(ctx context.Context, otelinst v1alph
413
418
return pod
414
419
}
415
420
421
+ func configureExporter (exporter v1alpha1.Exporter , pod * corev1.Pod , container * corev1.Container ) {
422
+ if exporter .Endpoint != "" {
423
+ if getIndexOfEnv (container .Env , constants .EnvOTELExporterOTLPEndpoint ) == - 1 {
424
+ container .Env = append (container .Env , corev1.EnvVar {
425
+ Name : constants .EnvOTELExporterOTLPEndpoint ,
426
+ Value : exporter .Endpoint ,
427
+ })
428
+ }
429
+ }
430
+ if exporter .TLS == nil {
431
+ return
432
+ }
433
+
434
+ if exporter .TLS .CA != "" {
435
+ val := fmt .Sprintf ("%s/%s" , exporterCertsMountPath , exporter .TLS .CA )
436
+ if filepath .IsAbs (exporter .TLS .CA ) {
437
+ val = exporter .TLS .CA
438
+ }
439
+ if getIndexOfEnv (container .Env , constants .EnvOTELExporterCertificate ) == - 1 {
440
+ container .Env = append (container .Env , corev1.EnvVar {
441
+ Name : constants .EnvOTELExporterCertificate ,
442
+ Value : val ,
443
+ })
444
+ }
445
+ }
446
+ if exporter .TLS .Cert != "" {
447
+ val := fmt .Sprintf ("%s/%s" , exporterCertsMountPath , exporter .TLS .Cert )
448
+ if filepath .IsAbs (exporter .TLS .Cert ) {
449
+ val = exporter .TLS .Cert
450
+ }
451
+ if getIndexOfEnv (container .Env , constants .EnvOTELExporterClientCertificate ) == - 1 {
452
+ container .Env = append (container .Env , corev1.EnvVar {
453
+ Name : constants .EnvOTELExporterClientCertificate ,
454
+ Value : val ,
455
+ })
456
+ }
457
+ }
458
+ if exporter .TLS .Key != "" {
459
+ val := fmt .Sprintf ("%s/%s" , exporterCertsMountPath , exporter .TLS .Key )
460
+ if filepath .IsAbs (exporter .TLS .Key ) {
461
+ val = exporter .TLS .Key
462
+ }
463
+ if getIndexOfEnv (container .Env , constants .EnvOTELExporterClientKey ) == - 1 {
464
+ container .Env = append (container .Env , corev1.EnvVar {
465
+ Name : constants .EnvOTELExporterClientKey ,
466
+ Value : val ,
467
+ })
468
+ }
469
+ }
470
+
471
+ if exporter .TLS .SecretName != "" {
472
+ addVolume := true
473
+ for _ , vol := range pod .Spec .Volumes {
474
+ if vol .Name == exporterCertsVolumeName {
475
+ addVolume = false
476
+ }
477
+ }
478
+ if addVolume {
479
+ pod .Spec .Volumes = append (pod .Spec .Volumes , corev1.Volume {
480
+ Name : exporterCertsVolumeName ,
481
+ VolumeSource : corev1.VolumeSource {
482
+ Secret : & corev1.SecretVolumeSource {SecretName : exporter .TLS .SecretName },
483
+ }})
484
+ }
485
+ addVolumeMount := true
486
+ for _ , vol := range container .VolumeMounts {
487
+ if vol .Name == exporterCertsVolumeName {
488
+ addVolumeMount = false
489
+ }
490
+ }
491
+ if addVolumeMount {
492
+ container .VolumeMounts = append (container .VolumeMounts , corev1.VolumeMount {
493
+ Name : exporterCertsVolumeName ,
494
+ MountPath : exporterCertsMountPath ,
495
+ })
496
+ }
497
+ }
498
+ }
499
+
416
500
// chooseServiceName returns the service name to be used in the instrumentation.
417
501
// The precedence is as follows:
418
502
// 1. label or annotation with key "service.name" or "app.kubernetes.io/name".
0 commit comments