Skip to content

[DPE-10738] feat(config): port PostgreSQL parameter building + resource introspection (2/6)#182

Open
marceloneppel wants to merge 2 commits into
16/edgefrom
skl-01-update-config-2-params
Open

[DPE-10738] feat(config): port PostgreSQL parameter building + resource introspection (2/6)#182
marceloneppel wants to merge 2 commits into
16/edgefrom
skl-01-update-config-2-params

Conversation

@marceloneppel

@marceloneppel marceloneppel commented Jul 11, 2026

Copy link
Copy Markdown
Member

Issue

update_config builds PostgreSQL's bootstrap.dcs.postgresql.parameters from the unit's CPU and memory, which both charms compute per substrate. This step ports the parameter builder and the substrate resource introspection it depends on.

Solution

  • managers/config.py: _build_postgresql_parameters with the _calculate_max_* helpers and _calculate_worker_process_config(cpu_cores).
  • Workload get_available_resources() -> tuple[int, int] — VM reads os.cpu_count() and available memory; K8s reads the node/pod via lightkube and raises DeployedWithoutTrustError on a 403 ApiError.
  • New k8s optional extra (lightkube, lightkube-models) mirroring the existing vm extra, plus a regenerated uv.lock.

DeployedWithoutTrustError is raised here and caught at the charm/event layer in the charm-adoption PR (managers-raise convention). Second (code-only) PR in the update_config stack; the K8sWorkload signature gains unit_name/namespace, so the one-line fixture update needed to keep the suite green rides with the code, and the new unit tests land in the stack's test PR (#188).

Checklist

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

@marceloneppel
marceloneppel force-pushed the skl-01-update-config-1-peer-accessors branch from 22d4f17 to 10eea18 Compare July 20, 2026 13:22
@marceloneppel
marceloneppel force-pushed the skl-01-update-config-2-params branch from a7ee622 to 786d9bd Compare July 20, 2026 13:22
@marceloneppel marceloneppel changed the title feat(config): port PostgreSQL parameter building + resource introspection feat(config): port PostgreSQL parameter building + resource introspection (2/5) Jul 20, 2026
@marceloneppel marceloneppel changed the title feat(config): port PostgreSQL parameter building + resource introspection (2/5) feat(config): port PostgreSQL parameter building + resource introspection (2/6) Jul 20, 2026
@marceloneppel
marceloneppel force-pushed the skl-01-update-config-1-peer-accessors branch from 10eea18 to ee47a46 Compare July 20, 2026 19:04
@marceloneppel
marceloneppel force-pushed the skl-01-update-config-2-params branch from 786d9bd to ddf2305 Compare July 20, 2026 19:04
Base automatically changed from skl-01-update-config-1-peer-accessors to 16/edge July 21, 2026 14:38
…tion

Internalizes PostgreSQL parameter calculation (worker-process auto/cap
rules, wal_compression, memory-limit conversion) into the library so
ConfigManager owns the full config-build flow instead of stopping at a
TODO. Resource discovery (cpu_cores, memory_bytes) moves onto the
workload rather than a substrate-specific manager: get_available_memory
already lives there, ConfigManager already holds self.workload, and
K8sManager doesn't exist yet when ConfigManager is constructed in
abstract_charm - so the workload is the only place both substrates can
share a single no-branch call site.

K8sWorkload gains required unit_name/namespace constructor args so its
lightkube Pod/Node lookups can resolve "my own pod" without depending on
a charm object reference, mirroring what the K8s charm does today via
self.unit.name/self.model.name. lightkube becomes a real (not merely
transitive) dependency via a new k8s pyproject extra, matching the
version pins the K8s test charm already uses.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
@marceloneppel
marceloneppel force-pushed the skl-01-update-config-2-params branch from ddf2305 to f9a1111 Compare July 21, 2026 17:46
@marceloneppel
marceloneppel marked this pull request as ready for review July 21, 2026 20:35
@marceloneppel
marceloneppel requested a review from a team as a code owner July 21, 2026 20:35
@marceloneppel
marceloneppel requested review from carlcsaposs-canonical, dragomirp, juju-charm-bot and taurus-forever and removed request for a team July 21, 2026 20:35
@marceloneppel marceloneppel changed the title feat(config): port PostgreSQL parameter building + resource introspection (2/6) [DPE-10738] feat(config): port PostgreSQL parameter building + resource introspection (2/6) Jul 21, 2026
Comment on lines +56 to +57
self.unit_name = unit_name
self.namespace = namespace

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move the methods depending on those to the state class?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Done on ef52b09.

@akram09 akram09 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good for me

Comment on lines +56 to +57
self.unit_name = unit_name
self.namespace = namespace

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

"""Returns the system available memory in bytes."""
raise NotImplementedError

def _get_node_name_for_pod(self) -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would make sense to move the functions that communicate with k8s to a separate manager or a separate K8s client class that is used in the managers ?

@marceloneppel marceloneppel Jul 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. Done on ef52b09. It needed some more adjustments to reach a working state.

The parameter-building port placed lightkube node/pod resource lookups on K8sWorkload and injected unit_name/namespace into its constructor. Both duplicate identity the state already holds and put K8s-API code on the workload abstraction, which reviewers flagged.

Move the lookups onto K8sManager, which is already K8s-only-loaded and holds the state, sourcing pod/namespace from state.peer.unit_name and state.model_name. ConfigManager reaches the value through a new state.available_resources property backed by a per-substrate provider (the VM workload, or the K8s manager), so the call site stays substrate-agnostic and lightkube never enters the VM import graph.

Behavior is unchanged: node allocatable clamped by the container limit, 403 -> DeployedWithoutTrustError. The Node lookups drop the namespace argument, which lightkube ignores for cluster-scoped resources.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants