all repos — janny @ bcfc8d6f2d4205994e1cf0889d7b05cbc540f147

clean up Kubernetes resources after a set TTL

Refactor get_resource_urls() to return a dict
Anirudh Oppiliappan x@icyphox.sh
Sun, 07 Mar 2021 22:07:56 +0530
commit

bcfc8d6f2d4205994e1cf0889d7b05cbc540f147

parent

b5e067ac1e28790ab3330714a2a014d0a7160dc5

3 files changed, 13 insertions(+), 10 deletions(-)

jump to
M janny/auth.pyjanny/auth.py

@@ -20,4 +20,5 @@ logging.info("Not in-cluster, continuing as is")

return session + SESSION = kube_auth()
M janny/main.pyjanny/main.py

@@ -1,20 +1,21 @@

from janny.utils import get -def get_resources(): + +def get_resource_urls(): apis = get("/apis/") apiv1 = get("/api/v1") - resource_objs = list() - resource_objs.append(apiv1.resources) + resource_urls = dict() + resource_urls["/api/v1"] = apiv1.resources for g in apis.groups: - resource_objs.append(get("/apis/" + g.preferredVersion.groupVersion).resources) + version = g.preferredVersion.groupVersion + resource_urls["/apis/" + version] = get( + "/apis/" + g.preferredVersion.groupVersion + ).resources - for resources in resource_objs: - for r in resources: - if "/" not in r.name and r.namespaced: - yield r.name + return resource_urls + def main(): - for r in get_resources(): - print(r) + get_resource_urls()
M janny/utils.pyjanny/utils.py

@@ -5,6 +5,7 @@

from janny.config import API_HOST from janny.auth import SESSION + def get(path): """Convert a JSON response into a Python object""" s = SESSION