Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add not dedoted k8s pod labels in autodiscover provider to be used for templating, exactly like annotations #1398

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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