Should use use_juju_for_storage=True and StoredState instead of direct state-set/state-get calls
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
charm-k8s-mattermost |
Fix Released
|
Medium
|
Paul Collins |
Bug Description
For operator framework 0.7 we are landing support for charms to maintain their state in Juju (using state-set and state-get) with our existing StoredState objects.
The actual patch that landed is here: https:/
With a bugfix for charms that have metrics.yaml here: https:/
0.7.0 with these fixes should be out later today.
That would change charm.py to use:
main(
And would mean you shouldn't need the charmstate.py file.
Likely you would need to keep state-get at least to have an 'upgrade_charm' event handler that would migrate from the existing state that has been set. Something like:
from ops.framework import StoredState
class MatterMostCharm
...
_stored = StoredState()
...
def __init__(self):
...
self.
db_uri=None,
db_
db_
)
def _on_upgrade_
if self._stored.db_uri is None:
old_uri = state_get('db_uri')
if old_uri is not None:
# optionally, not actually implemented by charmstate.py yet
The 'set_default' is necessary to declare them as attributes of _stored, so at any point you can do
if self._stored.db_uri is None:
The upgrade_charm is necessary if you want to migrate from previous state.
Related branches
- Stuart Bishop (community): Approve
- Mattermost Charmers: Pending requested
-
Diff: 155 lines (+44/-21)2 files modifiedsrc/charm.py (+38/-13)
src/charmstate.py (+6/-8)
Changed in charm-k8s-mattermost: | |
importance: | Undecided → Medium |
status: | New → Triaged |
Changed in charm-k8s-mattermost: | |
status: | Triaged → In Progress |
assignee: | nobody → Paul Collins (pjdc) |
Changed in charm-k8s-mattermost: | |
status: | In Progress → Fix Released |