Skip to content

Commit ec8bdeb

Browse files
committed
fix: relabeling
1 parent 6341245 commit ec8bdeb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/prometheus/validation/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (lcv *LabelConfigValidator) ValidateRelabelConfig(rc monitoringv1.RelabelCo
114114
return fmt.Errorf("'replacement' can not be set for %s action", rc.Action)
115115
}
116116

117-
if action == string(relabel.LabelMap) && (rc.Replacement != nil) && !lcv.isValidLabelName(*rc.Replacement) {
117+
if action == string(relabel.LabelMap) && (rc.Replacement != nil) && !varInRegexTemplate(*rc.Replacement) && !lcv.isValidLabelName(*rc.Replacement) {
118118
return fmt.Errorf("%q is invalid 'replacement' for %s action", *rc.Replacement, rc.Action)
119119
}
120120

pkg/prometheus/validation/validator_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,24 @@ func TestValidateRelabelConfig(t *testing.T) {
385385
},
386386
},
387387
},
388+
{
389+
scenario: "valid labelmap config with replacement containing template variable",
390+
relabelConfig: monitoringv1.RelabelConfig{
391+
Action: "labelmap",
392+
Regex: "^(cluster)$",
393+
Replacement: ptr.To("exported_${1}"),
394+
},
395+
prometheus: defaultPrometheusSpec,
396+
},
397+
{
398+
scenario: "valid labelmap config with replacement",
399+
relabelConfig: monitoringv1.RelabelConfig{
400+
Action: "labelmap",
401+
Regex: "__meta_kubernetes_(.*)",
402+
Replacement: ptr.To("k8s_${1}"),
403+
},
404+
prometheus: defaultPrometheusSpec,
405+
},
388406
} {
389407
t.Run(tc.scenario, func(t *testing.T) {
390408
lcv, err := NewLabelConfigValidator(&tc.prometheus)

0 commit comments

Comments
 (0)