@@ -17,6 +17,7 @@ package manager
1717import (
1818 "context"
1919 "fmt"
20+ "maps"
2021 "math"
2122 "path/filepath"
2223 "strings"
@@ -478,41 +479,30 @@ func setOtelCommonFieldsDefaults(otelCommonFields *otelv1beta1.OpenTelemetryComm
478479 if otelCommonFields .Args == nil {
479480 otelCommonFields .Args = make (map [string ]string )
480481 }
481- for key , value := range additionalArgs {
482- otelCommonFields .Args [key ] = value
483- }
484-
485- volumeMounts := []corev1.VolumeMount {
486- {
487- Name : "varlog" ,
488- ReadOnly : true ,
489- MountPath : "/var/log" ,
490- },
491- {
492- Name : "varlibdockercontainers" ,
493- ReadOnly : true ,
494- MountPath : "/var/lib/docker/containers" ,
495- },
496- }
497- otelCommonFields .VolumeMounts = append (otelCommonFields .VolumeMounts , volumeMounts ... )
498-
499- volumes := []corev1.Volume {
500- {
501- Name : "varlog" ,
502- VolumeSource : corev1.VolumeSource {
503- HostPath : & corev1.HostPathVolumeSource {
504- Path : "/var/log" ,
482+ maps .Copy (otelCommonFields .Args , additionalArgs )
483+
484+ volumeConfigs := []struct {
485+ name string
486+ path string
487+ }{
488+ {name : "varlog" , path : "/var/log" },
489+ {name : "varlibdockercontainers" , path : "/var/lib/docker/containers" },
490+ }
491+ for _ , config := range volumeConfigs {
492+ if ! volumeExists (otelCommonFields .Volumes , config .name ) {
493+ otelCommonFields .Volumes = append (otelCommonFields .Volumes , corev1.Volume {
494+ Name : config .name ,
495+ VolumeSource : corev1.VolumeSource {
496+ HostPath : & corev1.HostPathVolumeSource {
497+ Path : config .path ,
498+ },
505499 },
506- },
507- },
508- {
509- Name : "varlibdockercontainers" ,
510- VolumeSource : corev1.VolumeSource {
511- HostPath : & corev1.HostPathVolumeSource {
512- Path : "/var/lib/docker/containers" ,
513- },
514- },
515- },
500+ })
501+ otelCommonFields .VolumeMounts = append (otelCommonFields .VolumeMounts , corev1.VolumeMount {
502+ Name : config .name ,
503+ ReadOnly : true ,
504+ MountPath : config .path ,
505+ })
506+ }
516507 }
517- otelCommonFields .Volumes = append (otelCommonFields .Volumes , volumes ... )
518508}
0 commit comments