Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use charmed-mysql rock instead of the docker image #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ resources:
mysql-router-image:
type: oci-image
description: OCI image for mysql-router
# TODO: replace with canonical maintained image
upstream-source: dataplatformoci/mysql-router:8.0-22.04_edge
upstream-source: ghcr.io/canonical/charmed-mysql@sha256:924cb913733002e0936a36b6edab0bb8a4d72f1b92be0e0b7a933e797b7ef215
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: update the image hash once canonical/charmed-mysql-rock#23 is merged

assumes:
- k8s-api
12 changes: 5 additions & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
DATABASE_PROVIDES_RELATION,
DATABASE_REQUIRES_RELATION,
MYSQL_DATABASE_CREATED,
MYSQL_GROUP_NAME,
MYSQL_ROUTER_CONTAINER_NAME,
MYSQL_ROUTER_REQUIRES_DATA,
MYSQL_ROUTER_SERVICE_NAME,
MYSQL_USER_NAME,
NUM_UNITS_BOOTSTRAPPED,
PEER,
UNIT_BOOTSTRAPPED,
Expand Down Expand Up @@ -190,14 +192,10 @@ def mysql_router_layer(self) -> Layer:
MYSQL_ROUTER_SERVICE_NAME: {
"override": "replace",
"summary": "mysql router",
"command": "/run.sh mysqlrouter",
"command": "mysqlrouter --config /etc/mysqlrouter/mysqlrouter.conf",
"startup": "enabled",
"environment": {
"MYSQL_HOST": host,
"MYSQL_PORT": port,
"MYSQL_USER": requires_data["username"],
"MYSQL_PASSWORD": self.get_secret("app", "database-password") or "",
},
"user": MYSQL_USER_NAME,
"group": MYSQL_GROUP_NAME,
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
MYSQL_ROUTER_REQUIRES_DATA = "requires-data"
MYSQL_ROUTER_REQUIRES_APPLICATION_DATA = "requires-application-data"
MYSQL_ROUTER_SERVICE_NAME = "mysql_router"
MYSQL_ROUTER_USER_NAME = "mysqlrouter"
MYSQL_USER_NAME = "mysql"
MYSQL_GROUP_NAME = "mysql"
PASSWORD_LENGTH = 24
PEER = "mysql-router-peers"
ROUTER_CONFIG_DIRECTORY = "/tmp/mysqlrouter"
Expand Down
19 changes: 19 additions & 0 deletions src/relations/database_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
MYSQL_ROUTER_REQUIRES_APPLICATION_DATA,
MYSQL_ROUTER_REQUIRES_DATA,
MYSQL_ROUTER_SERVICE_NAME,
MYSQL_USER_NAME,
PASSWORD_LENGTH,
PEER,
UNIT_BOOTSTRAPPED,
Expand Down Expand Up @@ -158,6 +159,24 @@ def _on_backend_database_created(self, event: DatabaseCreatedEvent) -> None:
if self.charm.app_peer_data.get(MYSQL_DATABASE_CREATED):
return

container = self.charm.unit.get_container(MYSQL_ROUTER_CONTAINER_NAME)
# force somehow needed because router bootstrapped for "system" already
# (maybe because /etc/mysqlrouter/mysqlrouter.conf exists when router
# installed from canonical PPA?)
bootstrap_mysql_router_command = f"""
mysqlrouter
--user {MYSQL_USER_NAME}
--bootstrap {event.username}:{event.password}@{event.endpoints.split(",")[0]}
--conf-base-port 6446
--conf-set-option DEFAULT.server_ssl_mode=PREFERRED
--conf-set-option http_server.bind_address=127.0.0.1
--conf-use-gr-notifications
--force
""".split()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to bootstrap mysqlrouter when the application is scaled to more than 1 unit


process = container.exec(bootstrap_mysql_router_command)
process.wait_output()

self.charm.app_peer_data[MYSQL_ROUTER_REQUIRES_DATA] = json.dumps(
{
"username": event.username,
Expand Down
11 changes: 6 additions & 5 deletions src/relations/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
from ops.pebble import Layer, PathError

from constants import (
MYSQL_GROUP_NAME,
MYSQL_ROUTER_CONTAINER_NAME,
MYSQL_ROUTER_SERVICE_NAME,
MYSQL_ROUTER_USER_NAME,
MYSQL_USER_NAME,
ROUTER_CONFIG_DIRECTORY,
TLS_RELATION,
TLS_SSL_CERT_FILE,
Expand Down Expand Up @@ -256,8 +257,8 @@ def _create_tls_config_file(self) -> None:
self._write_content_to_file(
f"{ROUTER_CONFIG_DIRECTORY}/{TLS_SSL_CONFIG_FILE}",
config_string,
owner=MYSQL_ROUTER_USER_NAME,
group=MYSQL_ROUTER_USER_NAME,
owner=MYSQL_USER_NAME,
group=MYSQL_GROUP_NAME,
permission=0o600,
)

Expand All @@ -268,8 +269,8 @@ def _push_tls_files_to_workload(self) -> None:
self._write_content_to_file(
f"{ROUTER_CONFIG_DIRECTORY}/{value}",
self.charm.get_secret(SCOPE, key),
owner=MYSQL_ROUTER_USER_NAME,
group=MYSQL_ROUTER_USER_NAME,
owner=MYSQL_USER_NAME,
group=MYSQL_GROUP_NAME,
permission=0o600,
)

Expand Down