Repository navigation
refactor(garm-configurator): define required relation fields (ISD-7629) #468
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
Thanhphan1147
wants to merge
2
commits into
houston/ISD-7628
Choose a base branch
from
houston/ISD-7629
base: houston/ISD-7628
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.
+470
−151
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
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 |
|---|---|---|
|
|
@@ -49,9 +49,9 @@ def _reconcile(self, event: ops.EventBase) -> None: | |
|
|
||
| Only the leader unit publishes configurator data, so a non-leader blocks before doing | ||
| any work. The leader reads the current charm state, forwards OpenStack credentials to | ||
| the image-builder relation, publishes scaleset configuration (and secrets when the image | ||
| reference is available) to the garm-configurator relations' application databags, then | ||
| sets unit status to reflect readiness. | ||
| the image-builder relation, publishes the complete scaleset configuration (with secrets) | ||
| to the garm-configurator relations' application databags once every required value, | ||
| including the image, is available, then sets unit status to reflect readiness. | ||
|
|
||
| Args: | ||
| event: The triggering event. | ||
|
|
@@ -155,6 +155,12 @@ def _configure_garm_relation(self, state: CharmState) -> None: | |
| published before an image is configured and are retained when an image is withdrawn. | ||
| Only the leader reaches this method, so the application databag has a single writer. | ||
|
|
||
| The relation contract marks the fields that block provider or scaleset creation as | ||
| required. The configurator therefore publishes nothing until every one of them is | ||
| available: while the image builder has not supplied an image yet, it withdraws any | ||
| previously published payload instead of writing one the consumer would reject as | ||
| incomplete. | ||
|
|
||
| Does nothing when no garm-configurator relation is joined yet. Status reporting is | ||
| handled by the caller (_reconcile). | ||
|
|
||
|
|
@@ -164,6 +170,9 @@ def _configure_garm_relation(self, state: CharmState) -> None: | |
| garm_relation = self.model.get_relation(GARM_RELATION_NAME) | ||
| if garm_relation is None: | ||
| return | ||
| if state.image is None: | ||
| self._withdraw_garm_relation(garm_relation) | ||
| return | ||
|
Comment on lines
+173
to
+175
Contributor
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. Dont clear the relation data here, as misconfiguring can happen and that'll break a working deployment. We need to validate new changes but never wipe old data if the new data is invalid
Comment on lines
+173
to
+175
|
||
|
|
||
| password_secret = self._ensure_relation_secret( | ||
| garm_relation, | ||
|
|
@@ -175,13 +184,15 @@ def _configure_garm_relation(self, state: CharmState) -> None: | |
| "configurator-github-key", | ||
| state.github_app_config.private_key, | ||
| ) | ||
| if password_secret is None or github_key_secret is None: | ||
| return | ||
|
|
||
| pre_install = state.scaleset_config.pre_install_scripts | ||
| rc = state.runner_config | ||
| scaleset_data: dict[str, str] = { | ||
| "name": state.scaleset_config.name, | ||
| "provider_name": state.provider_config.provider_name, | ||
| "image_id": state.image or "", | ||
| "image_id": state.image, | ||
| "image_visibility": state.scaleset_config.image_visibility or "", | ||
| "security_group": state.scaleset_config.security_group, | ||
| "flavor": state.scaleset_config.flavor, | ||
|
|
@@ -211,25 +222,37 @@ def _configure_garm_relation(self, state: CharmState) -> None: | |
| provider=RelationProviderConfig( | ||
| openstack_auth_url=state.provider_config.auth_url, | ||
| openstack_username=state.provider_config.username, | ||
| openstack_password_secret_uri=( | ||
| str(password_secret.id) if password_secret is not None else None | ||
| ), | ||
| openstack_password_secret_uri=str(password_secret.id), | ||
| openstack_project_name=state.provider_config.project_name, | ||
| openstack_user_domain_name=state.provider_config.user_domain_name, | ||
| openstack_project_domain_name=state.provider_config.project_domain_name, | ||
| openstack_region_name=state.provider_config.region_name, | ||
| openstack_network=state.provider_config.network, | ||
| github_app_id=state.github_app_config.app_id, | ||
| github_installation_id=state.github_app_config.installation_id, | ||
| github_private_key_secret_uri=( | ||
| str(github_key_secret.id) if github_key_secret is not None else None | ||
| ), | ||
| github_private_key_secret_uri=str(github_key_secret.id), | ||
| ), | ||
| scaleset=RelationScalesetConfig(**scaleset_data), | ||
| ), | ||
| self.app, | ||
| ) | ||
|
|
||
| def _withdraw_garm_relation(self, relation: ops.Relation) -> None: | ||
| """Remove this application's payload from the garm-configurator relation. | ||
|
|
||
| Used while a required value, such as the runner image, is not available. Leaving an | ||
| older payload in place would keep publishing a configuration the operator has already | ||
| changed, and writing a partial one would make the consumer reject the relation. | ||
|
|
||
| Args: | ||
| relation: The garm-configurator relation to withdraw from. | ||
| """ | ||
| if relation.data[self.app]: | ||
| logger.info( | ||
| "Withdrawing garm-configurator relation data until required values are available" | ||
| ) | ||
| relation.data[self.app].clear() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ops.main(GarmConfiguratorCharm) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the name to
validate_field_not_empty