From d00706531560c08ed31812ef9d61d2cf0c878e24 Mon Sep 17 00:00:00 2001 From: Ali Kelkawi <81743070+kelkawi-a@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:32:34 +0300 Subject: [PATCH] Address charm review comments (#11) * address charm review comments --- README.md | 3 +++ charmcraft.yaml | 4 ++++ src/charm.py | 29 +++++++++++++++++++++-------- src/literals.py | 10 ++++++++++ src/relations/airbyte_server.py | 3 ++- tests/conftest.py | 2 +- 6 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/literals.py diff --git a/README.md b/README.md index c7494d1..5be1c8c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Charmhub Badge](https://charmhub.io/airbyte-ui-k8s/badge.svg)](https://charmhub.io/airbyte-ui-k8s) +[![Release Edge](https://github.com/canonical/airbyte-ui-k8s-operator/actions/workflows/publish_charm.yaml/badge.svg)](https://github.com/canonical/airbyte-ui-k8s-operator/actions/workflows/publish_charm.yaml) + # Airbyte UI K8s Operator This is the Kubernetes Python Operator for the diff --git a/charmcraft.yaml b/charmcraft.yaml index a74a813..3439acf 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -17,6 +17,10 @@ description: | to view and configure different connections. links: documentation: https://discourse.charmhub.io/t/charmed-airbyte-ui-k8s-overview/14529 + source: + - https://github.com/canonical/airbyte-ui-k8s-operator + issues: + - https://github.com/canonical/airbyte-ui-k8s-operator/issues # (Required for 'charm' type) bases: diff --git a/src/charm.py b/src/charm.py index 984801d..8210255 100755 --- a/src/charm.py +++ b/src/charm.py @@ -9,20 +9,22 @@ from charms.nginx_ingress_integrator.v0.nginx_route import require_nginx_route from ops import main, pebble from ops.charm import CharmBase -from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus +from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus, WaitingStatus from ops.pebble import CheckStatus +from literals import ( + AIRBYTE_SERVER_RELATION, + AIRBYTE_VERSION, + CONNECTOR_BUILDER_API_PORT, + INTERNAL_API_PORT, + WEB_UI_PORT, +) from log import log_event_handler from relations.airbyte_server import AirbyteServer from state import State logger = logging.getLogger(__name__) -WEB_UI_PORT = 8080 -INTERNAL_API_PORT = 8001 -CONNECTOR_BUILDER_API_PORT = 80 -AIRBYTE_VERSION = "0.60.0" - class AirbyteUIK8sOperatorCharm(CharmBase): """Airbyte UI charm. @@ -51,6 +53,7 @@ def __init__(self, *args): self.framework.observe(self.on.update_status, self._on_update_status) self.framework.observe(self.on.restart_action, self._on_restart) self.framework.observe(self.on.peer_relation_changed, self._on_peer_relation_changed) + self.framework.observe(self.on.config_changed, self._on_config_changed) # Handle Airbyte server relation self.airbyte_server = AirbyteServer(self) @@ -87,6 +90,16 @@ def _on_peer_relation_changed(self, event): """ self._update(event) + @log_event_handler(logger) + def _on_config_changed(self, event): + """Handle changed configuration. + + Args: + event: The event triggered when the relation changed. + """ + self.unit.status = WaitingStatus("configuring application") + self._update(event) + @log_event_handler(logger) def _on_update_status(self, event): """Handle `update-status` events. @@ -154,10 +167,10 @@ def _validate(self): raise ValueError("peer relation not ready") if not self._state.airbyte_server: - raise ValueError("airbyte-server relation: not available") + raise ValueError(f"{AIRBYTE_SERVER_RELATION} relation: not available") if not self._state.airbyte_server["status"] == "ready": - raise ValueError("airbyte-server relation: server is not ready") + raise ValueError(f"{AIRBYTE_SERVER_RELATION} relation: server is not ready") @log_event_handler(logger) def _update(self, event): diff --git a/src/literals.py b/src/literals.py new file mode 100644 index 0000000..28d68bc --- /dev/null +++ b/src/literals.py @@ -0,0 +1,10 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +"""Charm literals.""" + +WEB_UI_PORT = 8080 +INTERNAL_API_PORT = 8001 +CONNECTOR_BUILDER_API_PORT = 80 +AIRBYTE_VERSION = "0.60.0" +AIRBYTE_SERVER_RELATION = "airbyte-server" diff --git a/src/relations/airbyte_server.py b/src/relations/airbyte_server.py index f63330c..1d3c149 100644 --- a/src/relations/airbyte_server.py +++ b/src/relations/airbyte_server.py @@ -7,6 +7,7 @@ from ops import framework +from literals import AIRBYTE_SERVER_RELATION from log import log_event_handler logger = logging.getLogger(__name__) @@ -21,7 +22,7 @@ def __init__(self, charm): Args: charm: The charm to attach the hooks to. """ - super().__init__(charm, "airbyte-server") + super().__init__(charm, AIRBYTE_SERVER_RELATION) self.charm = charm charm.framework.observe(charm.on.airbyte_server_relation_joined, self._on_airbyte_server_relation_changed) charm.framework.observe(charm.on.airbyte_server_relation_changed, self._on_airbyte_server_relation_changed) diff --git a/tests/conftest.py b/tests/conftest.py index 0998abd..04df5c6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,7 @@ # Copyright 2024 Canonical Ltd. # See LICENSE file for licensing details. -"""Fixtures for jenkins-k8s charm tests.""" +"""Fixtures for charm tests.""" import pytest