@@ -43,7 +43,7 @@ func AddToPod(
4343 spec * v1beta1.InstrumentationSpec ,
4444 pullPolicy corev1.PullPolicy ,
4545 inInstanceConfigMap * corev1.ConfigMap ,
46- outPod * corev1.PodSpec ,
46+ template * corev1.PodTemplateSpec ,
4747 volumeMounts []corev1.VolumeMount ,
4848 sqlQueryPassword string ,
4949 logDirectories []string ,
@@ -76,13 +76,27 @@ func AddToPod(
7676 }},
7777 }
7878
79- // If the user has specified files to be mounted in the spec, add them to the projected config volume
80- if spec != nil && spec .Config != nil && spec .Config .Files != nil {
81- configVolume .Projected .Sources = append (configVolume .Projected .Sources , spec .Config .Files ... )
79+ // If the user has specified files to be mounted in the spec, add them to
80+ // the projected config volume
81+ if spec .Config != nil && spec .Config .Files != nil {
82+ configVolume .Projected .Sources = append (configVolume .Projected .Sources ,
83+ spec .Config .Files ... )
84+ }
85+
86+ // If the user has specified custom queries to add, put the queries file(s)
87+ // in the projected config volume
88+ if spec .Metrics != nil && spec .Metrics .CustomQueries != nil &&
89+ spec .Metrics .CustomQueries .Add != nil {
90+ for _ , querySet := range spec .Metrics .CustomQueries .Add {
91+ projection := querySet .Queries .AsProjection (querySet .Name +
92+ "/" + querySet .Queries .Key )
93+ configVolume .Projected .Sources = append (configVolume .Projected .Sources ,
94+ corev1.VolumeProjection {ConfigMap : & projection })
95+ }
8296 }
8397
8498 // Add configVolume to the pod's volumes
85- outPod . Volumes = append (outPod .Volumes , configVolume )
99+ template . Spec . Volumes = append (template . Spec .Volumes , configVolume )
86100
87101 // Create collector container
88102 container := corev1.Container {
@@ -136,18 +150,22 @@ func AddToPod(
136150 }},
137151 }
138152 container .VolumeMounts = append (container .VolumeMounts , logrotateConfigVolumeMount )
139- outPod . Volumes = append (outPod .Volumes , logrotateConfigVolume )
153+ template . Spec . Volumes = append (template . Spec .Volumes , logrotateConfigVolume )
140154 }
141155
142156 if feature .Enabled (ctx , feature .OpenTelemetryMetrics ) {
143157 container .Ports = []corev1.ContainerPort {{
144- ContainerPort : int32 (8889 ),
158+ ContainerPort : int32 (PrometheusPort ),
145159 Name : "otel-metrics" ,
146160 Protocol : corev1 .ProtocolTCP ,
147161 }}
148162 }
149163
150- outPod .Containers = append (outPod .Containers , container )
164+ template .Spec .Containers = append (template .Spec .Containers , container )
165+
166+ // add the proper label to support Pod discovery by Prometheus
167+ initialize .Labels (template )
168+ template .Labels [naming .LabelCollectorDiscovery ] = "true"
151169}
152170
153171// startCommand generates the command script used by the collector container
0 commit comments