diff --git a/lib/charms/traefik_route_k8s/v0/traefik_route.py b/lib/charms/traefik_k8s/v0/traefik_route.py similarity index 96% rename from lib/charms/traefik_route_k8s/v0/traefik_route.py rename to lib/charms/traefik_k8s/v0/traefik_route.py index de2da555..17708603 100644 --- a/lib/charms/traefik_route_k8s/v0/traefik_route.py +++ b/lib/charms/traefik_k8s/v0/traefik_route.py @@ -15,7 +15,7 @@ ```shell cd some-charm -charmcraft fetch-lib charms.traefik_route_k8s.v0.traefik_route +charmcraft fetch-lib charms.traefik_k8s.v0.traefik_route ``` To use the library from the provider side (Traefik): @@ -28,7 +28,7 @@ ``` ```python -from charms.traefik_route_k8s.v0.traefik_route import TraefikRouteProvider +from charms.traefik_k8s.v0.traefik_route import TraefikRouteProvider class TraefikCharm(CharmBase): def __init__(self, *args): @@ -56,7 +56,7 @@ def _handle_traefik_route_ready(self, event): ```python # ... -from charms.traefik_route_k8s.v0.traefik_route import TraefikRouteRequirer +from charms.traefik_k8s.v0.traefik_route import TraefikRouteRequirer class TraefikRouteCharm(CharmBase): def __init__(self, *args): @@ -88,7 +88,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 = 10 +LIBPATCH = 1 log = logging.getLogger(__name__) @@ -254,8 +254,10 @@ def is_ready(self, relation: Relation) -> bool: def get_config(self, relation: Relation) -> Optional[str]: """Renamed to ``get_dynamic_config``.""" - log.warning("``TraefikRouteProvider.get_config`` is deprecated. " - "Use ``TraefikRouteProvider.get_dynamic_config`` instead") + log.warning( + "``TraefikRouteProvider.get_config`` is deprecated. " + "Use ``TraefikRouteProvider.get_dynamic_config`` instead" + ) return self.get_dynamic_config(relation) def get_dynamic_config(self, relation: Relation) -> Optional[str]: @@ -356,7 +358,7 @@ def is_ready(self) -> bool: """Is the TraefikRouteRequirer ready to submit data to Traefik?""" return self._relation is not None - def submit_to_traefik(self, config: dict, static: dict=None): + def submit_to_traefik(self, config: dict, static: Optional[dict] = None): """Relay an ingress configuration data structure to traefik. This will publish to the traefik-route relation databag diff --git a/src/charm.py b/src/charm.py index 59aa5cd0..4f97276b 100755 --- a/src/charm.py +++ b/src/charm.py @@ -37,16 +37,16 @@ from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider from charms.tempo_k8s.v1.charm_tracing import trace_charm from charms.tempo_k8s.v2.tracing import TracingEndpointRequirer +from charms.traefik_k8s.v0.traefik_route import ( + TraefikRouteProvider, + TraefikRouteRequirerReadyEvent, +) from charms.traefik_k8s.v1.ingress import IngressPerAppProvider as IPAv1 from charms.traefik_k8s.v1.ingress_per_unit import ( DataValidationError, IngressPerUnitProvider, ) from charms.traefik_k8s.v2.ingress import IngressPerAppProvider as IPAv2 -from charms.traefik_route_k8s.v0.traefik_route import ( - TraefikRouteProvider, - TraefikRouteRequirerReadyEvent, -) from deepmerge import always_merger from lightkube.core.client import Client from lightkube.core.exceptions import ApiError diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 6f20d3f4..6d3e6a3d 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -72,7 +72,7 @@ def copy_traefik_library_into_tester_charms(ops_test): "traefik_k8s/v2/ingress.py", "traefik_k8s/v1/ingress_per_unit.py", "observability_libs/v1/kubernetes_service_patch.py", - "traefik_route_k8s/v0/traefik_route.py", + "traefik_k8s/v0/traefik_route.py", ] for tester in ["forward-auth", "ipa", "ipu", "tcp", "route"]: for lib in libraries: @@ -101,40 +101,85 @@ async def traefik_charm(ops_test): @timed_memoizer async def forward_auth_tester_charm(ops_test): charm_path = (Path(__file__).parent / "testers" / "forward-auth").absolute() - charm = await ops_test.build_charm(charm_path, verbosity="debug") - return charm + count = 0 + while True: + try: + charm = await ops_test.build_charm(charm_path, verbosity="debug") + return charm + except RuntimeError: + logger.warning("Failed to build forward auth tester. Trying again!") + count += 1 + + if count == 3: + raise @pytest.fixture(scope="module") @timed_memoizer async def ipa_tester_charm(ops_test): charm_path = (Path(__file__).parent / "testers" / "ipa").absolute() - charm = await ops_test.build_charm(charm_path, verbosity="debug") - return charm + count = 0 + while True: + try: + charm = await ops_test.build_charm(charm_path, verbosity="debug") + return charm + except RuntimeError: + logger.warning("Failed to build ipa tester. Trying again!") + count += 1 + + if count == 3: + raise @pytest.fixture(scope="module") @timed_memoizer async def ipu_tester_charm(ops_test): charm_path = (Path(__file__).parent / "testers" / "ipu").absolute() - charm = await ops_test.build_charm(charm_path, verbosity="debug") - return charm + count = 0 + while True: + try: + charm = await ops_test.build_charm(charm_path, verbosity="debug") + return charm + except RuntimeError: + logger.warning("Failed to build ipu tester. Trying again!") + count += 1 + + if count == 3: + raise @pytest.fixture(scope="module") @timed_memoizer async def tcp_tester_charm(ops_test): charm_path = (Path(__file__).parent / "testers" / "tcp").absolute() - charm = await ops_test.build_charm(charm_path, verbosity="debug") - return charm + count = 0 + while True: + try: + charm = await ops_test.build_charm(charm_path, verbosity="debug") + return charm + except RuntimeError: + logger.warning("Failed to build tcp tester. Trying again!") + count += 1 + + if count == 3: + raise @pytest.fixture(scope="module") @timed_memoizer async def route_tester_charm(ops_test): charm_path = (Path(__file__).parent / "testers" / "route").absolute() - charm = await ops_test.build_charm(charm_path, verbosity="debug") - return charm + count = 0 + while True: + try: + charm = await ops_test.build_charm(charm_path, verbosity="debug") + return charm + except RuntimeError: + logger.warning("Failed to build route tester. Trying again!") + count += 1 + + if count == 3: + raise @pytest.fixture(scope="module") diff --git a/tests/integration/spellbook/build_all_caches.py b/tests/integration/spellbook/build_all_caches.py index ad617190..254cdb52 100644 --- a/tests/integration/spellbook/build_all_caches.py +++ b/tests/integration/spellbook/build_all_caches.py @@ -23,9 +23,7 @@ def main(): spellbook_fetch( charm_name="route-tester", charm_root=testers_root / "route", - pull_libs=[ - traefik_root / "lib" / "charms" / "traefik_route_k8s" / "v0" / "traefik_route.py" - ], + pull_libs=[traefik_root / "lib" / "charms" / "traefik_k8s" / "v0" / "traefik_route.py"], ) spellbook_fetch( charm_name="ipa-tester", diff --git a/tests/integration/testers/forward-auth/charmcraft.yaml b/tests/integration/testers/forward-auth/charmcraft.yaml index ddf3772a..e439b3e7 100644 --- a/tests/integration/testers/forward-auth/charmcraft.yaml +++ b/tests/integration/testers/forward-auth/charmcraft.yaml @@ -13,5 +13,6 @@ parts: charm-binary-python-packages: - jsonschema - ops + - pydantic-core build-packages: - git diff --git a/tests/integration/testers/ipa/charmcraft.yaml b/tests/integration/testers/ipa/charmcraft.yaml index 7f0b9691..c864b362 100644 --- a/tests/integration/testers/ipa/charmcraft.yaml +++ b/tests/integration/testers/ipa/charmcraft.yaml @@ -12,5 +12,6 @@ parts: charm: charm-binary-python-packages: - ops + - pydantic-core build-packages: - git diff --git a/tests/integration/testers/ipu/charmcraft.yaml b/tests/integration/testers/ipu/charmcraft.yaml index 7f0b9691..c864b362 100644 --- a/tests/integration/testers/ipu/charmcraft.yaml +++ b/tests/integration/testers/ipu/charmcraft.yaml @@ -12,5 +12,6 @@ parts: charm: charm-binary-python-packages: - ops + - pydantic-core build-packages: - git diff --git a/tests/integration/testers/route/charmcraft.yaml b/tests/integration/testers/route/charmcraft.yaml index 7f0b9691..c864b362 100644 --- a/tests/integration/testers/route/charmcraft.yaml +++ b/tests/integration/testers/route/charmcraft.yaml @@ -12,5 +12,6 @@ parts: charm: charm-binary-python-packages: - ops + - pydantic-core build-packages: - git diff --git a/tests/integration/testers/route/src/charm.py b/tests/integration/testers/route/src/charm.py index 9c059b23..cc4626bc 100755 --- a/tests/integration/testers/route/src/charm.py +++ b/tests/integration/testers/route/src/charm.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # Copyright 2022 Canonical Ltd. # See LICENSE file for licensing details. -from charms.traefik_route_k8s.v0.traefik_route import TraefikRouteRequirer +from charms.traefik_k8s.v0.traefik_route import TraefikRouteRequirer from ops.charm import CharmBase from ops.model import ActiveStatus diff --git a/tests/integration/testers/tcp/charmcraft.yaml b/tests/integration/testers/tcp/charmcraft.yaml index 1d79c382..06980aca 100644 --- a/tests/integration/testers/tcp/charmcraft.yaml +++ b/tests/integration/testers/tcp/charmcraft.yaml @@ -13,5 +13,6 @@ parts: charm-binary-python-packages: - ops - lightkube + - pydantic-core build-packages: - git