Skip to content

feat: add 20.04 base and downgrade ops - #43

Merged
sinapah merged 7 commits into
mainfrom
feat/pack-for-focal
Sep 1, 2026
Merged

sinapah merged 7 commits into
mainfrom
feat/pack-for-focal

Conversation

@sinapah

@sinapah sinapah commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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

  1. Remove JujuContext. We used it to get principal_unit, availability_zone, and hook_name. Those attributes don't exist in JujuContext in Ops 2.
  2. Since we don't have JujuContext, we can't determine using env vars in the middle of the hook what event we are processing. Hence, rather than using if statements to get the event and return early if the event is a remove event, we'll observe install, upgrade, remove. We'll reconcile on all except remove, which is part of the "non reconcilable events".

Checklist

  • I have added or updated relevant documentation.
  • PR title makes an appropriate release note and follows conventional commits syntax.
  • Merge target is the correct branch, and relevant tandem backport PRs opened.

Context

Testing Instructions

All of these bundles should result in a healthy and functional deployment.

20.04

default-base: ubuntu@20.04/stable
applications:
  be:
    charm: local:blackbox-exporter-1
  ubuntu:
    charm: ubuntu
    channel: latest/stable
    revision: 26
    num_units: 1
    to:
    - "0"
    constraints: arch=amd64
    storage:
      block: loop,100M
      files: rootfs,100M
machines:
  "0":
    constraints: arch=amd64
relations:
- - ubuntu:juju-info
  - be:juju-info

22.04

default-base: ubuntu@22.04/stable
applications:
  be:
    charm: local:blackbox-exporter-0
  ubuntu:
    charm: ubuntu
    channel: latest/stable
    revision: 77
    num_units: 1
    to:
    - "0"
    constraints: arch=amd64
    storage:
      block: loop,100M
      files: rootfs,100M
machines:
  "0":
    constraints: arch=amd64
relations:
- - ubuntu:juju-info
  - be:juju-info

24.04

default-base: ubuntu@24.04/stable
applications:
  be:
    charm: local:blackbox-exporter-0
  ubuntu:
    charm: ubuntu
    channel: latest/stable
    revision: 79
    num_units: 1
    to:
    - "0"
    constraints: arch=amd64
    storage:
      block: loop,100M
      files: rootfs,100M
machines:
  "0":
    constraints: arch=amd64
relations:
- - ubuntu:juju-info
  - be:juju-info

Upgrade Notes

@sinapah
sinapah marked this pull request as ready for review August 27, 2026 21:03
@sinapah sinapah changed the title feat: pack for focal feat: Pack for focal Aug 31, 2026
Comment thread src/charm.py
Comment on lines -44 to -46
def juju_context(arg: str):
"""Return Juju env variables."""
return getattr(JujuContext.from_environ(), arg)

@sinapah sinapah Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread src/charm.py
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread src/charm.py
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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@lucabello lucabello changed the title feat: Pack for focal feat: add 20.04 base and downgrade ops Sep 1, 2026

@lucabello lucabello left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but please deploy this yourself on both 20.04 and a newer base, and do some manual testing before merging!

@sinapah
sinapah merged commit f63dc24 into main Sep 1, 2026
15 checks passed
@sinapah
sinapah deleted the feat/pack-for-focal branch September 1, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pack for focal

3 participants