Skip to content

Commit a7c99af

Browse files
DPE-1794 Implement COS integration (#93)
## Issue We need to introduce COS support for MySQLRouter ## Solution 1. Introduce COS support for MySQLRouter 2. Introduce the scaffolding for secrets to be able to store the monitoring password in the juju secrets backend ## Prerequisites 1. We need to merge the [snap PR](canonical/charmed-mysql-snap#41) that adds the COS machinery to the snap. After, we need to update the snap revision in the `snap.py` file 2. We need to import the secrets lib after the [following secrets PR in data-platform-libs](canonical/data-platform-libs#117) is merged ## TODO 1. ~~Determine why the `All Connections Information` and `Route byte to/from server` sections on the dashboard are not populated when more than 1 routers are deployed~~ (see #93 (comment)) 2. ~~Test router log collection (via Loki) when [the following issue is resolved](canonical/grafana-agent-operator#56 (see #93 (comment)) ## Demo ![image](https://github.com/canonical/mysql-router-operator/assets/99665202/e2173939-c2e8-4de2-a007-bb0dbb2269d4)
1 parent a7f6970 commit a7c99af

File tree

20 files changed

+3984
-551
lines changed

20 files changed

+3984
-551
lines changed

lib/charms/data_platform_libs/v0/data_interfaces.py

Lines changed: 998 additions & 436 deletions
Large diffs are not rendered by default.

lib/charms/grafana_agent/v0/cos_agent.py

Lines changed: 806 additions & 0 deletions
Large diffs are not rendered by default.

lib/charms/operator_libs_linux/v2/snap.py

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
# Increment this PATCH version before using `charmcraft publish-lib` or reset
8585
# to 0 if you are raising the major API version
86-
LIBPATCH = 3
86+
LIBPATCH = 4
8787

8888

8989
# Regex to locate 7-bit C1 ANSI sequences
@@ -214,7 +214,7 @@ class Snap(object):
214214
- state: a `SnapState` representation of its install status
215215
- channel: "stable", "candidate", "beta", and "edge" are common
216216
- revision: a string representing the snap's revision
217-
- confinement: "classic" or "strict"
217+
- confinement: "classic", "strict", or "devmode"
218218
"""
219219

220220
def __init__(
@@ -475,6 +475,8 @@ def _install(
475475
args = []
476476
if self.confinement == "classic":
477477
args.append("--classic")
478+
if self.confinement == "devmode":
479+
args.append("--devmode")
478480
if channel:
479481
args.append('--channel="{}"'.format(channel))
480482
if revision:
@@ -489,6 +491,7 @@ def _refresh(
489491
channel: Optional[str] = "",
490492
cohort: Optional[str] = "",
491493
revision: Optional[str] = None,
494+
devmode: bool = False,
492495
leave_cohort: Optional[bool] = False,
493496
) -> None:
494497
"""Refresh a snap.
@@ -497,6 +500,7 @@ def _refresh(
497500
channel: the channel to install from
498501
cohort: optionally, specify a cohort.
499502
revision: optionally, specify the revision of the snap to refresh
503+
devmode: optionally, specify devmode confinement
500504
leave_cohort: leave the current cohort.
501505
"""
502506
args = []
@@ -506,6 +510,9 @@ def _refresh(
506510
if revision:
507511
args.append('--revision="{}"'.format(revision))
508512

513+
if devmode:
514+
args.append("--devmode")
515+
509516
if not cohort:
510517
cohort = self._cohort
511518

@@ -530,6 +537,7 @@ def ensure(
530537
self,
531538
state: SnapState,
532539
classic: Optional[bool] = False,
540+
devmode: bool = False,
533541
channel: Optional[str] = "",
534542
cohort: Optional[str] = "",
535543
revision: Optional[str] = None,
@@ -539,6 +547,7 @@ def ensure(
539547
Args:
540548
state: a `SnapState` to reconcile to.
541549
classic: an (Optional) boolean indicating whether classic confinement should be used
550+
devmode: an (Optional) boolean indicating whether devmode confinement should be used
542551
channel: the channel to install from
543552
cohort: optional. Specify the key of a snap cohort.
544553
revision: optional. the revision of the snap to install/refresh
@@ -549,7 +558,15 @@ def ensure(
549558
Raises:
550559
SnapError if an error is encountered
551560
"""
552-
self._confinement = "classic" if classic or self._confinement == "classic" else ""
561+
if classic and devmode:
562+
raise ValueError("Cannot set both classic and devmode confinement")
563+
564+
if classic or self._confinement == "classic":
565+
self._confinement = "classic"
566+
elif devmode or self._confinement == "devmode":
567+
self._confinement = "devmode"
568+
else:
569+
self._confinement = ""
553570

554571
if state not in (SnapState.Present, SnapState.Latest):
555572
# We are attempting to remove this snap.
@@ -566,7 +583,7 @@ def ensure(
566583
self._install(channel, cohort, revision)
567584
else:
568585
# The snap is installed, but we are changing it (e.g., switching channels).
569-
self._refresh(channel, cohort, revision)
586+
self._refresh(channel=channel, cohort=cohort, revision=revision, devmode=devmode)
570587

571588
self._update_snap_apps()
572589
self._state = state
@@ -892,6 +909,7 @@ def add(
892909
state: Union[str, SnapState] = SnapState.Latest,
893910
channel: Optional[str] = "",
894911
classic: Optional[bool] = False,
912+
devmode: bool = False,
895913
cohort: Optional[str] = "",
896914
revision: Optional[str] = None,
897915
) -> Union[Snap, List[Snap]]:
@@ -904,6 +922,8 @@ def add(
904922
channel: an (Optional) channel as a string. Defaults to 'latest'
905923
classic: an (Optional) boolean specifying whether it should be added with classic
906924
confinement. Default `False`
925+
devmode: an (Optional) boolean specifying whether it should be added with devmode
926+
confinement. Default `False`
907927
cohort: an (Optional) string specifying the snap cohort to use
908928
revision: an (Optional) string specifying the snap revision to use
909929
@@ -920,7 +940,7 @@ def add(
920940
if isinstance(state, str):
921941
state = SnapState(state)
922942

923-
return _wrap_snap_operations(snap_names, state, channel, classic, cohort, revision)
943+
return _wrap_snap_operations(snap_names, state, channel, classic, devmode, cohort, revision)
924944

925945

926946
@_cache_init
@@ -936,8 +956,13 @@ def remove(snap_names: Union[str, List[str]]) -> Union[Snap, List[Snap]]:
936956
snap_names = [snap_names] if isinstance(snap_names, str) else snap_names
937957
if not snap_names:
938958
raise TypeError("Expected at least one snap to add, received zero!")
939-
940-
return _wrap_snap_operations(snap_names, SnapState.Absent, "", False)
959+
return _wrap_snap_operations(
960+
snap_names=snap_names,
961+
state=SnapState.Absent,
962+
channel="",
963+
classic=False,
964+
devmode=False,
965+
)
941966

942967

943968
@_cache_init
@@ -946,6 +971,7 @@ def ensure(
946971
state: str,
947972
channel: Optional[str] = "",
948973
classic: Optional[bool] = False,
974+
devmode: bool = False,
949975
cohort: Optional[str] = "",
950976
revision: Optional[int] = None,
951977
) -> Union[Snap, List[Snap]]:
@@ -957,6 +983,8 @@ def ensure(
957983
channel: an (Optional) channel as a string. Defaults to 'latest'
958984
classic: an (Optional) boolean specifying whether it should be added with classic
959985
confinement. Default `False`
986+
devmode: an (Optional) boolean specifying whether it should be added with devmode
987+
confinement. Default `False`
960988
cohort: an (Optional) string specifying the snap cohort to use
961989
revision: an (Optional) integer specifying the snap revision to use
962990
@@ -970,7 +998,15 @@ def ensure(
970998
channel = "latest"
971999

9721000
if state in ("present", "latest") or revision:
973-
return add(snap_names, SnapState(state), channel, classic, cohort, revision)
1001+
return add(
1002+
snap_names=snap_names,
1003+
state=SnapState(state),
1004+
channel=channel,
1005+
classic=classic,
1006+
devmode=devmode,
1007+
cohort=cohort,
1008+
revision=revision,
1009+
)
9741010
else:
9751011
return remove(snap_names)
9761012

@@ -980,6 +1016,7 @@ def _wrap_snap_operations(
9801016
state: SnapState,
9811017
channel: str,
9821018
classic: bool,
1019+
devmode: bool,
9831020
cohort: Optional[str] = "",
9841021
revision: Optional[str] = None,
9851022
) -> Union[Snap, List[Snap]]:
@@ -995,7 +1032,12 @@ def _wrap_snap_operations(
9951032
snap.ensure(state=SnapState.Absent)
9961033
else:
9971034
snap.ensure(
998-
state=state, classic=classic, channel=channel, cohort=cohort, revision=revision
1035+
state=state,
1036+
classic=classic,
1037+
devmode=devmode,
1038+
channel=channel,
1039+
cohort=cohort,
1040+
revision=revision,
9991041
)
10001042
snaps["success"].append(snap)
10011043
except SnapError as e:
@@ -1014,13 +1056,17 @@ def _wrap_snap_operations(
10141056

10151057

10161058
def install_local(
1017-
filename: str, classic: Optional[bool] = False, dangerous: Optional[bool] = False
1059+
filename: str,
1060+
classic: Optional[bool] = False,
1061+
devmode: Optional[bool] = False,
1062+
dangerous: Optional[bool] = False,
10181063
) -> Snap:
10191064
"""Perform a snap operation.
10201065
10211066
Args:
10221067
filename: the path to a local .snap file to install
10231068
classic: whether to use classic confinement
1069+
devmode: whether to use devmode confinement
10241070
dangerous: whether --dangerous should be passed to install snaps without a signature
10251071
10261072
Raises:
@@ -1033,6 +1079,8 @@ def install_local(
10331079
]
10341080
if classic:
10351081
args.append("--classic")
1082+
if devmode:
1083+
args.append("--devmode")
10361084
if dangerous:
10371085
args.append("--dangerous")
10381086
try:

metadata.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ provides:
2626
shared-db:
2727
interface: mysql-shared
2828
scope: container
29+
cos-agent:
30+
interface: cos_agent
31+
limit: 1
2932
requires:
3033
backend-database:
3134
interface: mysql_client
@@ -36,14 +39,13 @@ requires:
3639
interface: juju-info
3740
scope: container
3841
peers:
42+
cos:
43+
interface: cos
3944
upgrade-version-a:
4045
# Relation versioning scheme:
4146
# DA056 - Upgrading in-place upgrade protocol
4247
# https://docs.google.com/document/d/1H7qy5SAwLiCOKO9xMQJbbQP5_-jGV6Lhi-mJOk4gZ08/edit
4348
interface: upgrade
44-
# TODO TLS VM: re-enable peer relation
45-
# mysql-router-peers:
46-
# interface: mysql_router_peers
4749
# DEPRECATED shared-db: Workaround for legacy "mysql-shared" interface using unit databags instead of app databag
4850
deprecated-shared-db-credentials:
4951
interface: _deprecated_shared_db_peers

0 commit comments

Comments
 (0)