Skip to content

Commit f772a3d

Browse files
Add not dedoted k8s pod labels in autodiscover provider to be used for templating, exactly like annotations (#1398)
1 parent a3ea750 commit f772a3d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
- Fix unintended reset of source URI when downloading components {pull}1252[1252]
121121
- Create separate status reporter for local only events so that degraded fleet-checkins no longer affect health on successful fleet-checkins. {issue}1157[1157] {pull}1285[1285]
122122
- Add success log message after previous checkin failures {pull}1327[1327]
123+
- Fix inconsistency between kubernetes pod annotations and labels in autodiscovery templates {pull}1327[1327]
123124

124125
==== New features
125126

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ func generatePodData(
267267
_ = safemapstr.Put(annotations, k, v)
268268
}
269269
k8sMapping["annotations"] = annotations
270+
// Pass labels(not dedoted) to all events so that they can be used in templating.
271+
labels := mapstr.M{}
272+
for k, v := range pod.GetObjectMeta().GetLabels() {
273+
_ = safemapstr.Put(labels, k, v)
274+
}
275+
k8sMapping["labels"] = labels
270276

271277
processors := []map[string]interface{}{}
272278
// meta map includes metadata that go under kubernetes.*
@@ -305,6 +311,12 @@ func generateContainerData(
305311
_ = safemapstr.Put(annotations, k, v)
306312
}
307313

314+
// Pass labels to all events so that it can be used in templating.
315+
labels := mapstr.M{}
316+
for k, v := range pod.GetObjectMeta().GetLabels() {
317+
_ = safemapstr.Put(labels, k, v)
318+
}
319+
308320
for _, c := range containers {
309321
// If it doesn't have an ID, container doesn't exist in
310322
// the runtime, emit only an event if we are stopping, so
@@ -329,8 +341,9 @@ func generateContainerData(
329341
if len(namespaceAnnotations) != 0 {
330342
k8sMapping["namespace_annotations"] = namespaceAnnotations
331343
}
332-
// add annotations to be discoverable by templates
344+
// add annotations and labels to be discoverable by templates
333345
k8sMapping["annotations"] = annotations
346+
k8sMapping["labels"] = labels
334347

335348
//container ECS fields
336349
cmeta := mapstr.M{

0 commit comments

Comments
 (0)