Skip to content

refactor(config): adopt single-kernel update_config, drop charm copy#1647

Draft
marceloneppel wants to merge 2 commits into
test/async-replication-tlsfrom
skl-01-adopt-update-config-k8s
Draft

refactor(config): adopt single-kernel update_config, drop charm copy#1647
marceloneppel wants to merge 2 commits into
test/async-replication-tlsfrom
skl-01-adopt-update-config-k8s

Conversation

@marceloneppel

Copy link
Copy Markdown
Member

Issue

The K8s charm still carried its own copy of the update_config subsystem — parameter building, Patroni REST API patching, K8s replication-slot sync, restart handling, and config/user-hash persistence — duplicating logic the single-kernel library now owns. The VM charm already adopted the library's update_config (canonical/postgresql-operator#1849); while the duplication remains, the two substrates drift apart on every future config change.

Solution

Delegate to the library's ConfigManager.update_config and drop the charm's copy:

  • Construct the 7-arg ConfigManager (state, workload, tls_manager, patroni_manager + three charm-side bridge callbacks request_restart/refresh_endpoints/restart_services) so the library drives the K8s-specific pebble/metrics side effects without reaching into charm internals.
  • update_config becomes a thin wrapper that delegates and catches DeployedWithoutTrustError — the library's K8s workload now raises this typed exception on a 403 instead of a raw ApiError, and the charm re-surfaces its existing "deployed without trust" blocked status.
  • Delete the now-migrated charm methods (_build_postgresql_parameters, the worker-calc family, _api_update_config, _handle_postgresql_restart_need, generate_config_hash, is_restart_pending) and the charm-local templates/patroni.yml.j2 (the library owns the merged substrate-conditional template).
  • Pin the library at the archive of its update_config migration commit with the k8s extra (lightkube). Unreleased pin — this is stacked on test(integration): add async-replication-over-TLS coverage (K8s) #1619 (base test/async-replication-tls) and draft until the library releases.

Unit suite is green consuming the library (137 passed): 14 migrated-away tests removed, 5 added covering the three bridges, the delegation, and the DeployedWithoutTrust catch.

Checklist

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

The single-kernel PostgreSQL library now owns the full update_config
subsystem (parameter building, Patroni API patching, K8s slot sync,
restart handling, and hash persistence), matching the already-adopted
VM charm. Duplicating this logic in both places would let the two
substrates drift out of sync on every future config change, so the
charm delegates to the lib's ConfigManager instead of keeping its own
copy.

The charm now constructs a 7-arg ConfigManager wired with 3 bridge
callbacks (request_restart, refresh_endpoints, restart_services) so
the lib can trigger K8s-specific pebble/metrics side effects without
depending on charm internals directly. update_config becomes a thin
wrapper that also catches DeployedWithoutTrustError, since the lib's
K8s workload now raises this on a 403 instead of a raw ApiError.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
@github-actions github-actions Bot added the Libraries: Out of sync The charm libs used are out-of-sync label Jul 11, 2026
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>
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