-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Add relation for s3 interface on the provider side #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2e1d47d
feat: Add support for s3 interface
mvlassis 779dd26
fix linting
mvlassis 8abffe6
Spelling fix
mvlassis 9e3cc1b
Add unit test
mvlassis ae0589b
Add unit test
mvlassis 9def4ea
Use same import as other components in s3_component.py
mvlassis 80c8104
Fix docstring
mvlassis f426817
Update src/components/s3_provider_component.py
mvlassis 4c3cf9f
Resolve comments
mvlassis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
| """Component for interacting with S3-compatible object storage via the s3 interface. | ||
|
|
||
| This component uses the S3Provider interface, provided by the object-storage-charmlib library. | ||
| See: https://github.com/canonical/object-storage-integrator/tree/main/s3 | ||
| """ | ||
|
|
||
| import dataclasses | ||
| import logging | ||
|
|
||
| from charmed_kubeflow_chisme.components import Component | ||
| from object_storage import ( | ||
| PrematureDataAccessError, | ||
| S3Provider, | ||
| StorageConnectionInfoRequestedEvent, | ||
| ) | ||
| from ops import ActiveStatus, BlockedStatus, StatusBase, WaitingStatus | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
| class S3ProviderInputs: | ||
| """Defines the required inputs for S3ProviderComponent.""" | ||
|
|
||
| ENDPOINT: str | ||
| ACCESS_KEY: str | ||
| SECRET_KEY: str | ||
|
|
||
|
|
||
| class S3ProviderComponent(Component): | ||
| """Component that manages an S3-compatible object storage relation. | ||
|
|
||
| Publishes endpoint and credentials to related requirers using the `s3` interface. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| *args, | ||
| relation_name: str, | ||
| is_optional: bool = False, | ||
| **kwargs, | ||
| ): | ||
| """Initialise the component. | ||
|
|
||
| Args: | ||
| relation_name: Name of the S3 relation endpoint. | ||
| is_optional: When True, the component is Active even if no relation is present. | ||
| """ | ||
| super().__init__(*args, **kwargs) | ||
| self.relation_name = relation_name | ||
| self.is_optional = is_optional | ||
| self.s3_provider = S3Provider( | ||
| charm=self._charm, | ||
| relation_name=relation_name, | ||
| ) | ||
| self._events_to_observe = [ | ||
| self._charm.on[self.relation_name].relation_changed, | ||
| self._charm.on[self.relation_name].relation_broken, | ||
| self.s3_provider.on.storage_connection_info_requested, | ||
| ] | ||
|
|
||
| def _configure_unit(self, event): | ||
| """Execute everything this Component should do for every Unit.""" | ||
| if not self._charm.unit.is_leader(): | ||
| return | ||
|
|
||
| inputs: S3ProviderInputs = self._inputs_getter() | ||
| data = { | ||
| "endpoint": inputs.ENDPOINT, | ||
| "access-key": inputs.ACCESS_KEY, | ||
| "secret-key": inputs.SECRET_KEY, | ||
|
mvlassis marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if isinstance(event, StorageConnectionInfoRequestedEvent): | ||
| relation_ids = [event.relation.id] | ||
| else: | ||
| relation_ids = list(self.s3_provider.fetch_relation_data().keys()) | ||
|
|
||
| for relation_id in relation_ids: | ||
| try: | ||
| self.s3_provider.set_storage_connection_info(relation_id=relation_id, data=data) | ||
| except PrematureDataAccessError: | ||
| logger.warning("Relation %s not yet initialised, skipping.", relation_id) | ||
|
NohaIhab marked this conversation as resolved.
|
||
|
|
||
| def get_status(self) -> StatusBase: | ||
| """Return the status of this component. | ||
|
|
||
| - Blocked: no relation present and component is not optional. | ||
| - Active: no relation present and component is optional. | ||
| - Waiting: relation is present but no requirer has initialised the protocol yet. | ||
| - Active: at least one relation is fully initialised. | ||
| """ | ||
| relations = self._charm.model.relations[self.relation_name] | ||
|
|
||
| if not relations: | ||
| if self.is_optional: | ||
| return ActiveStatus() | ||
| return BlockedStatus(f"Please add the missing relation: {self.relation_name}") | ||
|
|
||
| if not any(self.s3_provider.is_protocol_ready(relation) for relation in relations): | ||
| return WaitingStatus(f"Waiting for {self.relation_name} relation to be initialised") | ||
|
|
||
| return ActiveStatus() | ||
|
NohaIhab marked this conversation as resolved.
|
||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.