-
Notifications
You must be signed in to change notification settings - Fork 1
feat(garm-configurator): integrate with image builder via github_runner_image_v0 #222
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
Open
cbartz
wants to merge
2
commits into
main
Choose a base branch
from
feat/image-builder-integration-ISD-5735
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+366
−34
Open
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
|
|
||
| import ops | ||
|
|
||
| from charm_state import CharmConfigInvalidError, CharmState | ||
| from charm_state import IMAGE_RELATION_NAME, CharmConfigInvalidError, CharmState | ||
|
|
||
|
|
||
| class GarmConfiguratorCharm(ops.CharmBase): | ||
|
|
@@ -21,29 +21,49 @@ def __init__(self, *args: typing.Any) -> None: | |
| args: passthrough to CharmBase. | ||
| """ | ||
| super().__init__(*args) | ||
| self.framework.observe(self.on.config_changed, self._on_config_changed) | ||
| self.framework.observe(self.on.collect_unit_status, self._on_collect_unit_status) | ||
| for event in [ | ||
| self.on.config_changed, | ||
| self.on.secret_changed, | ||
| self.on[IMAGE_RELATION_NAME].relation_joined, | ||
| self.on[IMAGE_RELATION_NAME].relation_changed, | ||
| self.on[IMAGE_RELATION_NAME].relation_broken, | ||
| ]: | ||
|
cbartz marked this conversation as resolved.
|
||
| self.framework.observe(event, self._reconcile) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. holistic pattern |
||
|
|
||
| def _on_config_changed(self, _event: ops.ConfigChangedEvent) -> None: | ||
| """Validate configuration on config-changed.""" | ||
| try: | ||
| CharmState.from_charm(self) | ||
| except CharmConfigInvalidError as e: | ||
| self.unit.status = ops.BlockedStatus(e.msg) | ||
| return | ||
| def _reconcile(self, event: ops.EventBase) -> None: | ||
| """Reconcile all charm state for every event. | ||
|
|
||
| def _on_collect_unit_status(self, event: ops.CollectStatusEvent) -> None: | ||
| """Handle collect-unit-status event. | ||
| Reads full current state and acts idempotently: forwards OpenStack | ||
| credentials to the image builder relation, and reports unit status. | ||
|
|
||
| Args: | ||
| event: The collect status event. | ||
| event: The triggering event. | ||
| """ | ||
| try: | ||
| CharmState.from_charm(self) | ||
| state = CharmState.from_charm(self) | ||
| except CharmConfigInvalidError as e: | ||
| self.unit.status = ops.BlockedStatus(e.msg) | ||
| return | ||
| event.add_status(ops.ActiveStatus("Ready")) | ||
|
|
||
| relation = self.model.get_relation(IMAGE_RELATION_NAME) | ||
| if relation is not None: | ||
| relation.data[self.unit].update( | ||
| { | ||
| "auth_url": state.provider_config.auth_url, | ||
| "password": state.provider_config.password, | ||
| "project_domain_name": state.provider_config.project_domain_name, | ||
|
cbartz marked this conversation as resolved.
|
||
| "project_name": state.provider_config.project_name, | ||
| "user_domain_name": state.provider_config.user_domain_name, | ||
| "username": state.provider_config.username, | ||
| } | ||
| ) | ||
|
|
||
| if relation is None: | ||
| self.unit.status = ops.WaitingStatus("Waiting for image builder relation") | ||
| elif state.image_id is None: | ||
| self.unit.status = ops.WaitingStatus("Waiting for image UUID from image builder") | ||
| else: | ||
|
cbartz marked this conversation as resolved.
|
||
| self.unit.status = ops.ActiveStatus("Ready") | ||
|
cbartz marked this conversation as resolved.
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
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.
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.