diff --git a/src/charm.py b/src/charm.py index e2c47315..201281df 100755 --- a/src/charm.py +++ b/src/charm.py @@ -32,11 +32,7 @@ ServicePort, ) from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider -from charms.traefik_k8s.v1.ingress import ( - IngressPerAppReadyEvent, - IngressPerAppRequirer, - IngressPerAppRevokedEvent, -) +from charms.traefik_k8s.v1.ingress import IngressPerAppRequirer from ops.charm import ActionEvent, CharmBase from ops.framework import StoredState from ops.main import main @@ -124,12 +120,12 @@ def __init__(self, *args): self.karma_provider = KarmaProvider(self, "karma-dashboard") self.remote_configuration = RemoteConfigurationRequirer(self) + api = ServicePort(self._ports.api, name=f"{self.app.name}") + ha = ServicePort(self._ports.ha, name=f"{self.app.name}-ha") self.service_patcher = KubernetesServicePatch( - self, - [ - ServicePort(self._ports.api, name=f"{self.app.name}"), - ServicePort(self._ports.ha, name=f"{self.app.name}-ha"), - ], + charm=self, + service_type="ClusterIP", + ports=[api, ha], ) self.resources_patch = KubernetesComputeResourcesPatch( self, @@ -167,9 +163,6 @@ def __init__(self, *args): ), ) - self.framework.observe(self.ingress.on.ready, self._on_ingress_ready) - self.framework.observe(self.ingress.on.revoked, self._on_ingress_revoked) - self.container = self.unit.get_container(self._container_name) # Core lifecycle events @@ -250,12 +243,6 @@ def _on_check_config(self, event: ActionEvent) -> None: {"result": output, "error-message": err, "valid": False if err else True} ) - def _on_ingress_ready(self, event: IngressPerAppReadyEvent): - logger.info("This app's ingress URL: %s", event.url) - - def _on_ingress_revoked(self, event: IngressPerAppRevokedEvent): - logger.info("This app no longer has ingress") - def _on_show_config_action(self, event: ActionEvent): """Hook for the show-config action.""" event.log(f"Fetching {self._config_path}") diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index f9e17cd3..80ba361a 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -21,7 +21,7 @@ class TestWithInitialHooks(unittest.TestCase): @patch.object(Alertmanager, "reload", tautology) @patch.object(AlertmanagerCharm, "_check_config", lambda *a, **kw: ("ok", "")) - @patch("charm.KubernetesServicePatch", lambda x, y: None) + @patch("charm.KubernetesServicePatch", lambda *_, **__: None) @patch("socket.getfqdn", new=lambda *args: "fqdn") @k8s_resource_multipatch @patch("lightkube.core.client.GenericSyncClient") @@ -146,7 +146,7 @@ class TestWithoutInitialHooks(unittest.TestCase): @patch.object(Alertmanager, "reload", tautology) @patch.object(AlertmanagerCharm, "_check_config", lambda *a, **kw: ("ok", "")) - @patch("charm.KubernetesServicePatch", lambda x, y: None) + @patch("charm.KubernetesServicePatch", lambda *_, **__: None) @k8s_resource_multipatch @patch("lightkube.core.client.GenericSyncClient") def setUp(self, *unused): diff --git a/tests/unit/test_external_url.py b/tests/unit/test_external_url.py index c25c56db..a7e7f5ae 100644 --- a/tests/unit/test_external_url.py +++ b/tests/unit/test_external_url.py @@ -24,7 +24,7 @@ class TestExternalUrl(unittest.TestCase): @patch.object(Alertmanager, "reload", tautology) @patch.object(AlertmanagerCharm, "_check_config", lambda *a, **kw: ("ok", "")) - @patch("charm.KubernetesServicePatch", lambda x, y: None) + @patch("charm.KubernetesServicePatch", lambda *_, **__: None) @patch("socket.getfqdn", new=lambda *args: "fqdn") @k8s_resource_multipatch @patch("lightkube.core.client.GenericSyncClient") diff --git a/tests/unit/test_remote_configuration_requirer.py b/tests/unit/test_remote_configuration_requirer.py index 63312370..c63b90e9 100644 --- a/tests/unit/test_remote_configuration_requirer.py +++ b/tests/unit/test_remote_configuration_requirer.py @@ -43,7 +43,7 @@ class TestAlertmanagerRemoteConfigurationRequirer(unittest.TestCase): @patch("lightkube.core.client.GenericSyncClient") @patch.object(AlertmanagerCharm, "_check_config", lambda *a, **kw: ("ok", "")) - @patch("charm.KubernetesServicePatch", lambda x, y: None) + @patch("charm.KubernetesServicePatch", lambda *_, **__: None) @k8s_resource_multipatch def setUp(self, _) -> None: self.harness = testing.Harness(AlertmanagerCharm)