Skip to content

refactor(config): adopt the single-kernel update_config subsystem#1849

Draft
marceloneppel wants to merge 12 commits into
16/edgefrom
skl-01-adopt-update-config
Draft

refactor(config): adopt the single-kernel update_config subsystem#1849
marceloneppel wants to merge 12 commits into
16/edgefrom
skl-01-adopt-update-config

Conversation

@marceloneppel

Copy link
Copy Markdown
Member

Issue

The update_config subsystem (PostgreSQL parameter building → patroni.yml render → Patroni REST API config patch → reload/restart decision → config-hash persistence) was duplicated in this charm and postgresql-k8s-operator. It has been migrated into the postgresql-charms-single-kernel library; this PR makes the VM charm consume the library's implementation instead of carrying its own copy.

Solution

  • Pin the library at the migration archive (08f5993, the lib PR-stack tip) so the unreleased update_config can be consumed and validated before the library is released. The pin is provisional and swaps to a released version once the lib stack lands.
  • Construct the library ConfigManager with its full collaborator set (tls_manager, patroni_manager) and three charm-owned bridges — request_restart (pop the restarted flag + acquire the rolling-restart lock), refresh_endpoints (client-relation update_endpoints), and restart_services (monitoring + LDAP-sync snap services).
  • update_config now delegates to ConfigManager.update_config; the charm's own copy is removed — _build_postgresql_parameters, the six _calculate_max_* helpers and their validator, _api_update_config, _handle_postgresql_restart_need, generate_config_hash, get_available_memory, is_restart_pending — along with templates/patroni.yml.j2 (the library owns the template).
  • The charm's unit suite is green consuming the library (193 passed): the 31 tests that covered the now-migrated behaviour are removed (that behaviour is tested in the library), and four tests are added for the previously-untested bridges and the delegation.

Stacked on the TLS migration (#1816, base flip/tls-lib) — draft until the lib stack releases and the pin is finalised.

Checklist

  • I have added or updated any relevant documentation.
  • I have cleaned any remaining cloud resources from my accounts.

Consume the single-kernel library's operator-certificate TLS handler
(events.tls.TLS) and TLSManager instead of the charm-side src/relations/tls.py,
stacked on the DPE-10062 Patroni/cluster port (#1788). The TLS events handler
owns the two certificate requirers and is constructor-injected into TLSManager,
whose live-fetch getters read cert/key from them. A charm-side reload bridge
(_reload_tls_after_push) reloads PostgreSQL after the lib handler stores+pushes
certs; it also fires on relation_broken so detaching the TLS operator re-renders
Patroni with TLS disabled.

Removes src/relations/tls.py and push_tls_files_to_workload (now owned by the
lib), routes internal-cert regeneration through _regenerate_internal_cert,
redirects the operator-cert getters to tls_manager, and pins the library to the
TLS stack tip via archive URL (16.3.2 is not yet released).

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
The TLS lib stack was rebased onto current 16/edge and re-bumped to
16.3.3 because 16/edge had meanwhile shipped its own 16.3.2, and the
rebase dropped the dead workload parameter from the TLS events handler
constructor, so the pin and the construction call move together.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
The relation_broken bridge registrations reference only self.on[...], so
an __init__ reorder above the lib handler's construction would silently
run the reload before the lib clears state and pushes files; the prior
test asserted membership without order. The bridge's except-and-defer
branch also had no coverage, so a refactor could drop the broad guard
without failing CI.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Absorb the single remaining 16/edge commit (ca93296: renovate bump to
published single-kernel 16.3.2) since the branch last merged 16/edge.
#1788 (Patroni-port) and the 5a9fa05 lib pin / 2-arg TLS migration are
already on this branch. Keep the branch's unreleased-lib archive-URL pin
(5a9fa05) over 16/edge's published-16.3.2 dep, since this branch tests
the unreleased TLS handler.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

# Conflicts:
#	poetry.lock
#	pyproject.toml
Absorb 16/edge deps bumps (946cb61: Python deps, 24a7609: lock
maintenance) landed since the last merge. Keep the branch's unreleased-lib
archive-URL pin (5a9fa05) over 16/edge's published-16.3.2 dep, since
this branch tests the unreleased TLS handler.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

# Conflicts:
#	poetry.lock
Re-pin the unreleased single-kernel library from 5a9fa05 to a1d2178,
the rebased TLS-stack tip. a1d2178 includes the operator-cert manager/
events handler (the migration payload) plus the docstring/comment cleanup
that dropped stale operator-repo file-path references and #168/V3-V4 idiom
mentions from the lib. The 5a9fa05→a1d2178 diff is docstring/comment-only,
so no charm-side code changes are required.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Remove _platform_machine, _observers_for, and the three
reload-bridge observer-ordering tests that exercised charm-side
__init__ wiring now that the bridge itself is transitional and
scheduled to leave the charm when update_config ports to the lib.

_platform_machine was redundant: refresh_versions.toml keys both
x86_64 and aarch64, so the platform.machine() snap-revision lookup
succeeds natively on either arch without the monkeypatch (proven by
the suite passing on aarch64 after removal). Its harness dependency
and the now-unused TLS_CLIENT/TLS_PEER_RELATION imports go with it.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
The TLS flip branch pinned postgresql-charms-single-kernel to a GitHub
archive URL (commit a1d2178) to test unreleased lib changes. 16.3.3 is
now published to PyPI carrying the same TLS state + manager/events
content, so restore the published-version pin form and regenerate
poetry.lock against the PyPI wheel/tarball.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>

# Conflicts:
#	poetry.lock
Point the charm at the lib PR-stack tip (08f5993) via its GitHub archive
tarball so the migrated update_config subsystem can be exercised by the
charm's own unit suite before the lib is released. The pin is provisional
and swaps to a released version once the lib stack lands.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
The single-kernel library now owns update_config end to end: parameter
building, worker-process calculation, Patroni API patching, restart-need
handling, and Patroni template rendering. Keeping the charm's copy of
that logic would mean maintaining two implementations of the same
behaviour, so the charm delegates to the lib's ConfigManager and its own
copies (worker-calc helpers, _api_update_config,
_handle_postgresql_restart_need, get_available_memory,
generate_config_hash, is_restart_pending, and the charm-local Patroni
template) are removed.

Tests for the deleted methods are dropped rather than re-pointed at the
lib, since the lib is a faithful behaviour-preserving port and their
coverage now lives there; re-asserting the same behaviour charm-side
would just be duplicated coverage. The three new bridge methods
(request_restart, refresh_endpoints, restart_services) that the lib
calls back into, plus the update_config delegation itself, get their
own tests since this is new charm-side wiring with no prior coverage.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
The lib's update_config stack was rebased to add the ported regression tests
(resource-introspection edges + the enable_tls render assertion), orphaning the
old tip 08f5993. Point the archive pin at the new #180 tip; the installed lib
source is unchanged from 08f5993 — only lib test files were added.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Base automatically changed from flip/tls-lib to 16/edge July 16, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Libraries: Out of sync The charm libs used are out-of-sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant