Skip to content

Commit

Permalink
Remove double observe (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
sed-i authored Jan 17, 2023
1 parent 66ab949 commit 59db306
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
25 changes: 6 additions & 19 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_external_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_remote_configuration_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59db306

Please sign in to comment.