istio_metadata

Istio metadata interface library.

This library provides the provider and requirer sides of the istio_metadata relation interface, used to transfer information about an instance of Istio (such as its root namespace) to charms that need to interface with Istio.

Provider usage:

from charmlibs.interfaces.istio_metadata import IstioMetadataProvider

class FooCharm(CharmBase):
    def __init__(self, framework):
        super().__init__(framework)
        self.istio_metadata = IstioMetadataProvider(
            charm=self,
            relation_mapping=self.model.relations,
            app=self.app,
        )

        self.framework.observe(self.on.leader_elected, self._publish)
        self.framework.observe(
            self.on['istio-metadata'].relation_joined, self._publish
        )

    def _publish(self, _):
        self.istio_metadata.publish(root_namespace='istio-system')

The provider’s charmcraft.yaml should declare:

provides:
  istio-metadata:
    interface: istio_metadata

Requirer usage:

from charmlibs.interfaces.istio_metadata import IstioMetadataRequirer

class FooCharm(CharmBase):
    def __init__(self, framework):
        super().__init__(framework)
        self.istio_metadata = IstioMetadataRequirer(
            self.model.relations, 'istio-metadata',
        )

        self.framework.observe(
            self.on['istio-metadata'].relation_changed, self._on_changed
        )
        self.framework.observe(
            self.on['istio-metadata'].relation_broken, self._on_changed
        )

    def _on_changed(self, _):
        data = self.istio_metadata.get_data()
        ...

The requirer’s charmcraft.yaml should declare (with limit: 1, since IstioMetadataRequirer is designed for relating to a single application):

requires:
  istio-metadata:
    limit: 1
    interface: istio_metadata
class IstioMetadataAppData(*, root_namespace: str)

Bases: BaseModel

Data model for the istio_metadata interface.

root_namespace: str
class IstioMetadataProvider(
charm: CharmBase,
relation_mapping: RelationMapping,
app: Application,
relation_name: str = 'istio-metadata',
)

Bases: object

The provider side of the istio-metadata relation.

property relations

Return the applications related to us under the monitored relation.

publish(root_namespace: str)

Post istio-metadata to all related applications.

This method writes to the relation’s app data bag, and thus should never be called by a unit that is not the leader otherwise ops will raise an exception.

Parameters:

root_namespace – The root namespace of the Istio deployment.

class IstioMetadataRequirer(
relation_mapping: RelationMapping,
relation_name: str = 'istio-metadata',
)

Bases: object

Endpoint wrapper for the requirer side of the istio-metadata relation.

property relations

Return relation instances for applications related to us on the monitored relation.

get_data() IstioMetadataAppData | None

Return data for at most one related application, raising if more than one is available.

Useful for charms that always expect exactly one related application. It is recommended that those charms also set limit=1 for that relation in charmcraft.yaml. Returns None if no data is available (either because no applications are related to us, or because the related application has not sent data).