5. Charm architecture

        C4Container
System_Boundary(web_app_charm, "Web app charm") {
   Container_Boundary(charm_container, "Charm Container") {
      Component(charm_logic, "Charm Logic", "Juju Operator Framework", "Controls application deployment & config")
   }
   Container_Boundary(web_app_container, "Workload Container") {
      Component(workload, "Workload", "Web Application", "Serves web requests")
   }
}
Rel(charm_logic, workload, "Supervises<br>process")
    

Web app support in Charmcraft and Rockcraft is a framework to easily deploy and operate your web app workloads and associated infrastructure, such as databases and ingress, using open source tooling.

The charm design leverages the sidecar pattern to allow multiple containers in each pod with Pebble running as the containers’ entrypoint. Pebble is a lightweight, API-driven process supervisor that is responsible for configuring processes to run in a container and controlling those processes throughout the workload lifecycle.

The charm consists of an app container which contains the workload to run in any of the supported web frameworks. As a result, if you run a kubectl get pods on a namespace named for the Juju model you’ve deployed the web app charm into, you’ll see something like the following:

NAME                          READY   STATUS    RESTARTS   AGE
web-app-0                     2/2     Running   0          6h4m

This shows there are two containers - the named above, as well as a container for the charm code itself. The charm container logic is determined by the paas-charm library.

And if you run kubectl describe pod web-app-0, all the containers will have the command /charm/bin/pebble. That’s because Pebble is responsible for the processes startup.

5.1. OCI images

We use Rockcraft to build OCI Images for the web app charm.

5.2. Juju events

Juju handles updates or changes to the charm and system through hooks, or events. These notifications provides the charm information that the system has changed and thus prompts a reaction from the charm to respond to the change, taking into account the charm’s configuration.

For more information on the events observed by 12-factor app charms, see Juju events.

5.3. Charm code overview

The src/paas_charm/charm.py contains the charm logic that all supported frameworks will inherit and extend. Each framework will define its entry point in its own charm.py file, defining a class that will extend from PaasCharm.

PaasCharm is the base class from which all Charms are formed, defined by Ops (Python framework for developing charms).

See also

Charm

The __init__ method guarantees that the charm observes all events relevant to its operation and handles them.

Take, for example, when a configuration is changed by using the CLI.

  1. User runs the command

    juju config sample_config=sample_value
    
  2. A config-changed event is emitted.

  3. In the __init__ method is defined how to handle this event like this:

    self.framework.observe(self.on.config_changed, self._on_config_changed)
    
  4. The method _on_config_changed, for its turn, will take the necessary actions such as waiting for all the relations to be ready and then configuring the container.