Skip to content

Commit

Permalink
[DPE-4861] Avoid ambiguous service selector when multiple mysql apps …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
shayancanonical committed Sep 10, 2024
1 parent ed0deb4 commit 0a9c34e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/k8s_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def create_endpoint_services(self, roles: List[str]) -> None:
roles: List of roles to append on the service name
"""
for role in roles:
selector = {"cluster-name": self.cluster_name, "role": role}
selector = {
"cluster-name": self.cluster_name,
"application-name": self.app_name,
"role": role,
}
service_name = f"{self.app_name}-{role}"
pod0 = self.client.get(
res=Pod,
Expand Down Expand Up @@ -128,6 +132,7 @@ def label_pod(self, role: str, pod_name: Optional[str] = None) -> None:
logger.debug(f"Patching {pod_name=} with {role=}")

pod.metadata.labels["cluster-name"] = self.cluster_name
pod.metadata.labels["application-name"] = self.app_name
pod.metadata.labels["role"] = role
self.client.patch(Pod, pod_name, pod)
except ApiError as e:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_k8s_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_create_endpoint_service(self, _create):
spec=ServiceSpec(
selector={
"cluster-name": self.harness.charm.app_peer_data.get("cluster-name"),
"application-name": self.harness.charm.model.app.name,
"role": "role1",
},
ports=[ServicePort(port=3306, targetPort=3306)],
Expand Down

0 comments on commit 0a9c34e

Please sign in to comment.