Skip to content

Commit

Permalink
Reduce the number of API calls to K8S
Browse files Browse the repository at this point in the history
The charm makes a large number of API calls to retrieve information
about the IP address allocated to the K8S service; cache this
information to reduce the number of calls made and speed up hook
performance.

Note functools.lru_cache is used as this charm runs on 20.04 which
uses Python 3.8 - when the base is updated to 22.04 the more simple
cache decorator can be used instead.
  • Loading branch information
javacruft committed Sep 14, 2023
1 parent 8204ffe commit 73f867e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""Charm Traefik."""
import contextlib
import enum
import functools
import ipaddress
import json
import logging
Expand Down Expand Up @@ -1271,6 +1272,7 @@ def _scrape_jobs(self) -> list:
]


@functools.lru_cache
def _get_loadbalancer_status(namespace: str, service_name: str):
client = Client() # type: ignore
traefik_service = client.get(Service, name=service_name, namespace=namespace)
Expand Down

0 comments on commit 73f867e

Please sign in to comment.