[DPE-10875] refactor(config): inject the resource provider instead of routing via state - #215
Open
marceloneppel wants to merge 1 commit into
Open
[DPE-10875] refactor(config): inject the resource provider instead of routing via state#215marceloneppel wants to merge 1 commit into
marceloneppel wants to merge 1 commit into
Conversation
… 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
force-pushed
the
refactor/inject-resource-provider
branch
from
August 18, 2026 18:23
d87aa73 to
ca66992
Compare
marceloneppel
marked this pull request as ready for review
August 19, 2026 18:51
marceloneppel
requested review from
carlcsaposs-canonical,
dragomirp,
juju-charm-bot and
taurus-forever
and removed request for
a team
August 19, 2026 18:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
CharmStatecarries aresource_providerslot that the charm assigns after construction, and anavailable_resourcesproperty that raisesRuntimeErrorwhen nobody set it.ConfigManageris 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
ConfigManagerdirectly and drop both the slot and the property, so the "not set" failure mode stops being representable. Each charm exposes it through aget_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
ConfigManagerin 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 existingResourceProviderprotocol rather than a K8s client, since the VM charm satisfies it through its workload andK8sManageris not importable on VM.Checklist