Better error handling
Anirudh Oppiliappan x@icyphox.sh
Tue, 09 Mar 2021 18:13:59 +0530
3 files changed,
28 insertions(+),
19 deletions(-)
M
deploy/clusterrole.yaml
→
deploy/clusterrole.yaml
@@ -8,6 +8,7 @@ - ""
resources: - pods - services + - configmaps verbs: - get - list
M
deploy/deployment.yaml
→
deploy/deployment.yaml
@@ -21,3 +21,8 @@ containers:
- name: janny image: janny:latest imagePullPolicy: IfNotPresent + args: + - "--included-resources" + - "deployments,configmaps,pods" + - "--namespaces" + - "default"
M
janny/main.py
→
janny/main.py
@@ -49,25 +49,28 @@ Spawns a clean up job -- runs on a new thread.
""" url, resource = resource_tuple resource_list = get(f"{url}/namespaces/{namespace}/{resource.name}") - for r in resource_list.items: - try: - if ( - "janny.ttl" in vars(r.metadata.annotations) - and r.metadata.name not in RUNNING - ): - logger.info( - f"New resource to clean up: {resource.name}/{r.metadata.name}: {vars(r.metadata.annotations)}" - ) - kill_time = vars(r.metadata.annotations)["janny.ttl"] - t = threading.Thread( - target=clean_up, - args=[url, resource.name, r.metadata.name, kill_time, namespace], - ) - logger.info(f"Starting cleaner thread for {r.metadata.name}") - RUNNING.append(r.metadata.name) - t.start() - except AttributeError: - pass + try: + for r in resource_list.items: + try: + if ( + "janny.ttl" in vars(r.metadata.annotations) + and r.metadata.name not in RUNNING + ): + logger.info( + f"New resource to clean up: {resource.name}/{r.metadata.name}: {vars(r.metadata.annotations)}" + ) + kill_time = vars(r.metadata.annotations)["janny.ttl"] + t = threading.Thread( + target=clean_up, + args=[url, resource.name, r.metadata.name, kill_time, namespace], + ) + logger.info(f"Starting cleaner thread for {r.metadata.name}") + RUNNING.append(r.metadata.name) + t.start() + except AttributeError: + pass + except AttributeError: + logger.error(f"Received: {resource_list.message}") def main(include_list, namespace_list):