Skip to content

fix: propagate role removal to postgres cluster when databases are removed from postgres database spec#1816

Merged
mploski merged 2 commits intofeature/database-controllersfrom
fix/postgres-controller-roles-removal
Apr 7, 2026
Merged

fix: propagate role removal to postgres cluster when databases are removed from postgres database spec#1816
mploski merged 2 commits intofeature/database-controllersfrom
fix/postgres-controller-roles-removal

Conversation

@mploski
Copy link
Copy Markdown
Collaborator

@mploski mploski commented Apr 3, 2026

Description

Fixes a bug where removing a database from postgres database CR spec.databases (or deleting the CR with DeletionPolicy: Delete) did not cause the corresponding PostgreSQL roles to be dropped in postgres cluster. postgres cluster only drops a role from cnpg when it receives Exists: false in the cluster spec — previously, removed roles were never marked absent but silently wiped out

Key Changes

  • api/v4/postgrescluster_types.go — removed omitempty from ManagedRole.Exists
  • pkg/postgresql/database/core/database.go:
    • cleanupManagedRoles now sends retained + deleted roles together in one SSA patch
  • internal/controller/postgresdatabase_controller_test.go — added integration test for DB removal while CR stays alive;
    extracted expectManagedRoleExists helper used across both role lifecycle tests

Testing and Verification

Added unit and integration tests. All green

Related Issues

Jira tickets, GitHub issues, Support tickets...

PR Checklist

  • Code changes adhere to the project's coding standards.
  • Relevant unit and integration tests are included.
  • Documentation has been updated accordingly.
  • All tests pass locally.
  • The PR description follows the project's guidelines.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contribution License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment with the exact sentence copied from below.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request

@mploski mploski force-pushed the fix/postgres-controller-roles-removal branch from 5618891 to e725c53 Compare April 3, 2026 14:58
@mploski mploski merged commit 50e9642 into feature/database-controllers Apr 7, 2026
5 of 9 checks passed
@mploski mploski deleted the fix/postgres-controller-roles-removal branch April 7, 2026 18:05
@github-actions github-actions bot locked and limited conversation to collaborators Apr 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants