Skip to content

Commit

Permalink
chore: update charm libraries (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
observability-noctua-bot authored Sep 18, 2024
1 parent 89e8b99 commit 8fd7c24
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 71 deletions.
13 changes: 11 additions & 2 deletions lib/charms/tempo_k8s/v2/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self, *args):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 9
LIBPATCH = 10

PYDEPS = ["pydantic"]

Expand Down Expand Up @@ -902,7 +902,16 @@ def _get_endpoint(
def get_endpoint(
self, protocol: ReceiverProtocol, relation: Optional[Relation] = None
) -> Optional[str]:
"""Receiver endpoint for the given protocol."""
"""Receiver endpoint for the given protocol.
It could happen that this function gets called before the provider publishes the endpoints.
In such a scenario, if a non-leader unit calls this function, a permission denied exception will be raised due to
restricted access. To prevent this, this function needs to be guarded by the `is_ready` check.
Raises:
ProtocolNotRequestedError:
If the charm unit is the leader unit and attempts to obtain an endpoint for a protocol it did not request.
"""
endpoint = self._get_endpoint(relation or self._relation, protocol=protocol)
if not endpoint:
requested_protocols = set()
Expand Down
91 changes: 22 additions & 69 deletions lib/charms/traefik_k8s/v0/traefik_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,16 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

r"""# Interface Library for traefik_route.
This library wraps relation endpoints for traefik_route. The requirer of this
relation is the traefik-route-k8s charm, or any charm capable of providing
Traefik configuration files. The provider is the traefik-k8s charm, or another
charm willing to consume Traefik configuration files.
## Getting Started
To get started using the library, you just need to fetch the library using `charmcraft`.
```shell
cd some-charm
charmcraft fetch-lib charms.traefik_k8s.v0.traefik_route
```
To use the library from the provider side (Traefik):
```yaml
requires:
traefik_route:
interface: traefik_route
limit: 1
```
```python
from charms.traefik_k8s.v0.traefik_route import TraefikRouteProvider
class TraefikCharm(CharmBase):
def __init__(self, *args):
# ...
self.traefik_route = TraefikRouteProvider(self)
self.framework.observe(
self.traefik_route.on.ready, self._handle_traefik_route_ready
)
def _handle_traefik_route_ready(self, event):
config: str = self.traefik_route.get_config(event.relation) # yaml
# use config to configure Traefik
```
To use the library from the requirer side (TraefikRoute):
```yaml
requires:
traefik-route:
interface: traefik_route
limit: 1
optional: false
```
```python
# ...
from charms.traefik_k8s.v0.traefik_route import TraefikRouteRequirer
class TraefikRouteCharm(CharmBase):
def __init__(self, *args):
# ...
traefik_route = TraefikRouteRequirer(
self, self.model.relations.get("traefik-route"),
"traefik-route"
)
if traefik_route.is_ready():
traefik_route.submit_to_traefik(
config={'my': {'traefik': 'configuration'}}
)
r"""# [DEPRECATED!] Interface Library for traefik_route.
This is a DEPRECATED version of the traefik_route interface library.
It was dropped and no longer maintained under `traefik-route-k8s-operator`, which will soon be archived.
traefik_route v0 is now maintained under `traefik-k8s-operator`.
Please fetch the new library with `charmcraft fetch-lib charms.traefik_k8s.v0.traefik_route`.
```
"""
import logging
from typing import Optional
Expand All @@ -88,7 +29,7 @@ def __init__(self, *args):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 1
LIBPATCH = 11

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -157,6 +98,12 @@ def __init__(
external_host: The external host.
scheme: The scheme.
"""
log.warning(
"The ``traefik_route v0`` library is DEPRECATED "
"and no longer maintained under ``traefik-route-k8s-operator``. "
"``traefik_route v0`` is now maintained under ``traefik-k8s-operator``. "
"Please fetch the new library with ``charmcraft fetch-lib charms.traefik_k8s.v0.traefik_route``."
)
super().__init__(charm, relation_name)
self._stored.set_default(external_host=None, scheme=None)

Expand Down Expand Up @@ -292,6 +239,12 @@ class TraefikRouteRequirer(Object):
_stored = StoredState()

def __init__(self, charm: CharmBase, relation: Relation, relation_name: str = "traefik-route"):
log.warning(
"The ``traefik_route v0`` library is DEPRECATED "
"and no longer maintained under ``traefik-route-k8s-operator``. "
"``traefik_route v0`` is now maintained under ``traefik-k8s-operator``. "
"Please fetch the new library with ``charmcraft fetch-lib charms.traefik_k8s.v0.traefik_route``."
)
super(TraefikRouteRequirer, self).__init__(charm, relation_name)
self._stored.set_default(external_host=None, scheme=None)

Expand Down

0 comments on commit 8fd7c24

Please sign in to comment.