Cherry-pick #24742 to 7.x: Refactor kubernetes autodiscover to avoid skipping short-living pods #25167
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cherry-pick of PR #24742 to 7.x branch. Original message:
What does this PR do?
Refactor logic in kubernetes autodiscover that decides when to generate events to try to address #22718.
Kubernetes autodiscover can generate events without network information now (without
host
orport
/ports
). This allows to generate events for pods that haven't started yet, or have succeeded/failed before generating a running event. These events still include the container id, so they can be used to collect logs. Still, no start event is generated if no pod ip and no container ids are available.Some helpers have been added to obtain relevant information from pods and their containers.
Some additional small refactors are done to improve readability.
Why is it important?
Current logic is checking similar things at the pod and container levels, try to simplify this logic focusing in containers only.
No matter what is the state of the pod, if there is a container running or trying to run, even if it is unhealthy, some configuration should be generated, so logs can be collected.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesCHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Author's Checklist
data.host
.This is logged at the debug level:
data.host
ordata.ports
.data.ports.*
doesn't seem to be working, check if this is a regression. Named ports were not added to container events. They are now.Author's notes for the future
data.ports
is not included in container-level events, so it doesn't work when conditions for specific containers are used.How to test this PR locally
kubectl run --image=redis redis -- echo foo
).Related issues
Use cases
Collect logs from containers in short-living or failing pods.