Kubernetes

Where to instantiate

The refresh class must be instantiated as early as possible in the charm code execution.

It must be instantiated exactly once per Juju event (once per charm code execution).

However, the refresh class must be instantiated after:

  • Your CharmSpecific subclass is defined

  • Anything referenced by your CharmSpecific callbacks (i.e. pre-refresh checks, refresh_snap) is defined

    Some of the CharmSpecific callbacks will be implemented in later steps. The instantiation may need to be moved after the callbacks are implemented

For most charms, it is simplest to instantiate the refresh class in the ops.CharmBase __init__ method.

Instantiate charm_refresh.Kubernetes

Example charm.py
class PostgreSQLCharm(ops.CharmBase):
    def __init__(self, *args):
        # [...]

        self.refresh = charm_refresh.Kubernetes(
            KubernetesPostgreSQLRefresh( (1)
                workload_name="PostgreSQL", (2)
                charm_name="postgresql-k8s", (3)
                oci_resource_name="postgresql-image", (4)
            )
        )

        # [...]
1 Replace KubernetesPostgreSQLRefresh with your subclass of charm_refresh.CharmSpecificKubernetes
2 Replace PostgreSQL with the upstream workload name. This must be the same as the name used in 10. Update actions.yaml
3 Replace postgresql-k8s with the charm name in metadata.yaml
4 Replace postgresql-image with the resource name for the workload OCI image in metadata.yaml resources. This must be the same as the resource used in 11. Create refresh_versions.toml