Skip to content

Allow skipping PostgreSQL database backup/restore#353

Open
dsavineau wants to merge 1 commit into
ansible:mainfrom
dsavineau:skip_db_backup_restore
Open

Allow skipping PostgreSQL database backup/restore#353
dsavineau wants to merge 1 commit into
ansible:mainfrom
dsavineau:skip_db_backup_restore

Conversation

@dsavineau

@dsavineau dsavineau commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

This allows one to skip the PostgreSQL database dump/restore during via the EDABackup and EDARestore CRDs on external database configuration.

A new parameter called postgres_skip_data is introduced (defaults to false for backward compatibility) but can be turn on to skip the pg_dump and pg_restore parts.

At restore time, if no database dump file is found in the backup then the postgres_skip_data parameter needs to be explicitely set to true.

Summary by CodeRabbit

  • New Features
    • Added postgres_skip_data option to skip PostgreSQL database dump/restore data in both backup and restore operations
    • Added .status.backupPostgres and .status.restorePostgres fields to report whether PostgreSQL data handling was performed
    • Added restore validation that checks for the PostgreSQL backup file and requires postgres_skip_data when it’s missing
  • Improvements
    • Improved PostgreSQL connection handling by sourcing configuration from the referenced Secret during backup and restore

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: b7f8a85f-7ef8-4e32-a26b-90b82fd43a0b

📥 Commits

Reviewing files that changed from the base of the PR and between ef4e164 and 5680468.

📒 Files selected for processing (15)
  • config/crd/bases/eda.ansible.com_edabackups.yaml
  • config/crd/bases/eda.ansible.com_edarestores.yaml
  • config/manifests/bases/eda-server-operator.clusterserviceversion.yaml
  • roles/backup/defaults/main.yml
  • roles/backup/tasks/creation.yml
  • roles/backup/tasks/init.yml
  • roles/backup/tasks/postgres.yml
  • roles/backup/tasks/set_database_config.yml
  • roles/backup/tasks/update_status.yml
  • roles/restore/defaults/main.yml
  • roles/restore/tasks/check_postgres_backup.yml
  • roles/restore/tasks/main.yml
  • roles/restore/tasks/postgres.yml
  • roles/restore/tasks/set_database_config.yml
  • roles/restore/tasks/update_status.yml
💤 Files with no reviewable changes (2)
  • roles/backup/tasks/postgres.yml
  • roles/restore/tasks/postgres.yml
🚧 Files skipped from review as they are similar to previous changes (12)
  • roles/backup/tasks/creation.yml
  • roles/restore/tasks/update_status.yml
  • roles/backup/tasks/update_status.yml
  • roles/backup/tasks/init.yml
  • roles/restore/tasks/main.yml
  • config/manifests/bases/eda-server-operator.clusterserviceversion.yaml
  • roles/backup/defaults/main.yml
  • roles/backup/tasks/set_database_config.yml
  • roles/restore/tasks/check_postgres_backup.yml
  • config/crd/bases/eda.ansible.com_edarestores.yaml
  • roles/restore/defaults/main.yml
  • roles/restore/tasks/set_database_config.yml

📝 Walkthrough

Walkthrough

This PR adds support for skipping PostgreSQL database data during backup and restore operations in the EDA server operator. The changes refactor database configuration retrieval into reusable task files, initialize backup directories early in the pipeline, and extend CRD schemas with the new postgres_skip_data boolean field and corresponding status fields for both backup and restore operations.

Changes

PostgreSQL Skip-Data Control for Backup and Restore

Layer / File(s) Summary
CRD Schema and Operator Manifest
config/crd/bases/eda.ansible.com_edabackups.yaml, config/crd/bases/eda.ansible.com_edarestores.yaml, config/manifests/bases/eda-server-operator.clusterserviceversion.yaml
EDABackup and EDARestore CRDs gain spec.postgres_skip_data boolean (default false) and status fields (backupPostgres, restorePostgres); operator manifest adds UI descriptors for form controls.
Backup Database Configuration and Defaults
roles/backup/defaults/main.yml, roles/backup/tasks/set_database_config.yml
Backup defaults add postgres_skip_data setting; new set_database_config.yml task file queries the Kubernetes Secret referenced by status.databaseConfigurationSecret, validates presence, and decodes PostgreSQL connection parameters into Ansible facts.
Backup Workflow and Status Reporting
roles/backup/tasks/init.yml, roles/backup/tasks/creation.yml, roles/backup/tasks/postgres.yml, roles/backup/tasks/update_status.yml
Backup init.yml computes shared timestamp and creates backup directory early via k8s_exec; creation.yml includes set_database_config.yml before postgres tasks; postgres.yml removes duplicated config-lookup and directory-creation logic; update_status.yml adds backupPostgres field derived from skip flag and database type.
Restore Database Configuration and Defaults
roles/restore/defaults/main.yml, roles/restore/tasks/set_database_config.yml
Restore defaults add postgres_skip_data setting; new set_database_config.yml task file reads secret name from spec.database.database_secret, queries Secret via k8s_info, and decodes connection parameters with type defaulting to unmanaged.
Restore Validation, Workflow and Status
roles/restore/tasks/check_postgres_backup.yml, roles/restore/tasks/main.yml, roles/restore/tasks/postgres.yml, roles/restore/tasks/update_status.yml
New check_postgres_backup.yml validates backup file (eda.db) exists unless skip is enabled; main.yml orchestrates conditional inclusion of config, validation, and restore tasks; postgres.yml removes duplicated config-lookup logic; update_status.yml adds restorePostgres field derived from skip flag and database type.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: introducing the ability to skip PostgreSQL database backup/restore operations via a new parameter.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@dsavineau dsavineau marked this pull request as ready for review June 11, 2026 21:38

@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: 5

🧹 Nitpick comments (1)
roles/backup/tasks/set_database_config.yml (1)

15-23: 💤 Low value

Inconsistent default handling pattern compared to restore role.

Line 22 uses default('unmanaged'|b64encode) | b64decode while the restore role (shown in context snippet) uses b64decode | default('unmanaged'). Both produce the same result, but the restore pattern is more conventional and easier to understand. Consider aligning with the restore implementation for consistency.

♻️ Suggested alignment with restore pattern
-    eda_postgres_type: "{{ pg_config['resources'][0]['data']['type'] | default('unmanaged'|b64encode) | b64decode }}"
+    eda_postgres_type: "{{ pg_config['resources'][0]['data']['type'] | b64decode | default('unmanaged') }}"
🤖 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 `@roles/backup/tasks/set_database_config.yml` around lines 15 - 23, The
eda_postgres_type default is applied before b64decode which is inconsistent with
the restore role; update the set_fact entry for eda_postgres_type in the Store
Database Configuration task (the set_fact block) to decode first then apply
default by changing its expression to apply b64decode before default (i.e., use
pg_config['resources'][0]['data']['type'] | b64decode | default('unmanaged')) so
it matches the restore pattern and is clearer.
🤖 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 `@roles/backup/tasks/set_database_config.yml`:
- Around line 10-13: The fail task "Fail if postgres configuration secret status
does not exist" uses the wrong condition; change the when clause to check the
actual resources list inside pg_config (e.g., pg_config.resources) rather than
the top-level dict: update the when to something like testing whether
pg_config.resources is undefined or empty (for example using pg_config.resources
is not defined or pg_config.resources | default([]) | length == 0) so the
failure triggers when the secret is missing or the resources list is empty.

In `@roles/backup/tasks/update_status.yml`:
- Line 13: The backupPostgres status calculation is wrong because it only uses
postgres_skip_data; change it to mirror the actual execution condition used in
creation.yml by setting backupPostgres to true when either postgres data is not
skipped or the Postgres type is managed (i.e., use the boolean expression
equivalent to "not postgres_skip_data | bool or eda_postgres_type ==
'managed'"); update the variable expression referencing backupPostgres,
postgres_skip_data and eda_postgres_type so the status accurately reflects
whether the backup task ran.

In `@roles/restore/tasks/set_database_config.yml`:
- Around line 14-22: The set_fact task stores database fields by directly
indexing pg_config['resources'][0], which will error if the Secret wasn't found;
update the role to first check that pg_config.resources exists and has at least
one item (e.g., with a when: "pg_config.resources is defined and
pg_config.resources | length > 0") before running the set_fact that assigns
eda_postgres_user, eda_postgres_pass, eda_postgres_database, eda_postgres_port,
eda_postgres_host, and eda_postgres_type, and add an alternate path (either a
fail task with a clear message or a fallback set_fact with safe defaults using
default(...)) to handle the missing Secret case.
- Around line 14-22: The task assumes all keys exist in
pg_config['resources'][0]['data']; add explicit validation before set_fact to
check the required keys (username, password, database, port, host, type) are
present and provide a clear error if any are missing or else supply safe
defaults for optional values. Use the same pg_config reference in an assert or
fail task (or use the default filter for eda_postgres_type) to verify each key
exists (e.g., check "'username' in pg_config['resources'][0]['data']" etc.), and
only run the set_fact that decodes values (eda_postgres_user, eda_postgres_pass,
eda_postgres_database, eda_postgres_port, eda_postgres_host, eda_postgres_type)
after validation so failures produce a clear, actionable message.

In `@roles/restore/tasks/update_status.yml`:
- Line 11: The restorePostgres status is computed from postgres_skip_data only,
but the actual restore task (postgres.yml via main.yml) runs when "not
postgres_skip_data | bool or eda_postgres_type == 'managed'"; update the
calculation of restorePostgres to mirror that condition so the status reflects
whether the PostgreSQL restore actually ran — e.g. set restorePostgres to the
boolean expression "not postgres_skip_data | bool or eda_postgres_type ==
'managed'" (reference variables: restorePostgres, postgres_skip_data,
eda_postgres_type and the postgres.yml/main.yml condition).

---

Nitpick comments:
In `@roles/backup/tasks/set_database_config.yml`:
- Around line 15-23: The eda_postgres_type default is applied before b64decode
which is inconsistent with the restore role; update the set_fact entry for
eda_postgres_type in the Store Database Configuration task (the set_fact block)
to decode first then apply default by changing its expression to apply b64decode
before default (i.e., use pg_config['resources'][0]['data']['type'] | b64decode
| default('unmanaged')) so it matches the restore pattern and is clearer.
🪄 Autofix (Beta)

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: Enterprise

Run ID: 06e69410-8cce-4dab-a207-c86923ae5dd3

📥 Commits

Reviewing files that changed from the base of the PR and between 0ca356d and ef4e164.

📒 Files selected for processing (15)
  • config/crd/bases/eda.ansible.com_edabackups.yaml
  • config/crd/bases/eda.ansible.com_edarestores.yaml
  • config/manifests/bases/eda-server-operator.clusterserviceversion.yaml
  • roles/backup/defaults/main.yml
  • roles/backup/tasks/creation.yml
  • roles/backup/tasks/init.yml
  • roles/backup/tasks/postgres.yml
  • roles/backup/tasks/set_database_config.yml
  • roles/backup/tasks/update_status.yml
  • roles/restore/defaults/main.yml
  • roles/restore/tasks/check_postgres_backup.yml
  • roles/restore/tasks/main.yml
  • roles/restore/tasks/postgres.yml
  • roles/restore/tasks/set_database_config.yml
  • roles/restore/tasks/update_status.yml
💤 Files with no reviewable changes (2)
  • roles/restore/tasks/postgres.yml
  • roles/backup/tasks/postgres.yml

Comment thread roles/backup/tasks/set_database_config.yml
Comment thread roles/backup/tasks/update_status.yml Outdated
Comment thread roles/restore/tasks/set_database_config.yml
Comment thread roles/restore/tasks/update_status.yml Outdated
Comment thread config/crd/bases/eda.ansible.com_edabackups.yaml Outdated
Comment thread roles/backup/tasks/update_status.yml Outdated
This allows one to skip the PostgreSQL database dump/restore during via the
EDABackup and EDARestore CRDs on external database configuration.

A new parameter called `postgres_skip_data` is introduced (defaults to false
for backward compatibility) but can be turn on to skip the pg_dump and
pg_restore parts.
That value is passed down to nested components so other pg_dump/pg_restore calls
are also skipped.

At restore time, if no database dump file is found in the backup then the
`postgres_skip_data` parameter needs to be explicitely set to true.

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
@dsavineau dsavineau force-pushed the skip_db_backup_restore branch from ef4e164 to 5680468 Compare June 15, 2026 13:37
@sonarqubecloud

Copy link
Copy Markdown

@dsavineau dsavineau requested a review from rooftopcellist June 15, 2026 13:38
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.

2 participants