Skip to content

fix: fetch logs from all containers in test pods - #32099

Merged
TerryHowe merged 2 commits into
helm:mainfrom
SebTardif:fix/helm-test-logs-multi-container
May 11, 2026
Merged

fix: fetch logs from all containers in test pods#32099
TerryHowe merged 2 commits into
helm:mainfrom
SebTardif:fix/helm-test-logs-multi-container

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

When a test pod contains multiple containers (e.g. Istio/Consul/Vault sidecars, or multi-container test setups), helm test --logs fails with:

unable to get pod logs for <pod>: a container name must be specified for pod <pod>, choose one of: [container-0 container-1]

This is because GetPodLogs() called the Kubernetes log API without specifying a container name. When a pod has >1 container, the API requires an explicit container name.

Fix: Fetch the pod spec first, then iterate over all containers (init containers + regular containers) and request logs for each one by name. This matches the behavior of kubectl logs --all-containers.

  • Errors from individual containers are collected and returned together via errors.Join() rather than aborting on the first failure
  • Output header now shows POD LOGS: <pod> (<container>) for clarity
  • Also fixes a typo: hooksByWight -> hooksByWeight

Closes #6902
Also addresses #9892

Special notes for your reviewer:

  • Permissions: No changes (still uses Pods.Get + Pods.GetLogs, no RBAC changes needed)
  • API: No changes to GetPodLogs() signature
  • Backward compatibility: Single-container pods now get a (container: X) suffix in the log header. Since multi-container pods previously always errored, there is no breaking change.

If applicable:

  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

When a test pod contains multiple containers (e.g. Istio/Consul/Vault
sidecars), 'helm test --logs' failed with 'a container name must be
specified'. This happened because GetPodLogs called the Kubernetes log
API without specifying a container name.

The fix fetches the pod spec first, then iterates over all containers
(init containers + regular containers) and requests logs for each one
explicitly. Errors from individual containers are collected and returned
together via errors.Join rather than aborting on the first failure.

Also fixes a typo: hooksByWight -> hooksByWeight.

Closes helm#6902

Signed-off-by: Sebastien Tardif <SebTardif@ncf.ca>
Copilot AI review requested due to automatic review settings May 4, 2026 20:58
@pull-request-size pull-request-size Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 4, 2026
@promptless-for-oss

Copy link
Copy Markdown

Promptless prepared a documentation update related to this change.

Triggered by helm/helm#32099

Added a "Viewing Test Logs" section to docs/topics/chart_tests.md documenting the --logs flag behavior, including multi-container pod support and the output format showing container names.

Review: Document helm test --logs multi-container support

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates helm test --logs to fetch pod logs per container instead of relying on the pod-level default, so multi-container test pods no longer fail when Kubernetes requires an explicit container name.

Changes:

  • Refactors ReleaseTesting.GetPodLogs to fetch the pod first and iterate containers when collecting logs.
  • Adds joined per-container error handling and includes the container name in log headers.
  • Expands release_testing_test.go with coverage for multi-container and init-container cases, plus a typo fix in a local variable name.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
pkg/action/release_testing.go Implements per-container pod log retrieval and aggregates container-level failures.
pkg/action/release_testing_test.go Adds tests for multi-container/init-container log collection paths and updates an error assertion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/action/release_testing.go
Comment thread pkg/action/release_testing_test.go Outdated
Comment thread pkg/action/release_testing.go
- Close log stream after reading (prevents connection/fd leak)
- Strengthen tests to assert on output headers rather than error paths
- Remove unused import

Signed-off-by: Sebastien Tardif <SebTardif@ncf.ca>
@SebTardif

Copy link
Copy Markdown
Contributor Author

@sabre1041 @joejulian @TerryHowe — this PR addresses #6902 (and #9892) by fetching logs from all containers in test pods, which you discussed in PR #12113.

Key differences from #12113 and #31854:

  • Always iterates per-container (no annotation needed, no special-casing single vs multi)
  • Includes init containers
  • Aggregates errors with errors.Join() instead of dropping them
  • Closes the log stream after reading
  • Includes unit tests for multi-container, init-container, pod-not-found, and output format

Would appreciate a review when you get a chance. Thanks!

Comment thread pkg/action/release_testing.go
@TerryHowe
TerryHowe dismissed their stale review May 7, 2026 20:23

Resolved

@SebTardif
SebTardif requested a review from TerryHowe May 7, 2026 20:57

@sabre1041 sabre1041 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice job

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@TerryHowe
TerryHowe merged commit 0f09636 into helm:main May 11, 2026
5 checks passed
@scottrigby scottrigby added the bug Categorizes issue or PR as related to a bug. label Aug 13, 2026
@scottrigby

Copy link
Copy Markdown
Member

This was missed in the v4.2.0 release. Adding to the next patch release.

@scottrigby scottrigby added this to the 4.2.4 milestone Aug 13, 2026
@scottrigby scottrigby added needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. picked Indicates that a PR has been cherry-picked into the next release candidate. and removed needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. picked Indicates that a PR has been cherry-picked into the next release candidate. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

helm test --logs for all containers in a pod

6 participants

Sponsor
SponsoredKunjungi sekarang
Promo