def delete_resources()

in eks_infrastructure/eks_cleanup/eks_cleanup_job.py [0:0]


def delete_resources(list_item, k8s_api, job_type, namespace):
    """
    Check the uptime for each resouce and delete if the uptime is greater than 3 hours
    """

    for item in list_item.items:
        item_name = item.metadata.name
        item_creation_time = item.metadata.creation_timestamp
        LOGGER.info(f"Resource name {item_name}")
        LOGGER.info(f"Resource creation time {item_creation_time}")

        # Do not delete the kubeflow mxnet operator as it is a system resource and exists in default namespace
        if "mxnet-operator" in item_name:
            continue

        hours = get_run_time(item_creation_time)
        LOGGER.info(f"Resource {item_name} up time in hours: {hours}")

        if hours >= JOB_TIMEOUT:
            LOGGER.info(f"Deleting resource {item_name}")
            if job_type == "deployment":
                k8s_api.delete_namespaced_deployment(item_name, namespace)
            if job_type == "pod":
                k8s_api.delete_namespaced_pod(item_name, namespace)