Skip to content

Commit

Permalink
Support juju expose (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical authored Aug 28, 2023
1 parent 0d73dcb commit ac5c0c2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from socket import getfqdn
from typing import Optional

import ops
from charms.data_platform_libs.v0.s3 import S3Requirer
from charms.grafana_k8s.v0.grafana_dashboard import GrafanaDashboardProvider
from charms.loki_k8s.v0.loki_push_api import LogProxyConsumer
Expand Down Expand Up @@ -426,6 +427,18 @@ def _on_leader_elected(self, _: LeaderElectedEvent) -> None:
"app", required_password, generate_random_password(PASSWORD_LENGTH)
)

def _open_ports(self) -> None:
"""Open ports if supported.
Used if `juju expose` ran on application
"""
if ops.JujuVersion.from_environ().supports_open_port_on_k8s:
try:
self.unit.open_port("tcp", 3306)
self.unit.open_port("tcp", 33060)
except ops.ModelError:
logger.exception("failed to open port")

def _configure_instance(self, container) -> bool:
"""Configure the instance for use in Group Replication."""
try:
Expand Down Expand Up @@ -466,6 +479,8 @@ def _configure_instance(self, container) -> bool:
logger.debug("Unable to configure instance: {}".format(e))
return False

self._open_ports()

try:
# Set workload version
if workload_version := self._mysql.get_mysql_version():
Expand Down

0 comments on commit ac5c0c2

Please sign in to comment.