From a7c4785516981c892e93187e76172b0e0bac040d Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 18 Sep 2024 12:50:45 +0300 Subject: [PATCH 1/3] publish traefik_route lib --- .../v0/traefik_route.py | 16 +++++++++------- src/charm.py | 8 ++++---- tests/integration/conftest.py | 2 +- tests/integration/spellbook/build_all_caches.py | 4 +--- tests/integration/testers/route/src/charm.py | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) rename lib/charms/{traefik_route_k8s => traefik_k8s}/v0/traefik_route.py (96%) 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..13b0f467 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: 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/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 From 98c4454c9b08c988b1b367dbddc0e1311d16d278 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 18 Sep 2024 14:00:46 +0300 Subject: [PATCH 2/3] retry charm build --- tests/integration/conftest.py | 65 +++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 13b0f467..6d3e6a3d 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -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") From d146376b3c09eb27eda719195aadb3ad4d5d8342 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 18 Sep 2024 14:28:45 +0300 Subject: [PATCH 3/3] add pydantic core --- tests/integration/testers/forward-auth/charmcraft.yaml | 1 + tests/integration/testers/ipa/charmcraft.yaml | 1 + tests/integration/testers/ipu/charmcraft.yaml | 1 + tests/integration/testers/route/charmcraft.yaml | 1 + tests/integration/testers/tcp/charmcraft.yaml | 1 + 5 files changed, 5 insertions(+) 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/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