Skip to content
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

docs: clarify where StoredState is stored, and the upgrade behaviour #1416

Merged

Conversation

tonyandrewmeyer
Copy link
Contributor

Adjustments to the StoredState documentation:

  • For StoredDict, StoredList, and StoredSet, note that charms would not normally create these directly and would use StoredState instead.
  • Explain where the data is stored (there is one case that it doesn't mention, where there is already a unit-state DB locally, but I think that complicates things too much to specify here).
  • Explain what happens when the charm is upgraded and recommend using a peer relation over stored state for K8s charms that want data preserved across upgrades.

As a related drive-by: remove the jujuremoved tag for use_juju_for_storage, since this won't actually be going away with Juju 4.0.

Fixes #1270

ops/framework.py Outdated

Charms are not expected to use this class directly. Adding a
:class:`StoredState` attribute to a charm class will automatically use this
class to store dictionary-like data.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does Ops know whether to create a StoredDict, StoredList, or StoredSet when you create/access a _stored attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you set the attribute it gets wrapped and similarly unwrapped when accessed.

It does an isinstance check so I guess the doc should say "dictionary data" rather than
dictionary-like" even though the StoredDict class is more generic.

ops/framework.py Outdated
Comment on lines 1150 to 1159
Data is stored alongside the charm (in the charm container for Kubernetes
sidecar charms, and on the machine for machine charms), except for podspec
charms and charms explicitly passing `True` for `use_juju_for_storage` when
running :meth:`ops.main` (in those cases, the data is stored in Juju).

For machine charms, charms are upgraded in-place on the machine, so the data
is preserved. For Kubernetes sidecar charms, when the charm is upgraded, the
pod is replaced, so any data is lost. When data should be preserved across
upgrades, Kubernetes sidecar charms should use a peer-relation for the data
instead of `StoredState`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random ideas -- I know that use_juju_for_storage isn't actually going away with 4.0, but do we want to continue to steer people away from it?

We could mention podspec charms going away in future? e.g.

"except for podspec charms (deprecated in favour of sidecare charms), where the data is stored in Juju."

And maybe move the bit about use_juju_for_storage to after the good recommendation in the last paragraph for preserving data across upgrades? e.g. as a final sentence:

"To explicitly opt into Juju data storage, set use_juju_for_storage to True when running :meth:ops.main (but this is not recommended)."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podspec charms are deprecated, aren't they? Second guessing myself ..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podspec charms are deprecated, aren't they? Second guessing myself ..

Yes :). You have to find that info in the Juju docs, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adjusted it to mention podspec and use_juju_for_storage being deprecated - I agree that's worth doing.

I don't think the use_juju_for_storage mention should be at the end, though - even with a "this is not recommended" I think it promotes it too much saying that it's a way to opt in. We don't want people doing this (and they'll get a warning if they do) - it's mentioned here so people that are doing it know that it is a consequence, but if they want the storage to be in Juju then they should use a peer relation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@tonyandrewmeyer tonyandrewmeyer merged commit 2d6ab02 into canonical:main Oct 10, 2024
30 checks passed
@tonyandrewmeyer tonyandrewmeyer deleted the improve-storedstate-docs-1270 branch October 10, 2024 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation is missing for StoredState behavior
3 participants