Skip to content

Commit 0a9c34e

Browse files
[DPE-4861] Avoid ambiguous service selector when multiple mysql apps in a model have the same cluster-name (#501)
* Avoid ambiguous service selector when multiple mysql apps in a model have the same cluster-name * Use hyphen instead of underscore * Fix failing unit test
1 parent ed0deb4 commit 0a9c34e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/k8s_helpers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def create_endpoint_services(self, roles: List[str]) -> None:
5454
roles: List of roles to append on the service name
5555
"""
5656
for role in roles:
57-
selector = {"cluster-name": self.cluster_name, "role": role}
57+
selector = {
58+
"cluster-name": self.cluster_name,
59+
"application-name": self.app_name,
60+
"role": role,
61+
}
5862
service_name = f"{self.app_name}-{role}"
5963
pod0 = self.client.get(
6064
res=Pod,
@@ -128,6 +132,7 @@ def label_pod(self, role: str, pod_name: Optional[str] = None) -> None:
128132
logger.debug(f"Patching {pod_name=} with {role=}")
129133

130134
pod.metadata.labels["cluster-name"] = self.cluster_name
135+
pod.metadata.labels["application-name"] = self.app_name
131136
pod.metadata.labels["role"] = role
132137
self.client.patch(Pod, pod_name, pod)
133138
except ApiError as e:

tests/unit/test_k8s_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def test_create_endpoint_service(self, _create):
4949
spec=ServiceSpec(
5050
selector={
5151
"cluster-name": self.harness.charm.app_peer_data.get("cluster-name"),
52+
"application-name": self.harness.charm.model.app.name,
5253
"role": "role1",
5354
},
5455
ports=[ServicePort(port=3306, targetPort=3306)],

0 commit comments

Comments
 (0)