Zookeeper K8s

Channel Revision Published Runs on
latest/stable 10 09 Mar 2022
Ubuntu 20.04
latest/beta 8 08 Jun 2021
Ubuntu 20.04
latest/edge 21 12 Apr 2023
Ubuntu 22.04 Ubuntu 20.04
latest/edge 16 15 Oct 2022
Ubuntu 22.04 Ubuntu 20.04
3/stable 51 27 Feb 2024
Ubuntu 22.04
3/candidate 51 27 Feb 2024
Ubuntu 22.04
3/beta 51 27 Feb 2024
Ubuntu 22.04
3/edge 64 13 Sep 2024
Ubuntu 22.04
juju deploy zookeeper-k8s --channel 3/stable
Show information

Platform:

charms.zookeeper_k8s.v0.zookeeper

ZooKeeper Library.

This library implements both sides of the zookeeper interface.

The provider side of this interface is implemented by the zookeeper-k8s Charmed Operator.

Any Charmed Operator that requires a ZooKeeper database for providing its service should implement the requirer side of this interface. kafka-k8s is an example.

In a nutshell using this library to implement a Charmed Operator requiring a ZooKeeper database (and talking to it as a ZooKeeper client) would look like

$ charmcraft fetch-lib charms.zookeeper_k8s.v0.zookeeper

metadata.yaml:

requires:
  zookeeper:
    interface: zookeeper

src/charm.py:

from charms.zookeeper_k8s.v0.zookeeper import ZooKeeperEvents, ZooKeeperRequires
from ops.charm import CharmBase


class MyCharm(CharmBase):

    on = ZooKeeperEvents()

    def __init__(self, *args):
        super().__init__(*args)
        self.zookeeper = ZooKeeperRequires(self)
        self.framework.observe(
            self.on.zookeeper_clients_changed,
            self._on_zookeeper_clients_changed,
        )
        self.framework.observe(
            self.on.zookeeper_clients_broken,
            self._on_zookeeper_clients_broken,
        )

    def _on_zookeeper_clients_changed(self, event):
        # Get zookeeper client addresses
        client_addresses: str = self.zookeeper.hosts
        # client_addresses => "zk-0:2181,zk-1:2181"

    def _on_zookeeper_clients_broken(self, event):
        # Stop service
        # ...
        self.unit.status = BlockedStatus("need zookeeper relation")

You can file bugs here!


class ZooKeeperEvents

ZooKeeper events.

Description

This class defines the events that ZooKeeper can emit.

Events: zookeeper_clients_changed (_ClientsBrokenEvent)

class ZooKeeperRequires

Description

ZooKeeper requires relation. None

Methods

ZooKeeperRequires. __init__( self , charm: CharmBase , endpoint_name: str )

Constructor.

Arguments

charm (CharmBase)

The charm that implements the relation.

endpoint_name (str)

Endpoint name of the relation.

ZooKeeperRequires. hosts( self )

Get zookeeper hosts.

Returns

Optional[str]

Comma-listed zookeeper client hosts.

class ZooKeeperProvides

ZooKeeper provides relation.

Methods

ZooKeeperProvides. __init__( self , charm: CharmBase , endpoint_name: str )

Constructor.

Arguments

charm (CharmBase)

The charm that implements the relation.

endpoint_name (str)

Endpoint name of the relation.

ZooKeeperProvides. update_hosts( self , client_addresses: str , relation_id )

Update hosts in the zookeeper relation.

Arguments

client_addresses (str)

Comma-listed addresses of zookeeper clients.

relation_id (Optional[int])

Id of the relation. If set, it will be used to update the relation data of the specified relation. If not set, the data for all the relations will be updated.

Description

This method will cause a relation-changed event in the requirer units of the relation.