Make charm accessible and introspectable

By default, expose this charm as a LoadBalancer service to allow
external access from outside of K8S which is its principle use
case.

Add action to allow introspection of the deployed service for
the URL to connect to the Southbound DB relay.

Change-Id: Ie234ca70d9090be463b5c971a8f01302958c91f5
This commit is contained in:
James Page 2022-10-11 14:28:47 +01:00
parent 38f9b79ba1
commit f98f9f6690
4 changed files with 32 additions and 4 deletions

View File

@ -1,2 +1,2 @@
# NOTE: no actions yet!
{ }
get-southbound-db-url:
description: Southbound DB Connection URL for access to OVN via the relay.

View File

@ -25,7 +25,9 @@ develop a new k8s charm using the Operator Framework:
"""
import logging
from typing import List, Mapping
from ipaddress import IPv4Address, IPv6Address
from typing import List, Mapping, Union
from ops.framework import StoredState
from ops.main import main
@ -87,8 +89,27 @@ class OVNRelayOperatorCharm(ovn_charm.OSBaseOVNOperatorCharm):
self,
[
('southbound', 6642),
]
],
service_type="LoadBalancer"
)
self.framework.observe(
self.on.get_southbound_db_url_action,
self._get_southbound_db_url_action
)
def _get_southbound_db_url_action(self, event):
event.set_results({"url": self.southbound_db_url})
@property
def ingress_address(self) -> Union[IPv4Address, IPv6Address]:
"""Network IP address for access to the OVN relay service."""
return self.model.get_binding(
'ovsdb-cms-relay').network.ingress_addresses[0]
@property
def southbound_db_url(self) -> str:
"""Full connection URL for Southbound DB relay."""
return f"ssl:{self.ingress_address}:6442"
def get_pebble_handlers(self):
pebble_handlers = [

1
tests/actions.yaml Symbolic link
View File

@ -0,0 +1 @@
../actions.yaml

View File

@ -63,3 +63,9 @@ class TestOVNRelayXenaOperatorCharm(test_utils.CharmTestCase):
'/root/ovn-relay-wrapper.sh']
for f in ovsdb_config_files:
self.check_file('ovsdb-server', f)
def test_southbound_db_url(self):
self.assertEqual(
'ssl:10.0.0.10:6442',
self.harness.charm.southbound_db_url
)