Skip to content

Commit 8a646b4

Browse files
authored
Adds fix to update Services if loadbalancer-extra-annotations config option is set (#451)
## Issue [450](#450) Configuring `loadbalancer-extra-annotations` doesn't update the Kubernetes Service ## Solution Updates the check for recreating the LoadBalancer service to verify if the current annotations match the value set inside `loadbalancer-extra-annotations` config option. If they don't match, it will update the service inside K8s
1 parent 94192d9 commit 8a646b4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/charm.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,22 @@ def _reconcile_service(self) -> None:
184184
service = self._get_service()
185185
service_exists = service is not None
186186
service_type = service_exists and _ServiceType(service.spec.type)
187-
if service_exists and service_type == desired_service_type:
188-
return
189-
190-
pod0 = self._get_pod(f"{self.app.name}/0")
191-
187+
service_annotations = {}
188+
if service_exists:
189+
service_annotations = service.metadata.annotations or {}
192190
annotations = (
193191
json.loads(self.config.get("loadbalancer-extra-annotations", "{}"))
194192
if desired_service_type == _ServiceType.LOAD_BALANCER
195193
else {}
196194
)
195+
if (
196+
service_exists
197+
and service_type == desired_service_type
198+
and service_annotations == annotations
199+
):
200+
return
201+
202+
pod0 = self._get_pod(f"{self.app.name}/0")
197203

198204
desired_service = lightkube.resources.core_v1.Service(
199205
metadata=lightkube.models.meta_v1.ObjectMeta(

0 commit comments

Comments
 (0)