Skip to content

Commit 2ee13bb

Browse files
committed
Fixed selectorMatchLabels
Signed-off-by: Yuri Sa <[email protected]>
1 parent 00d2a04 commit 2ee13bb

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

internal/manifests/collector/servicemonitor_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestDesiredServiceMonitors(t *testing.T) {
4040
"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
4141
"app.kubernetes.io/managed-by": "opentelemetry-operator",
4242
"app.kubernetes.io/part-of": "opentelemetry",
43-
"app.kubernetes.io/name": fmt.Sprintf("%s-monitoring", params.OtelCol.Name),
43+
"app.kubernetes.io/name": fmt.Sprintf("%s-collector-monitoring", params.OtelCol.Name),
4444
}
4545
assert.Equal(t, expectedSelectorLabels, actual.Spec.Selector.MatchLabels)
4646
}
@@ -62,7 +62,7 @@ func TestDesiredServiceMonitorsWithPrometheus(t *testing.T) {
6262
"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
6363
"app.kubernetes.io/managed-by": "opentelemetry-operator",
6464
"app.kubernetes.io/part-of": "opentelemetry",
65-
"app.kubernetes.io/name": fmt.Sprintf("%s-monitoring", params.OtelCol.Name),
65+
"app.kubernetes.io/name": fmt.Sprintf("%s-collector-monitoring", params.OtelCol.Name),
6666
}
6767
assert.Equal(t, expectedSelectorLabels, actual.Spec.Selector.MatchLabels)
6868
}

internal/naming/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ func ServiceAccount(otelcol string) string {
159159
func ServiceMonitor(otelcol string) string {
160160
return DNSName(Truncate("%s-collector", 63, otelcol))
161161
}
162+
162163
// ServiceMonitorSelectorName builds the service Monitor name based on the instance.
163164
func ServiceMonitorSelectorName(otelcol string) string {
164-
return DNSName(Truncate("%s-monitoring", 63, otelcol))
165+
return DNSName(Truncate("%s-monitoring", 63, checkCollectorPrefix(otelcol)))
165166
}
166167

167168
// PodMonitor builds the pod Monitor name based on the instance.

internal/naming/triming.go

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package naming
2020
import (
2121
"fmt"
2222
"regexp"
23+
"strings"
2324
)
2425

2526
var regexpEndReplace, regexpBeginReplace *regexp.Regexp
@@ -72,3 +73,13 @@ func trimNonAlphaNumeric(text string) string {
7273
newText := regexpEndReplace.ReplaceAllString(text, "")
7374
return regexpBeginReplace.ReplaceAllString(newText, "")
7475
}
76+
77+
// checkCollectorPrefix adds -collecto suffix in case the ObjectName doesn't contain it
78+
// used on ServiceMonitor selector labels to filter the monitoring service out.
79+
func checkCollectorPrefix(text string) string {
80+
if !strings.Contains(text, "-collector") {
81+
var newText = text + "-collector"
82+
return newText
83+
}
84+
return text
85+
}

0 commit comments

Comments
 (0)