π Current Behavior
Our existing log tool fetches logs from a Kubernetes pod container using:
{
"name": "string",
"namespace": "string",
"container_name": "",
"tail_lines": 10
}
Current Logic:
- If
container_name is specified β return logs for that specific container.
- If
container_name is NOT specified β return logs for the podβs default container only.
Output format:
{
"logs": {
"current_container": "string",
"previously_terminated_container": "string"
}
}
π© Problem
In multi-container pods (sidecars, init containers, service meshes, etc.), returning logs from only the default container can:
- Hide important information from other containers
- Make debugging more difficult
- Create ambiguity about which container logs are being returned
- Force multiple API calls to retrieve full pod logs
β
Proposed Behavior Change
If container_name is not provided, the API should:
Return logs from all containers inside the pod, structured by container name.
If container_name is provided, behavior remains unchanged.
This maintains backward compatibility while improving usability.
π Proposed Implementation Approach
We can wrap the current functionality:
Step 1: Describe the Pod
Use Kubernetes API to retrieve the pod definition:
Step 2: Iterate Through Containers
For each container:
- Call existing log retrieval logic
- Append results in a structured format
π¦ Proposed Response Structure
Instead of returning a single container log object, return:
{
"logs": {
"app": {
"current": "log content...",
"previous": "previous log content..."
},
"sidecar": {
"current": "log content...",
"previous": null
}
}
}
π― Benefits
- β
More intuitive behavior
- β
Better debugging experience
- β
Reduces API round-trips
- β
Backward compatible (explicit container still works)
- β
Scales naturally with multi-container pods
βοΈ Considerations
-
Performance
- Large pods with many containers may increase response size.
- Mitigation: keep
tail_lines enforced per container.
-
Response Size
Another strategy :
π§ Summary
Enhancing the log tool to return logs from all containers when no container is specified aligns better with real-world Kubernetes usage patterns, especially for multi-container pods.
The change is technically straightforward:
- Describe pod
- Iterate containers
- Aggregate results in structured response
This significantly improves debugging experience with minimal implementation risk.
π Current Behavior
Our existing log tool fetches logs from a Kubernetes pod container using:
{ "name": "string", "namespace": "string", "container_name": "", "tail_lines": 10 }Current Logic:
container_nameis specified β return logs for that specific container.container_nameis NOT specified β return logs for the podβs default container only.Output format:
{ "logs": { "current_container": "string", "previously_terminated_container": "string" } }π© Problem
In multi-container pods (sidecars, init containers, service meshes, etc.), returning logs from only the default container can:
β Proposed Behavior Change
If
container_nameis not provided, the API should:If
container_nameis provided, behavior remains unchanged.This maintains backward compatibility while improving usability.
π Proposed Implementation Approach
We can wrap the current functionality:
Step 1: Describe the Pod
Use Kubernetes API to retrieve the pod definition:
Extract all container names:
spec.containersspec.initContainersStep 2: Iterate Through Containers
For each container:
π¦ Proposed Response Structure
Instead of returning a single container log object, return:
{ "logs": { "app": { "current": "log content...", "previous": "previous log content..." }, "sidecar": { "current": "log content...", "previous": null } } }π― Benefits
βοΈ Considerations
Performance
tail_linesenforced per container.Response Size
Could add optional flag:
for explicit behavior (if team prefers safer rollout).
Another strategy :
Introduce new boolean field:
Keep current default unchanged
π§ Summary
Enhancing the log tool to return logs from all containers when no container is specified aligns better with real-world Kubernetes usage patterns, especially for multi-container pods.
The change is technically straightforward:
This significantly improves debugging experience with minimal implementation risk.