feat: add 20.04 base and downgrade ops - #43
Merged
Merged
Conversation
sinapah
marked this pull request as ready for review
August 27, 2026 21:03
sinapah
commented
Aug 31, 2026
Comment on lines
-44
to
-46
| def juju_context(arg: str): | ||
| """Return Juju env variables.""" | ||
| return getattr(JujuContext.from_environ(), arg) |
Contributor
Author
There was a problem hiding this comment.
This is one of the most important removals in going from ops 3 to Ops 2. JujuContext does exist in Ops 2, but none of the attributes we need from it exist in that version. See the Solution field in the PR description for details.
sinapah
commented
Aug 31, 2026
Comment on lines
+131
to
+140
| @property | ||
| def _principal_unit_name(self) -> str: | ||
| """Return the name of the principal unit this subordinate is attached to.""" | ||
| relation = self.model.get_relation("juju-info") | ||
| if not relation: | ||
| return "" | ||
| principals = relation.units | ||
| if not principals: | ||
| return "" | ||
| return next(iter(principals)).name |
Contributor
Author
There was a problem hiding this comment.
Note: we have to do this because unlike ops 3 which provides the principal unit through an env var, there is no native way in Ops 2 to get this.
sinapah
commented
Aug 31, 2026
Comment on lines
+110
to
+113
| self.framework.observe( | ||
| self.on[PEERS_RELATION_NAME].relation_joined, self._on_peers_relation_joined | ||
| ) | ||
| observe_events(self, all_events.difference(NON_RECONCILABLE_EVENTS), self._reconcile) |
Contributor
Author
There was a problem hiding this comment.
lucabello
approved these changes
Sep 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue
We need to pack this charm for Focal. However, previously, some of the logic in this charm was written with Ops 3 features. To enable packing for Focal, we should rewrite such logic using Ops 2.
Fixes #44.
A good example charm to look at to see how this should be implemented would be https://github.com/canonical/script-exporter-operator/.
Solution
JujuContext. We used it to getprincipal_unit,availability_zone, andhook_name. Those attributes don't exist inJujuContextin Ops 2.JujuContext, we can't determine using env vars in the middle of the hook what event we are processing. Hence, rather than usingifstatements to get theeventand return early if the event is aremoveevent, we'll observeinstall,upgrade,remove. We'll reconcile on all exceptremove, which is part of the "non reconcilable events".Checklist
Context
Testing Instructions
All of these bundles should result in a healthy and functional deployment.
20.04
22.04
24.04
Upgrade Notes