Repository navigation
refactor(garm-configurator): define required relation fields (ISD-7629) - #468
Thanhphan1147 wants to merge 2 commits into
Conversation
290ca55 to
9f23019
Compare
…ion (ISD-7629) Mark the provider and scaleset fields that block provider, credential, or scaleset creation as required in the shared relation model, rejecting blank values, and give the optional fields GARM's defaults. The configurator now publishes nothing until every required value, including the image, is available, withdrawing an older payload instead of writing an incomplete one.
…7629) Publish the newly required provider and scaleset fields in the garm unit fixtures, treat a payload missing a required field as an invalid relation, and bump the shared relation-library pin. Document the required fields and the configurator's publish-only-when-complete behaviour.
cbd896e to
4efc035
Compare
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _reject_blank(value: str, info: pydantic.ValidationInfo) -> str: |
There was a problem hiding this comment.
Update the name to validate_field_not_empty
| if state.image is None: | ||
| self._withdraw_garm_relation(garm_relation) | ||
| return |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
🟡 Changes recommended
Active issues remain because whitespace-only credentials and entity fields are accepted, and withdrawing one configurator’s databag can delete existing provider and scaleset resources despite the intended preservation behavior.
3 open issues
What changed in this PR
This PR formalizes the garm-configurator relation contract so provider and scaleset payloads cannot be created from incomplete required fields. It updates both charms, shared relation models, tests, dependency pinning, and documentation.
Changes:
- Marks provider and scaleset fields as required, validates relation payloads, and applies explicit defaults to optional fields.
- Makes the configurator withhold or withdraw relation data until a complete payload, including an image, is available.
- Updates GARM/configurator tests, documentation, changelog, and the shared relation-library pin.
| File | Description |
|---|---|
| docs/reference/charms.md | Documents the required and optional configurator relation fields and behavior. |
| docs/changelog.md | Records the relation-contract and image-publication changes. |
| charms/garm/tests/unit/test_charm.py | Updates GARM tests for invalid relation payloads and missing images. |
| charms/garm/tests/unit/test_charm_state.py | Adapts relation-state fixtures and tests to the stricter shared models. |
| charms/garm/requirements.txt | Pins the GARM charm to the updated shared relation-library revision. |
| charms/garm-configurator/tests/unit/test_garm_configurator_relation.py | Adds coverage for required fields, defaults, entity exclusivity, and invalid payload handling. |
| charms/garm-configurator/tests/unit/test_charm.py | Tests complete-payload publication and withdrawal behavior when images are unavailable. |
| charms/garm-configurator/src/charm.py | Publishes complete relation data and withdraws payloads when required values, including the image, are unavailable. |
| charms/garm-configurator/lib/garm_configurator_relation.py | Defines the shared provider and scaleset relation models, validation rules, and optional defaults. |
Review effort: Lite
| if state.image is None: | ||
| self._withdraw_garm_relation(garm_relation) | ||
| return |
| if not (self.openstack_password or self.openstack_password_secret_uri): | ||
| raise ValueError( | ||
| "one of openstack_password or openstack_password_secret_uri is required" | ||
| ) |
| if bool(self.org) == bool(self.repo): | ||
| raise ValueError("exactly one of org or repo is required") |


What this PR does
Defines the required and optional fields of the
garm-configuratorrelation and enforces the contract from both sides.garm_configurator_relationmodels now mark the provider and scaleset fields that block provider, credential, or scaleset creation as required and reject blank values. Required provider fields are the OpenStack URL/user/project/domains/region/network, the GitHub App ids and private-key secret URI, and a password source. Required scaleset fields are the name, provider name, image, flavor, architecture, and exactly one of org or repo.min_idle_runner="0",max_runner="1",runner_group="Default", and so on) instead of defaulting to an empty string.garm-configuratorpublishes its relation payload only when every required value, including the image, is available. While the image builder has not supplied an image, it withdraws any older payload rather than writing an incomplete one. If a required config value is missing, the charm blocks before writing.garmcontinues to mark a relation with an incomplete or malformed payload as invalid and blocks rather than rendering a partial provider or scaleset.This is the relation-contract part of ISD-7629 (spec reference: ISD303). LXD provider support itself remains out of scope.
Why we need it
The relation databag previously gave every field an empty-string default, so neither side could tell which fields actually gate provider or scaleset creation. An incomplete payload could look valid, and the configurator could publish a scaleset without an image. Making the blocking fields required, and the fields with sensible defaults explicitly optional, gives the two charms one clear contract.
Test plan
tox -c tox.toml -e unitincharms/garm-configurator— 97 passed.tox -c tox.toml -e fmt,lint,complexity,staticincharms/garm-configurator— all pass.tox -c tox.toml -e unitincharms/garm— 480 passed, recreated against the bumped relation-library pin.tox -c tox.toml -e fmt,lint,complexity,staticincharms/garm— all pass.tox -c tox.toml -e coverage-reportin both charms — garm-configurator 96% total.make -C docs spellcheck— 0 errors.go test ./...— all packages pass.Review focus
openstack_password(kept for backwards compatibility) oropenstack_password_secret_uri; the configurator publishes the secret URI.eef25b8from this branch, so CI installs the updated shared package.Potential breaking changes
garm-configuratorpayload that omits a now-required field, or carries a blank value for one, is invalid and makes the GARM charm block instead of creating a partial provider or scaleset.Checklist
CONTRIBUTING.mdhas been updated upon changes to the contribution/development process (not applicable)docs/reference/charms.mdanddocs/changelog.md)docs/changelog.mdwith user-relevant changesterraform fmtpasses andtflintreports no errors (not applicable)AGENTS.md(not applicable).copilot-collections.yamlor.github/instructions/: I re-checked whether theAGENTS.md"12-factor divergences" guidance still matches the upstream copilot-collections guidance (not applicable)