fix(report,cluster): ensure the process continues when previous logs are unavailable by armru · Pull Request #8992 · cloudnative-pg/cloudnative-pg

@dosubot dosubot bot added the size:M

This PR changes 30-99 lines, ignoring generated files.

label

Oct 29, 2025

@armru armru changed the title fix(plugin): kubectl cnpg report cluster --logs fails when previous logs unavailable fix(report,cluster): ensure the process continues when previous logs are unavailable

Oct 29, 2025

gbartolini

@dosubot dosubot bot added the lgtm

This PR has been approved by a maintainer

label

Oct 29, 2025

@armru @jbattiato

…ogs unavailable

Fixed two bugs in the pod logs writer that caused log collection to fail:

1. When Previous option is enabled, sendLogsToWriter was attempting to
   fetch logs with Previous=true twice - once for previous logs and
   again for current logs. This caused failures when containers had
   never been restarted (no previous terminated container exists).
   Now it correctly fetches previous logs first (with error handling),
   then fetches current logs with Previous=false.

2. The Multiple method was incorrectly passing opts instead of
   containerOpts to sendLogsToWriter, causing the container name to
   not be set properly.

These fixes ensure that:
- Missing previous logs are handled gracefully without stopping execution
- Current logs are always collected even if previous logs are unavailable
- Each container's logs are fetched with the correct container name

Fixes #8985

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>

jbattiato

cnpg-bot pushed a commit that referenced this pull request

Oct 30, 2025
…unavailable (#8992)

Fixes two issues in the pod logs writer that caused log collection to fail:

1. Incorrect handling of previous logs: when the `Previous` option was enabled,
   `sendLogsToWriter` attempted to fetch logs with `Previous=true` twice — once
   for the previous logs and again for the current logs.  This failed when
   containers had never been restarted (no previous terminated container).
   The logic now correctly fetches previous logs first (with proper error
   handling) and then retrieves current logs with `Previous=false`.

2. Incorrect container options: the `Multiple` method was passing `opts`
   instead of `containerOpts` to `sendLogsToWriter`, resulting in missing
   container names in the log collection process.

With these fixes:

- Missing previous logs no longer stop the process.
- Current logs are always collected, even if previous logs are unavailable.
- Each container’s logs are fetched with the correct container name.

Fixes #8985

Signed-off-by: Armando Ruocco armando.ruocco@enterprisedb.com
(cherry picked from commit eef478d)

cnpg-bot pushed a commit that referenced this pull request

Oct 30, 2025
…unavailable (#8992)

Fixes two issues in the pod logs writer that caused log collection to fail:

1. Incorrect handling of previous logs: when the `Previous` option was enabled,
   `sendLogsToWriter` attempted to fetch logs with `Previous=true` twice — once
   for the previous logs and again for the current logs.  This failed when
   containers had never been restarted (no previous terminated container).
   The logic now correctly fetches previous logs first (with proper error
   handling) and then retrieves current logs with `Previous=false`.

2. Incorrect container options: the `Multiple` method was passing `opts`
   instead of `containerOpts` to `sendLogsToWriter`, resulting in missing
   container names in the log collection process.

With these fixes:

- Missing previous logs no longer stop the process.
- Current logs are always collected, even if previous logs are unavailable.
- Each container’s logs are fetched with the correct container name.

Fixes #8985

Signed-off-by: Armando Ruocco armando.ruocco@enterprisedb.com
(cherry picked from commit eef478d)

cnpg-bot pushed a commit that referenced this pull request

Oct 30, 2025
…unavailable (#8992)

Fixes two issues in the pod logs writer that caused log collection to fail:

1. Incorrect handling of previous logs: when the `Previous` option was enabled,
   `sendLogsToWriter` attempted to fetch logs with `Previous=true` twice — once
   for the previous logs and again for the current logs.  This failed when
   containers had never been restarted (no previous terminated container).
   The logic now correctly fetches previous logs first (with proper error
   handling) and then retrieves current logs with `Previous=false`.

2. Incorrect container options: the `Multiple` method was passing `opts`
   instead of `containerOpts` to `sendLogsToWriter`, resulting in missing
   container names in the log collection process.

With these fixes:

- Missing previous logs no longer stop the process.
- Current logs are always collected, even if previous logs are unavailable.
- Each container’s logs are fetched with the correct container name.

Fixes #8985

Signed-off-by: Armando Ruocco armando.ruocco@enterprisedb.com
(cherry picked from commit eef478d)