Skip to content

Commit

Permalink
Add not dedoted k8s pod labels in autodiscover provider to be used fo…
Browse files Browse the repository at this point in the history
…r templating, exactly like annotations (#1398)
  • Loading branch information
MichaelKatsoulis authored Oct 10, 2022
1 parent a3ea750 commit f772a3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
- Fix unintended reset of source URI when downloading components {pull}1252[1252]
- 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]
- Add success log message after previous checkin failures {pull}1327[1327]
- Fix inconsistency between kubernetes pod annotations and labels in autodiscovery templates {pull}1327[1327]

==== New features

Expand Down
15 changes: 14 additions & 1 deletion internal/pkg/composable/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ func generatePodData(
_ = safemapstr.Put(annotations, k, v)
}
k8sMapping["annotations"] = annotations
// Pass labels(not dedoted) to all events so that they can be used in templating.
labels := mapstr.M{}
for k, v := range pod.GetObjectMeta().GetLabels() {
_ = safemapstr.Put(labels, k, v)
}
k8sMapping["labels"] = labels

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

// Pass labels to all events so that it can be used in templating.
labels := mapstr.M{}
for k, v := range pod.GetObjectMeta().GetLabels() {
_ = safemapstr.Put(labels, k, v)
}

for _, c := range containers {
// If it doesn't have an ID, container doesn't exist in
// the runtime, emit only an event if we are stopping, so
Expand All @@ -329,8 +341,9 @@ func generateContainerData(
if len(namespaceAnnotations) != 0 {
k8sMapping["namespace_annotations"] = namespaceAnnotations
}
// add annotations to be discoverable by templates
// add annotations and labels to be discoverable by templates
k8sMapping["annotations"] = annotations
k8sMapping["labels"] = labels

//container ECS fields
cmeta := mapstr.M{
Expand Down

0 comments on commit f772a3d

Please sign in to comment.