Skip to content

Commit 9c6ab7d

Browse files
fix: validate only kubernetes-related vars from kubernetes metadata (#9307) (#9418)
* fix: validate only kubernetes-related vars from kubernetes metadata * fix: QF1004: could use strings.ReplaceAll instead * chore: add changelog fragment (cherry picked from commit 228e4fc) Co-authored-by: Panos Koutsovasilis <[email protected]>
1 parent a257915 commit 9c6ab7d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kind: bug-fix
2+
summary: Correct hints annotations parsing to resolve only `${kubernetes.*}` placeholders instead of resolving all `${...}` patterns.
3+
component: elastic-agent
4+
pr: https://github.com/elastic/elastic-agent/pull/9307

internal/pkg/composable/providers/kubernetes/hints.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (m *hintsBuilder) getFromMeta(value string, kubeMeta mapstr.M) string {
117117
if value == "" {
118118
return ""
119119
}
120-
r := regexp.MustCompile(`\${([^{}]+)}`)
120+
r := regexp.MustCompile(`\${(kubernetes\.[^{}]+)}`)
121121
matches := r.FindAllString(value, -1)
122122
for _, match := range matches {
123123
key := strings.TrimSuffix(strings.TrimPrefix(match, "${kubernetes."), "}")
@@ -131,7 +131,7 @@ func (m *hintsBuilder) getFromMeta(value string, kubeMeta mapstr.M) string {
131131
m.logger.Debugf("cannot convert value into string: %v", val)
132132
return ""
133133
}
134-
value = strings.Replace(value, match, hintVal, -1)
134+
value = strings.ReplaceAll(value, match, hintVal)
135135
}
136136
return value
137137
}

0 commit comments

Comments
 (0)