Event

In Ops, an event is a data structure that encapsulates part of the execution context of a charm. In particular, it contains information regarding why this specific execution is taking place. When creating a charm, you write charms and implement handlers that respond to events and state changes communicated by Juju controller using the observer pattern.

The execution context of a charm is expressed in environment variables. For more, see Charm environment variables.

For example:

  • A config-changed event is the data structure used to communicate to the charm that its configuration has changed.
  • A http-relation-departed event is the data structure used to tell the charm that a particular unit is departing the http relation.

See more:

Here’s a proposed addition to the page (I have no edit permissions) (cc: @tmihoc).

See also:

Juju and the operator framework divide event types into the following categories:

Hook execution context

The execution context of a charm is expressed in environment variables.

Charms written with the operator framework benefit from the various abstraction levels on top of the environment variables, so charm authors rarely (if at all) need to work with them directly.

In a pebble-ready event they would be along these lines:

{
 'APT_LISTCHANGES_FRONTEND': 'none',
 'CHARM_DIR': '/var/lib/juju/agents/unit-bare-0/charm',
 'CLOUD_API_VERSION': '1.23.0',
 'DEBIAN_FRONTEND': 'noninteractive',
 'JUJU_AGENT_SOCKET_ADDRESS': '@/var/lib/juju/agents/unit-bare-0/agent.socket',
 'JUJU_AGENT_SOCKET_NETWORK': 'unix',
 'JUJU_API_ADDRESSES': '10.152.183.4:17070 '
                       'controller-service.controller-charm-dev.svc.cluster.local:17070',
 'JUJU_AVAILABILITY_ZONE': '',
 'JUJU_CHARM_DIR': '/var/lib/juju/agents/unit-bare-0/charm',
 'JUJU_CHARM_FTP_PROXY': '',
 'JUJU_CHARM_HTTPS_PROXY': '',
 'JUJU_CHARM_HTTP_PROXY': '',
 'JUJU_CHARM_NO_PROXY': '127.0.0.1,localhost,::1',
 'JUJU_CONTEXT_ID': 'bare/0-workload-pebble-ready-1918120275707858680',
 'JUJU_DISPATCH_PATH': 'hooks/workload-pebble-ready',
 'JUJU_HOOK_NAME': 'workload-pebble-ready',
 'JUJU_MACHINE_ID': '',
 'JUJU_METER_INFO': 'not set',
 'JUJU_METER_STATUS': 'AMBER',
 'JUJU_MODEL_NAME': 'welcome',
 'JUJU_MODEL_UUID': 'cdac5656-2423-4388-8f30-41854b4cca7d',
 'JUJU_PRINCIPAL_UNIT': '',
 'JUJU_SLA': 'unsupported',
 'JUJU_UNIT_NAME': 'bare/0',
 'JUJU_VERSION': '2.9.29',
 'JUJU_WORKLOAD_NAME': 'workload',
 'KUBERNETES_PORT': 'tcp://10.152.183.1:443',
 'KUBERNETES_PORT_443_TCP': 'tcp://10.152.183.1:443',
 'KUBERNETES_PORT_443_TCP_ADDR': '10.152.183.1',
 'KUBERNETES_PORT_443_TCP_PORT': '443',
 'KUBERNETES_PORT_443_TCP_PROTO': 'tcp',
 'KUBERNETES_SERVICE_HOST': '10.152.183.1',
 'KUBERNETES_SERVICE_PORT': '443',
 'KUBERNETES_SERVICE_PORT_HTTPS': '443',
 'LANG': 'C.UTF-8',
 'OPERATOR_DISPATCH': '1',
 'PATH': '/var/lib/juju/tools/unit-bare-0:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/charm/bin',
 'PWD': '/var/lib/juju/agents/unit-bare-0/charm',
 'PYTHONPATH': 'lib:venv',
 'TERM': 'tmux-256color',
}

To take the example further, the JUJU_WORKLOAD_NAME environment variable, for example, is only set for workload events (currently it is only pebble-ready).

1 Like

Hi @sed-i, that’s an excellent addition. Do you want to put it in yourself? I’ve increased your permissions. (Hopefully enough; if not, let me know.)

Still no edit permissions. Feel free to add it in.

1 Like