Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MISC] Sanitize PostgreSQL extra-user-roles arg #506

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sinclert-canonical
Copy link
Contributor

This PR contains a slight refactor to sync code with PostgreSQL VM / K8s operator codebases.

Changes:

  • Start leveraging PostgreSQL lib PERMISSIONS_GROUP_ADMIN constant.
  • Start passing PostgreSQL lib create-user extra_user_roles argument as a list.

@sinclert-canonical sinclert-canonical added the not bug or enhancement PR is not 'bug' or 'enhancement'. For release notes label Mar 4, 2025
Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.

Project coverage is 75.11%. Comparing base (000f9c8) to head (3f732ef).

Files with missing lines Patch % Lines
src/charm.py 25.00% 3 Missing ⚠️
src/relations/pgbouncer_provider.py 66.66% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #506      +/-   ##
==========================================
- Coverage   75.20%   75.11%   -0.10%     
==========================================
  Files           9        9              
  Lines        1319     1326       +7     
  Branches      239      241       +2     
==========================================
+ Hits          992      996       +4     
- Misses        254      256       +2     
- Partials       73       74       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sinclert-canonical sinclert-canonical force-pushed the sinclert/provider-extra-roles branch from 5ee3858 to 8994aa2 Compare March 4, 2025 10:40
@sinclert-canonical
Copy link
Contributor Author

Not sure why the test-db tests and the test-backend-database tests fail consistently 🤔

@dragomirp
Copy link
Contributor

dragomirp commented Mar 4, 2025

Not sure why the test-db tests and the test-backend-database tests fail consistently 🤔

Pgbouncer is a subordinate charm and has to run on both Jammy (py 3.10) and Focal (py 3.8). The list typing doesn't seem to work on python 3.8:

unit-pgbouncer-1: 11:12:20 WARNING unit.pgbouncer/1.install Traceback (most recent call last):
unit-pgbouncer-1: 11:12:20 WARNING unit.pgbouncer/1.install   File "/var/lib/juju/agents/unit-pgbouncer-1/charm/src/charm.py", line 25, in <module>
unit-pgbouncer-1: 11:12:20 WARNING unit.pgbouncer/1.install     from charms.postgresql_k8s.v0.postgresql import PERMISSIONS_GROUP_ADMIN
unit-pgbouncer-1: 11:12:20 WARNING unit.pgbouncer/1.install   File "/var/lib/juju/agents/unit-pgbouncer-1/charm/lib/charms/postgresql_k8s/v0/postgresql.py", line 104, in <module>
unit-pgbouncer-1: 11:12:20 WARNING unit.pgbouncer/1.install     class PostgreSQL:
unit-pgbouncer-1: 11:12:20 WARNING unit.pgbouncer/1.install   File "/var/lib/juju/agents/unit-pgbouncer-1/charm/lib/charms/postgresql_k8s/v0/postgresql.py", line 226, in PostgreSQL
unit-pgbouncer-1: 11:12:20 WARNING unit.pgbouncer/1.install     extra_user_roles: Optional[list[str]] = None,
unit-pgbouncer-1: 11:12:20 WARNING unit.pgbouncer/1.install TypeError: 'type' object is not subscriptable

We will have to change the lib to Optional[List[str]] for backwards compatibility.

@sinclert-canonical
Copy link
Contributor Author

sinclert-canonical commented Mar 4, 2025

The list typing doesn't seem to work on python 3.8.

Right, that Python >= 3.10 syntax is coming from the recently merged PostgreSQL charm lib...

I would rather leave this PR frozen in time, until we decide to bump the minimum Python version in this repository, than to open another round of 3+ PRs just to revert a function signature. WDYT?

@dragomirp
Copy link
Contributor

Right, that Python >= 3.10 syntax is coming from the recently merged PostgreSQL charm lib...

I would rather leave this PR frozen in time, until we decide to bump the minimum Python version in this repository, than to open another round of 3+ PRs just to revert a function signature. WDYT?

There's no plan for updating the python version ATM, since that is what's available in Focal. The charm lib has to work on 3.8.

@sinclert-canonical sinclert-canonical force-pushed the sinclert/provider-extra-roles branch from 8994aa2 to f074c3a Compare March 4, 2025 12:03
@sinclert-canonical sinclert-canonical force-pushed the sinclert/provider-extra-roles branch from f074c3a to 3f732ef Compare March 4, 2025 13:12
@sinclert-canonical
Copy link
Contributor Author

PR rebased assuming the PostgreSQL k8s operator PR fixing the function signature will be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Libraries: Out of sync not bug or enhancement PR is not 'bug' or 'enhancement'. For release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants