Contents · The machine charm

pkgproxy design: the machine charm

The Juju charm that runs the snap on a machine. Part of the pkgproxy design, whose index says which file holds each § number.

31. The machine charm: the snap, with Juju

charms/pkgproxy/ is pkgproxy, a machine charm written with ops and packed with charmcraft’s uv plugin, for Ubuntu 24.04 and 26.04, amd64 only for now (gitlab.com/zygoon/pkgproxy#182). It runs the pkgproxy snap, as the shared package cache of the machines around it. It shares src/common.py with the Kubernetes charm (§30), and has its actions, stats, invalidate and setup-script, so that the two are run the same way: each runs the snap’s pkgproxyctl, and setup-script gives the address of public-url, else of the unit (its juju-info binding’s ingress address).

31.1 The snap it installs

The charm installs pkgproxy from the store at the revision snap.toml, next to charmcraft.yaml, pins for the machine’s architecture (uname -m), and holds it there with snap refresh --hold: a revision of the charm always installs the same build of the snap, signed, and the snap changes only when the charm does, with juju refresh, which refreshes it to the new charm’s pin. snap.toml pins an aarch64 revision too, as pin-snap writes one for each architecture the store has, although the charm is packed for amd64 alone: the aarch64 pin waits for gitlab.com/zygoon/pkgproxy#182.

snap.toml in the tree pins a released snap, for a charm packed by hand. The jobs that publish the charm (§30.9) pin the snaps CI built from the same commit: they need snap-edge or snap-stable, which upload them to the store, and charms/pkgproxy/pin-snap rewrites snap.toml in each packed charm with the store’s revisions of the snap’s version. That version is the charm’s own, git describe of the commit, in the snap’s spelling: v0.12.1-6-g169a226 is v0.12.1+git6.169a226, and a tag is itself. The hashes need only agree in their common prefix: git abbreviates a hash to however many characters the clone needs, so the charm’s may be longer than the snap’s or shorter. The job fails when the store has no amd64 build of it. Deploying such a deployment again from GitLab works only while the store’s channels still offer that version.

A non-empty pkgproxy-snap file resource is installed with snap install --dangerous in its place, at install and when a new one is attached. The tests deploy the charm with the snap of the same pipeline that way. A released revision has no resource: it installs its pin.

31.2 Options

The options are the Kubernetes charm’s, without service-type, and are set with snap set pkgproxy, as the snap’s options are the daemon’s flags (snap/local/bin/pkgproxy-env). Each is set when it differs from its default and unset (KEY!) otherwise, so the daemon’s default stays the only default; lxd-tls=false sets lxd-tls-addr=off. The model’s proxy settings set http-proxy, https-proxy and no-proxy, which are unset without them, so the snap takes /etc/environment’s.

The snap’s configure hook runs pkgproxy -check-config, so the charm has no validation of its own: when the hook fails, snapd keeps the last good options, and the charm is blocked with the hook’s last line, the daemon’s message. TestMachineCharmOptionsAreSnapOptions keeps each option one that pkgproxy-env maps.

31.3 Storage, ports and status

The optional cache storage is mounted at /var/snap/pkgproxy/common/cache, the snap’s cache directory; without it the cache is on the machine’s root disk. The charm opens 3142, and 3143 unless lxd-tls is false, so juju expose works.

The status is the first that applies: blocked when the storage does not keep extended attributes, or when the configure hook refused the options; waiting while pkgproxy does not answer its health route; active, with the same message as the Kubernetes charm’s when pkgproxy is offline (§30.6).