File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
pkg/prometheus/validation Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments