Kafka K8s

Channel Revision Published Runs on
latest/stable 5 09 Mar 2022
Ubuntu 20.04
latest/edge 27 25 Apr 2023
Ubuntu 22.04
3/stable 56 27 Feb 2024
Ubuntu 22.04
3/candidate 56 27 Feb 2024
Ubuntu 22.04
3/beta 56 27 Feb 2024
Ubuntu 22.04
3/edge 60 03 May 2024
Ubuntu 22.04
juju deploy kafka-k8s --channel 3/stable
Show information

Platform:

charms.kafka_k8s.v0.kafka

Kafka library.

This library implements both sides of the kafka interface.

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

Any Charmed Operator that requires Kafka for providing its service should implement the requirer side of this interface.

In a nutshell using this library to implement a Charmed Operator requiring Kafka would look like

$ charmcraft fetch-lib charms.kafka_k8s.v0.kafka

metadata.yaml:

requires:
  kafka:
    interface: kafka
    limit: 1

src/charm.py:

from charms.kafka_k8s.v0.kafka import KafkaEvents, KafkaRequires
from ops.charm import CharmBase


class MyCharm(CharmBase):

    on = KafkaEvents()

    def __init__(self, *args):
        super().__init__(*args)
        self.kafka = KafkaRequires(self)
        self.framework.observe(
            self.on.kafka_available,
            self._on_kafka_available,
        )
        self.framework.observe(
            self.on["kafka"].relation_broken,
            self._on_kafka_broken,
        )

    def _on_kafka_available(self, event):
        # Get Kafka host and port
        host: str = self.kafka.host
        port: int = self.kafka.port
        # host => "kafka-k8s"
        # port => 9092

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

You can file bugs here!


class KafkaEvents

Kafka events.

Description

This class defines the events that Kafka can emit.

Events: kafka_available (_KafkaAvailableEvent)

class KafkaRequires

Description

Requires-side of the Kafka relation. None

Methods

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

KafkaRequires. host( self )

Description

Get kafka hostname. None

KafkaRequires. port( self )

Description

Get kafka port number. None

class KafkaProvides

Description

Provides-side of the Kafka relation. None

Methods

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

KafkaProvides. set_host_info( self , host: str , port: int , relation )

Set Kafka host and port.

Arguments

host (str)

Kafka hostname or IP address.

port (int)

Kafka port.

relation (Optional[Relation])

Relation to update. If not specified, all relations will be updated.

Description

This function writes in the application data of the relation, therefore, only the unit leader can call it.