Skip to content

Commit e7d7efd

Browse files
[DPE-5417] Add check to ensure peer databag populated before reconciling mysqld exporter pebble layers (#505)
* Add check to ensure peer databag populated before reconciling mysqld exporter pebble layers * Do not return a value * Add integration test to ensure bundle with grafana-agent integration does not error * Add missing poetry lock file update
1 parent 2009919 commit e7d7efd

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

poetry.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/charm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ def _reconcile_mysqld_exporter(
459459
self, event: RelationCreatedEvent | RelationBrokenEvent
460460
) -> None:
461461
"""Handle a COS relation created or broken event."""
462+
if not self._is_peer_data_set:
463+
logger.debug("Unit not yet ready to reconcile mysqld exporter. Waiting...")
464+
return
465+
462466
container = self.unit.get_container(CONTAINER_NAME)
463467
if not container.can_connect():
464468
# reconciliation is done on pebble ready
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bundle: kubernetes
2+
name: testing
3+
applications:
4+
mysql-k8s:
5+
charm: {{ mysql_charm_path }}
6+
trust: true
7+
scale: 1
8+
constraints: mem=2G
9+
resources:
10+
mysql-image: {{ mysql_image_source }}
11+
grafana-agent-k8s:
12+
charm: grafana-agent-k8s
13+
channel: latest/stable
14+
scale: 1
15+
relations:
16+
- [mysql-k8s:metrics-endpoint, grafana-agent-k8s:metrics-endpoint]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2024 Canonical Ltd.
3+
# See LICENSE file for licensing details.
4+
5+
import logging
6+
import pathlib
7+
import tempfile
8+
9+
import jinja2
10+
import pytest
11+
import yaml
12+
from pytest_operator.plugin import OpsTest
13+
14+
logger = logging.getLogger(__name__)
15+
16+
METADATA = yaml.safe_load(pathlib.Path("./metadata.yaml").read_text())
17+
IMAGE_SOURCE = METADATA["resources"]["mysql-image"]["upstream-source"]
18+
TIMEOUT = 10 * 60
19+
20+
21+
@pytest.mark.group(1)
22+
@pytest.mark.abort_on_fail
23+
async def test_deploy_bundle_with_cos_integrations(ops_test: OpsTest) -> None:
24+
"""Test COS integrations formed before mysql is allocated and deployed."""
25+
logger.info("Building the mysql-k8s charm")
26+
charm_path = await ops_test.build_charm(".")
27+
28+
bundle_template = jinja2.Template(
29+
pathlib.Path(
30+
"./tests/integration/bundle_templates/grafana_agent_integration.j2"
31+
).read_text()
32+
)
33+
rendered_bundle = bundle_template.render(
34+
mysql_charm_path=str(charm_path), mysql_image_source=IMAGE_SOURCE
35+
)
36+
37+
with tempfile.NamedTemporaryFile(mode="w+", suffix=".yaml") as rendered_bundle_file:
38+
rendered_bundle_file.write(rendered_bundle)
39+
rendered_bundle_file.flush()
40+
41+
logger.info("Deploying grafana_agent_integration bundle")
42+
await ops_test.model.deploy(f"local:{rendered_bundle_file.name}", trust=True)
43+
44+
logger.info("Waiting until mysql-k8s becomes active")
45+
await ops_test.model.wait_for_idle(
46+
apps=["mysql-k8s"],
47+
status="active",
48+
raise_on_blocked=True,
49+
timeout=TIMEOUT,
50+
)

0 commit comments

Comments
 (0)