Skip to content

Commit 0a60bb8

Browse files
committed
refactor: commonfields structure
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
1 parent 4c477b2 commit 0a60bb8

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

pkg/resources/manager/collector_manager.go

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package manager
1717
import (
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

Comments
 (0)