Skip to content

feat: cnpg support - #208

Merged
moshloop merged 1 commit into
mainfrom
cnpg-support
Aug 6, 2026
Merged

feat: cnpg support#208
moshloop merged 1 commit into
mainfrom
cnpg-support

Conversation

@yashmehrotra

@yashmehrotra yashmehrotra commented Aug 5, 2026

Copy link
Copy Markdown
Member

Fixes: #199

Summary by CodeRabbit

  • New Features

    • Added health evaluation for CloudNativePG PostgreSQL clusters and backups.
    • Reports Healthy, Progressing, Degraded, Suspended, and Unknown states based on readiness, backup progress, failures, and configuration.
    • Provides informative failure messages, including backup and WAL archiving errors.
  • Tests

    • Added comprehensive scenarios covering cluster readiness, suspension, stale status, backup failures, and backup lifecycle phases.
    • Improved health-status comparisons and test fixture handling.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

CloudNativePG Cluster and Backup health customizations were added. Lua health-status normalization was centralized. Test discovery was updated, and fixture-based tests cover health, readiness, failure, suspension, and backup lifecycle states.

Changes

CloudNativePG health

Layer / File(s) Summary
Lua health normalization
pkg/lua/lua.go, pkg/lua/health_test.go
Health-status normalization now uses a shared helper. Lua tests use the corrected customization path and normalize expected statuses before comparison.
Backup health evaluation
pkg/resource_customizations/postgresql.cnpg.io/Backup/*
Backup phases map to Progressing, Degraded, Healthy, or Unknown. Tests and fixtures cover missing status, active phases, completion, failures, configuration errors, WAL archiving errors, and unknown phases.
Cluster health evaluation
pkg/resource_customizations/postgresql.cnpg.io/Cluster/*, pkg/health/health_test.go
Cluster health handles suspension, hibernation, readiness conditions, stale generations, phase states, and failed-backup warnings. Tests cover the corresponding Cluster and Backup outcomes.

Sequence Diagram(s)

sequenceDiagram
  participant HealthTest
  participant ExecuteHealthLua
  participant ClusterHealthLua
  participant BackupHealthLua
  HealthTest->>ExecuteHealthLua: evaluate CloudNativePG fixture
  ExecuteHealthLua->>ClusterHealthLua: evaluate Cluster health
  ClusterHealthLua-->>ExecuteHealthLua: return cluster health result
  ExecuteHealthLua->>BackupHealthLua: evaluate Backup health
  BackupHealthLua-->>ExecuteHealthLua: return backup health result
  ExecuteHealthLua-->>HealthTest: return normalized status
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: adding CloudNativePG support.
Linked Issues check ✅ Passed The cluster health logic reports a warning for failed LastBackupSucceeded conditions, with matching fixtures and tests [#199].
Out of Scope Changes check ✅ Passed The changes support CloudNativePG health evaluation and test coverage; no unrelated code changes are evident.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cnpg-support
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch cnpg-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/resource_customizations/postgresql.cnpg.io/Cluster/health.lua`:
- Around line 112-114: Update the failed-backup condition in the health
evaluation to remove the conditionIsStale(lastBackup) exclusion, so any
LastBackupSucceeded=False condition still triggers the warning unless the
existing BackupStarted, Degraded, or Suspended exceptions apply. Add a fixture
covering a current Ready=True condition alongside a stale failed-backup
condition.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 00972484-44fa-4f0a-8c85-7f0e8f31cc06

📥 Commits

Reviewing files that changed from the base of the PR and between fcea7ae and 440a94b.

📒 Files selected for processing (24)
  • pkg/health/health_test.go
  • pkg/lua/health_test.go
  • pkg/lua/lua.go
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/health.lua
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/health_test.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/completed.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/failed.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/finalizing.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/invalid.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/no_status.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/pending.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/running.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/unknown.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Backup/testdata/wal_archiving_failing.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/health.lua
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/health_test.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/testdata/backup_started.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/testdata/degraded.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/testdata/healthy.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/testdata/last_backup_failed.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/testdata/no_status.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/testdata/progressing.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/testdata/stale_ready.yaml
  • pkg/resource_customizations/postgresql.cnpg.io/Cluster/testdata/suspended.yaml

Comment on lines +112 to +114
local lastBackup = findCondition("LastBackupSucceeded")
if lastBackup ~= nil and lastBackup.status == "False" and lastBackup.reason ~= "BackupStarted"
and not conditionIsStale(lastBackup) and hs.status ~= "Degraded" and hs.status ~= "Suspended" then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not ignore a failed last backup when its condition is stale.

Line 114 suppresses the warning when LastBackupSucceeded=False has an older observedGeneration. If Ready=True is current, the script returns Healthy instead. This violates the PR objective for a failed latest backup.

Remove not conditionIsStale(lastBackup) from this condition. Add a fixture with a current ready condition and a stale failed-backup condition.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/resource_customizations/postgresql.cnpg.io/Cluster/health.lua` around
lines 112 - 114, Update the failed-backup condition in the health evaluation to
remove the conditionIsStale(lastBackup) exclusion, so any
LastBackupSucceeded=False condition still triggers the warning unless the
existing BackupStarted, Degraded, or Suspended exceptions apply. Add a fixture
covering a current Ready=True condition alongside a stale failed-backup
condition.

@moshloop
moshloop merged commit 2188b63 into main Aug 6, 2026
9 checks passed
@moshloop
moshloop deleted the cnpg-support branch August 6, 2026 05:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CNPG Cluster

2 participants