all repos — janny @ 0d6df5bfac2c32e7db092d8ed4ecd19811ef25f3

clean up Kubernetes resources after a set TTL

Fix concurrency of cleanup jobs
Anirudh Oppiliappan x@icyphox.sh
Sun, 14 Mar 2021 13:46:31 +0530
commit

0d6df5bfac2c32e7db092d8ed4ecd19811ef25f3

parent

ec88575db2d8915a34cc523c2e2f01af6575ee4f

2 files changed, 4 insertions(+), 3 deletions(-)

jump to
M deploy/deployment.yamldeploy/deployment.yaml

@@ -23,6 +23,6 @@ image: janny:latest

imagePullPolicy: IfNotPresent args: - "--included-resources" - - "deployments,configmaps,pods" + - "deployments,services,ingresses" - "--namespaces" - "default"
M janny/main.pyjanny/main.py

@@ -47,12 +47,13 @@ """

url, resource = resource_tuple resource_list = get(f"{url}/namespaces/{namespace}/{resource.name}") try: + # items = [i for r in resource_list.items if "janny.ttl" in vars(r.metadata.annotations) and r.metadata.name not in RUNNING] for r in resource_list.items: try: annotations = vars(r.metadata.annotations) if ( "janny.ttl" in annotations - and r.metadata.name not in RUNNING + and f"{resource}/{r.metadata.name}" not in RUNNING ): logger.info( f"New resource to clean up: {resource.name}/{r.metadata.name}: ttl: {annotations['janny.ttl']}"

@@ -69,7 +70,7 @@ namespace,

], ) logger.info(f"Starting cleaner thread for {r.metadata.name}") - RUNNING.append(r.metadata.name) + RUNNING.append(f"{resource}/{r.metadata.name}") t.start() except AttributeError: pass