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

[DPE-5833] Create new PostgreSQL version 16 charm #680

Draft
wants to merge 37 commits into
base: 16/edge
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
36dd51c
WIP: enable pg_tracing
shayancanonical Oct 30, 2024
a7ebd83
adapt render patroni function
lucasgameiroborges Oct 30, 2024
a6ab133
Move pg_tracing conf to the correct location
shayancanonical Oct 31, 2024
4d61e71
Merge branch 'experiment/pg_tracing' of github.com:canonical/postgres…
shayancanonical Oct 31, 2024
14157ac
fix lint and unit tests
lucasgameiroborges Nov 6, 2024
6633050
use ubuntu 24.04 as base
lucasgameiroborges Nov 6, 2024
fd5fa46
fix issues + revert base to jammy
lucasgameiroborges Nov 7, 2024
8be9d0f
fix queries for plugin testing
lucasgameiroborges Nov 7, 2024
22a517f
Merge remote-tracking branch 'origin/main' into experiment/pg_tracing
lucasgameiroborges Nov 19, 2024
a9ca5d5
downgrade psycopg2 version
lucasgameiroborges Nov 19, 2024
2090059
update lock file
lucasgameiroborges Nov 19, 2024
a0f3006
update psycopg2-binary too
lucasgameiroborges Nov 19, 2024
16fc2b6
revery psycopg2 versions and add ssl params
lucasgameiroborges Nov 19, 2024
35c0e53
revert lock
lucasgameiroborges Nov 19, 2024
59af024
use noble as base
lucasgameiroborges Nov 19, 2024
77e203e
use different workflow version
lucasgameiroborges Nov 19, 2024
ce650d9
remove cache
lucasgameiroborges Nov 19, 2024
8229e7f
edit plugin
lucasgameiroborges Nov 20, 2024
c30f480
fix integration tests
lucasgameiroborges Nov 20, 2024
ede9c4d
revert pgtracing config + add new snaps
lucasgameiroborges Nov 21, 2024
644ea77
try fixes
lucasgameiroborges Nov 21, 2024
1de4ef4
try new fixes
lucasgameiroborges Nov 21, 2024
6aa0ae4
try fixing restart
lucasgameiroborges Nov 21, 2024
e27901a
try catching reload errors
lucasgameiroborges Nov 22, 2024
e4b8953
adapt test_subordinates to remove ubuntu pro charm
lucasgameiroborges Nov 22, 2024
381845c
try use newer branch for workflow
lucasgameiroborges Nov 26, 2024
9249e7a
Merge branch 'main' into test-pg-16
lucasgameiroborges Nov 26, 2024
6d18038
fix lock hash
lucasgameiroborges Nov 26, 2024
7c780fe
use new branch for plugin too
lucasgameiroborges Nov 26, 2024
d5ebec7
remove old refs to pg 14
lucasgameiroborges Nov 26, 2024
167ac59
specify cc version 3 on release workflow
lucasgameiroborges Nov 27, 2024
3fa1e3b
remove juju 2.9 + refactor release workflow
lucasgameiroborges Nov 27, 2024
788acd7
remove libjuju constraint
lucasgameiroborges Nov 27, 2024
88dd50b
fix release too
lucasgameiroborges Nov 27, 2024
0835d07
use new charm + small adjustments
lucasgameiroborges Dec 4, 2024
1dda43e
Merge remote-tracking branch 'origin/main' into test-pg-16
lucasgameiroborges Dec 5, 2024
26561aa
fix lock file
lucasgameiroborges Dec 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,16 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23.1.1
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@lucas/fix-collect-bases
with:
cache: true
cache: false
charmcraft-snap-channel: 3.x/stable

integration-test:
strategy:
fail-fast: false
matrix:
juju:
- agent: 2.9.51 # renovate: juju-agent-pin-minor
libjuju: ==2.9.49.0 # renovate: latest libjuju 2
allure_on_amd64: false
- agent: 3.4.6 # renovate: juju-agent-pin-minor
allure_on_amd64: true
- snap_channel: 3.6/stable
Expand Down Expand Up @@ -84,7 +82,6 @@ jobs:
cloud: lxd
juju-agent-version: ${{ matrix.juju.agent }}
juju-snap-channel: ${{ matrix.juju.snap_channel }}
libjuju-version-constraint: ${{ matrix.juju.libjuju }}
_beta_allure_report: ${{ matrix.juju.allure_on_amd64 && matrix.architecture == 'amd64' }}
secrets:
integration-test: |
Expand Down
67 changes: 55 additions & 12 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Release to Charmhub
on:
push:
branches:
- main
- 16/edge
paths-ignore:
- 'tests/**'
- 'docs/**'
Expand All @@ -14,27 +14,70 @@ on:
- '.github/workflows/ci.yaml'
- '.github/workflows/lib-check.yaml'
- '.github/workflows/sync_docs.yaml'
# for testing purposes:
workflow_dispatch:

jobs:
ci-tests:
name: Tests
uses: ./.github/workflows/ci.yaml
secrets: inherit
permissions:
contents: write # Needed for Allure Report beta

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@lucas/fix-collect-bases
with:
cache: false
charmcraft-snap-channel: 3.x/stable

integration-test:
strategy:
fail-fast: false
matrix:
juju:
- agent: 3.4.6 # renovate: juju-agent-pin-minor
allure_on_amd64: true
- snap_channel: 3.6/candidate
allure_on_amd64: false
architecture:
- amd64
include:
- juju:
agent: 3.4.6 # renovate: juju-agent-pin-minor
allure_on_amd64: true
architecture: arm64
- juju:
snap_channel: 3.6/candidate
allure_on_amd64: false
architecture: arm64
name: Integration | ${{ matrix.juju.agent || matrix.juju.snap_channel }} | ${{ matrix.architecture }}
needs:
- build
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
architecture: ${{ matrix.architecture }}
cloud: lxd
juju-agent-version: ${{ matrix.juju.agent }}
juju-snap-channel: ${{ matrix.juju.snap_channel }}
_beta_allure_report: ${{ matrix.juju.allure_on_amd64 && matrix.architecture == 'amd64' }}
secrets:
integration-test: |
{
"AWS_ACCESS_KEY": "${{ secrets.AWS_ACCESS_KEY }}",
"AWS_SECRET_KEY": "${{ secrets.AWS_SECRET_KEY }}",
"GCP_ACCESS_KEY": "${{ secrets.GCP_ACCESS_KEY }}",
"GCP_SECRET_KEY": "${{ secrets.GCP_SECRET_KEY }}",
"UBUNTU_PRO_TOKEN" : "${{ secrets.UBUNTU_PRO_TOKEN }}",
"LANDSCAPE_ACCOUNT_NAME": "${{ secrets.LANDSCAPE_ACCOUNT_NAME }}",
"LANDSCAPE_REGISTRATION_KEY": "${{ secrets.LANDSCAPE_REGISTRATION_KEY }}",
}
permissions:
contents: write # Needed for Allure Report beta

release:
name: Release charm
needs:
- ci-tests
- integration-test
- build
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v23.1.1
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@lucas/fix-collect-bases
with:
channel: 14/edge
channel: 16/edge
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
secrets:
charmhub-token: ${{ secrets.CHARMHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ juju add-model sample-model
To deploy a single unit of PostgreSQL using its [default configuration](config.yaml), run the following command:

```shell
juju deploy postgresql --channel 14/stable
juju deploy postgresql --channel 16/stable
```

It is customary to use PostgreSQL with replication to ensure high availability. A replica is equivalent to a juju unit.

To deploy PostgreSQL with multiple replicas, specify the number of desired units with the `-n` option:

```shell
juju deploy postgresql --channel 14/stable -n <number_of_units>
juju deploy postgresql --channel 16/stable -n <number_of_units>
```

To add replicas to an existing deployment, see the [Add replicas](#add-replicas) section.
Expand Down
16 changes: 9 additions & 7 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# See LICENSE file for licensing details.

type: charm
bases:
- name: ubuntu
channel: "22.04"
architectures: [amd64]
- name: ubuntu
channel: "22.04"
architectures: [arm64]
base: [email protected]

platforms:
amd64:
build-on: amd64
build-for: amd64
arm64:
build-on: arm64
build-for: arm64
parts:
charm:
build-snaps:
Expand Down
17 changes: 10 additions & 7 deletions lib/charms/postgresql_k8s/v0/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 39
LIBPATCH = 40

INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles"

Expand Down Expand Up @@ -339,10 +339,12 @@ def enable_disable_extensions(self, extensions: Dict[str, bool], database: str =

# Enable/disabled the extension in each database.
for database in databases:
with self._connect_to_database(
database=database
) as connection, connection.cursor() as cursor:
connection = self._connect_to_database(database=database)
connection.autocommit = True
with connection.cursor() as cursor:
for extension, enable in ordered_extensions.items():
if extension == "postgis":
cursor.execute("SET pgaudit.log = 'none';")
cursor.execute(
f"CREATE EXTENSION IF NOT EXISTS {extension};"
if enable
Expand All @@ -364,6 +366,7 @@ def _generate_database_privileges_statements(
) -> List[Composed]:
"""Generates a list of databases privileges statements."""
statements = []
statements.append(sql.SQL("GRANT USAGE, CREATE ON SCHEMA public TO admin;"))
if relations_accessing_this_database == 1:
statements.append(
sql.SQL(
Expand Down Expand Up @@ -418,11 +421,11 @@ def _generate_database_privileges_statements(
sql.SQL("GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA {} TO {};").format(
schema, sql.Identifier(user)
),
sql.SQL("GRANT USAGE ON SCHEMA {} TO {};").format(
sql.SQL("GRANT USAGE, CREATE ON SCHEMA {} TO {};").format(
schema, sql.Identifier(user)
),
sql.SQL("GRANT CREATE ON SCHEMA {} TO {};").format(
schema, sql.Identifier(user)
sql.SQL("GRANT USAGE, CREATE ON SCHEMA {} TO admin;").format(
schema
),
])
return statements
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ optional = true
pytest = "^8.3.3"
pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.1", subdirectory = "python/pytest_plugins/github_secrets"}
pytest-operator = "^0.38.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.1", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.1", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", branch = "lucas/fix-collect-bases", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.0.5", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
# renovate caret doesn't work: https://github.com/renovatebot/renovate/issues/26940
juju = "<=3.5.0.0"
boto3 = "*"
Expand Down
16 changes: 14 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,12 @@ def update_config(self, is_creating_backup: bool = False) -> bool:
return True

if not self._patroni.member_started:
if enable_tls:
logger.debug(
"Early exit update_config: patroni not responding but TLS is enabled."
)
self._handle_postgresql_restart_need(True)
return True
logger.debug("Early exit update_config: Patroni not started yet")
return False

Expand Down Expand Up @@ -1780,8 +1786,14 @@ def _validate_config_options(self) -> None:

def _handle_postgresql_restart_need(self, enable_tls: bool) -> None:
"""Handle PostgreSQL restart need based on the TLS configuration and configuration changes."""
restart_postgresql = self.is_tls_enabled != self.postgresql.is_tls_enabled()
self._patroni.reload_patroni_configuration()
if self._can_connect_to_postgresql:
restart_postgresql = self.is_tls_enabled != self.postgresql.is_tls_enabled()
else:
restart_postgresql = False
try:
self._patroni.reload_patroni_configuration()
except Exception as e:
logger.error(f"Reload patroni call failed! error: {e!s}")
# Wait for some more time than the Patroni's loop_wait default value (10 seconds),
# which tells how much time Patroni will wait before checking the configuration
# file again to reload it.
Expand Down
2 changes: 1 addition & 1 deletion src/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def remove_raft_member(self, member_ip: str) -> None:
if not result.startswith("SUCCESS"):
raise RemoveRaftMemberFailedError()

@retry(stop=stop_after_attempt(10), wait=wait_exponential(multiplier=1, min=2, max=10))
@retry(stop=stop_after_attempt(20), wait=wait_exponential(multiplier=1, min=2, max=10))
def reload_patroni_configuration(self):
"""Reload Patroni configuration after it was changed."""
requests.post(
Expand Down
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
SNAP_PACKAGES = [
(
POSTGRESQL_SNAP_NAME,
{"revision": {"aarch64": "132", "x86_64": "133"}},
{"revision": {"aarch64": "138", "x86_64": "139"}},
)
]

Expand Down
4 changes: 2 additions & 2 deletions src/dependency.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"snap": {
"dependencies": {},
"name": "charmed-postgresql",
"upgrade_supported": "^14",
"version": "14.12"
"upgrade_supported": "^16",
"version": "16.6"
}
}
10 changes: 9 additions & 1 deletion src/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"aa_DJ",
"aa_DJ.utf8",
"aa_ER",
"aa_ER@saaho",
"aa_ET",
"af_ZA",
"af_ZA.utf8",
Expand Down Expand Up @@ -97,6 +96,7 @@
"chr_US",
"ckb_IQ",
"cmn_TW",
"crh_RU",
"crh_UA",
"cs_CZ",
"cs_CZ.utf8",
Expand Down Expand Up @@ -248,6 +248,7 @@
"ga_IE",
"ga_IE.utf8",
"ga_IE@euro",
"gbm_IN",
"gd_GB",
"gd_GB.utf8",
"gez_ER",
Expand Down Expand Up @@ -308,6 +309,7 @@
"ks_IN@devanagari",
"ku_TR",
"ku_TR.utf8",
"kv_RU",
"kw_GB",
"kw_GB.utf8",
"ky_KG",
Expand Down Expand Up @@ -389,6 +391,7 @@
"pt_PT@euro",
"quz_PE",
"raj_IN",
"rif_MA",
"ro_RO",
"ro_RO.utf8",
"ru_RU",
Expand Down Expand Up @@ -430,8 +433,10 @@
"sr_RS",
"sr_RS@latin",
"ss_ZA",
"ssy_ER",
"st_ZA",
"st_ZA.utf8",
"su_ID",
"sv_FI",
"sv_FI.utf8",
"sv_FI@euro",
Expand All @@ -440,6 +445,7 @@
"sv_SE.utf8",
"sw_KE",
"sw_TZ",
"syr",
"szl_PL",
"ta_IN",
"ta_LK",
Expand All @@ -458,6 +464,7 @@
"tl_PH.utf8",
"tn_ZA",
"to_TO",
"tok",
"tpi_PG",
"tr_CY",
"tr_CY.utf8",
Expand Down Expand Up @@ -491,6 +498,7 @@
"yo_NG",
"yue_HK",
"yuw_PG",
"zgh_MA",
"zh_CN",
"zh_CN.gb18030",
"zh_CN.gbk",
Expand Down
4 changes: 2 additions & 2 deletions src/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def _on_upgrade_charm_check_legacy(self) -> None:
fixed_dependencies["snap"] = {
"dependencies": {},
"name": "charmed-postgresql",
"upgrade_supported": "^14",
"version": "14.9",
"upgrade_supported": "^16",
"version": "16.6",
}
self.peer_relation.data[self.charm.app].update({
"dependencies": json.dumps(fixed_dependencies)
Expand Down
Loading
Loading