Skip to content

Commit

Permalink
Address charm review comments (#11)
Browse files Browse the repository at this point in the history
* address charm review comments
  • Loading branch information
kelkawi-a authored Jul 16, 2024
1 parent c2bdab3 commit d007065
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 21 additions & 8 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions src/literals.py
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion src/relations/airbyte_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from ops import framework

from literals import AIRBYTE_SERVER_RELATION
from log import log_event_handler

logger = logging.getLogger(__name__)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit d007065

Please sign in to comment.