MLOps Libs
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/edge | 1 | 07 Feb 2024 |
juju deploy mlops-libs --channel edge
Deploy universal operators easily with Juju, the Universal Operator Lifecycle Manager.
Platform:
charms.mlops_libs.v0.k8s_service_info
-
- Last updated 20 Mar 2024
- Revision Library version 0.1
Library for sharing Kubernetes Services information.
This library offers a Python API for providing and requesting information about
any Kubernetes Service resource.
The default relation name is k8s-svc-info
and it's recommended to use that name,
though if changed, you must ensure to pass the correct name when instantiating the
provider and requirer classes, as well as in metadata.yaml
.
Getting Started
Fetching the library with charmcraft
Using charmcraft you can:
charmcraft fetch-lib charms.mlops_libs.v0.k8s_service_info
Using the library as requirer
Add relation to metadata.yaml
requires:
k8s-svc-info:
interface: k8s-service
limit: 1
Instantiate the KubernetesServiceInfoRequirer class in charm.py
from ops.charm import CharmBase
from charms.mlops_libs.v0.kubernetes_service_info import KubernetesServiceInfoRequirer, KubernetesServiceInfoRelationError
class RequirerCharm(CharmBase):
def __init__(self, *args):
self._k8s_svc_info_requirer = KubernetesServiceInfoRequirer(self)
self.framework.observe(self.on.some_event_emitted, self.some_event_function)
def some_event_function():
# use the getter function wherever the info is needed
try:
k8s_svc_info_data = self._k8s_svc_info_requirer.get_data()
except KubernetesServiceInfoRelationError as error:
"your error handler goes here"
Using the library as provider
Add relation to metadata.yaml
provides:
k8s-svc-info:
interface: k8s-service
Instantiate the KubernetesServiceInfoProvider class in charm.py
from ops.charm import CharmBase
from charms.mlops_libs.v0.kubernetes_service_info import KubernetesServiceInfoProvider, KubernetesServiceInfoRelationError
class ProviderCharm(CharmBase):
def __init__(self, *args, **kwargs):
...
self._k8s_svc_info_provider = KubernetesServiceInfoProvider(self)
self.observe(self.on.some_event, self._some_event_handler)
def _some_event_handler(self, ...):
# This will update the relation data bag with the Service name and port
try:
self._k8s_svc_info_provider.send_data(name, port)
except KubernetesServiceInfoRelationError as error:
"your error handler goes here"
Relation data
The data shared by this library is:
- name: the name of the Kubernetes Service as it appears in the resource metadata, e.g. "metadata-grpc-service".
- port: the port of the Kubernetes Service
Index
class KubernetesServiceInfoRelationError
Description
Base exception class for any relation error handled by this library. None
class KubernetesServiceInfoRelationMissingError
Description
Exception to raise when the relation is missing on either end. None
Methods
KubernetesServiceInfoRelationMissingError. __init__( self )
class KubernetesServiceInfoRelationDataMissingError
Description
Exception to raise when there is missing data in the relation data bag. None
Methods
KubernetesServiceInfoRelationDataMissingError. __init__( self , message )
class KubernetesServiceInfoUpdatedEvent
Description
Indicates the Kubernetes Service Info data was updated. None
class KubernetesServiceInfoEvents
Description
Events for the Kubernetes Service Info library. None
class KubernetesServiceInfoObject
Representation of a Kubernetes Service info object.
Arguments
The name of the Service
The port of the Service
class KubernetesServiceInfoRequirer
Implement the Requirer end of the Kubernetes Service Info relation.
Arguments
the provider application
(list, optional): list of BoundEvents that this manager should handle. Use this to update the data sent on this relation on demand.
the name of the relation
Attributes
Description
Observes the relation events and get data of a related application.
This library emits:
- KubernetesServiceInfoUpdatedEvent: when data received on the relation is updated.
Methods
KubernetesServiceInfoRequirer. __init__( self , charm: CharmBase , refresh_event , relation_name )
KubernetesServiceInfoRequirer. get_data( self )
Description
Return a KubernetesServiceInfoObject. None
class KubernetesServiceInfoRequirerWrapper
Wrapper for the relation data getting logic.
Arguments
the requirer application
the name of the relation
Attributes
Methods
KubernetesServiceInfoRequirerWrapper. __init__( self , charm , relation_name )
KubernetesServiceInfoRequirerWrapper. get_data( self )
Return a KubernetesServiceInfoObject containing Kubernetes Service information.
class KubernetesServiceInfoProvider
Implement the Provider end of the Kubernetes Service Info relation.
Arguments
the provider application
the name of the Kubernetes Service the provider knows about
the port number of the Kubernetes Service the provider knows about
(list, optional): list of BoundEvents that this manager should handle. Use this to update the data sent on this relation on demand.
the name of the relation
Attributes
Description
Observes relation events to send data to related applications.
Methods
KubernetesServiceInfoProvider. __init__( self , charm: CharmBase , name: str , port: str , refresh_event , relation_name )
class KubernetesServiceInfoProviderWrapper
Wrapper for the relation data sending logic.
Arguments
the provider application
the name of the relation
Attributes
Methods
KubernetesServiceInfoProviderWrapper. __init__( self , charm: CharmBase , relation_name )
KubernetesServiceInfoProviderWrapper. send_data( self , name: str , port: str )
Update the relation data bag with data from a Kubernetes Service.
Arguments
the name of the Kubernetes Service the provider knows about
the port number of the Kubernetes Service the provider knows about
Description
This method will complete successfully even if there are no related applications.