Skip to content

[DPE-10875] refactor(config): inject the resource provider instead of routing via state - #215

Open
marceloneppel wants to merge 1 commit into
16/edgefrom
refactor/inject-resource-provider
Open

[DPE-10875] refactor(config): inject the resource provider instead of routing via state#215
marceloneppel wants to merge 1 commit into
16/edgefrom
refactor/inject-resource-provider

Conversation

@marceloneppel

@marceloneppel marceloneppel commented Aug 17, 2026

Copy link
Copy Markdown
Member

Issue

CharmState carries a resource_provider slot that the charm assigns after construction, and an available_resources property that raises RuntimeError when nobody set it. ConfigManager is the only consumer, so the state class is acting as a service locator for a single manager's dependency. Raised by @akram09 in review on #182 and again on #183.

Solution

Hand the provider to ConfigManager directly and drop both the slot and the property, so the "not set" failure mode stops being representable. Each charm exposes it through a get_resource_provider() method (abstract on the base charm, returning the K8s manager or the VM workload), and the manager resolves the getter on use.

It is injected as a getter rather than an instance because the K8s manager that supplies it is constructed after ConfigManager in the charm's __init__ — the same late binding the existing charm bridges already use, so no construction reordering is needed. The injected type is the existing ResourceProvider protocol rather than a K8s client, since the VM charm satisfies it through its workload and K8sManager is not importable on VM.

Checklist

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

@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.

Thank you !

Base automatically changed from tls-files-pushed to 16/edge August 18, 2026 16:07
… state

CharmState carried a resource_provider slot the charm assigned after
construction, plus an available_resources property that raised when nobody had
set it. ConfigManager is the only consumer, so the state class was acting as a
service locator for one manager's dependency.

Hand the provider to ConfigManager directly. It arrives as a getter because the
K8s manager that supplies it is built after ConfigManager in the charm's
__init__, which is the same late-binding the restart and endpoint bridges
already use.

Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
@marceloneppel
marceloneppel force-pushed the refactor/inject-resource-provider branch from d87aa73 to ca66992 Compare August 18, 2026 18:23
@marceloneppel marceloneppel changed the title refactor(config): inject the resource provider instead of routing via state [DPE-10875] refactor(config): inject the resource provider instead of routing via state Aug 19, 2026
@marceloneppel
marceloneppel marked this pull request as ready for review August 19, 2026 18:51
@marceloneppel
marceloneppel requested a review from a team as a code owner August 19, 2026 18:51
@marceloneppel
marceloneppel requested review from carlcsaposs-canonical, dragomirp, juju-charm-bot and taurus-forever and removed request for a team August 19, 2026 18:51
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.

2 participants