Skip to content

Commit

Permalink
feat: add requested resources info to servers endpoint (#261)
Browse files Browse the repository at this point in the history
fix #223
  • Loading branch information
lorenzo-cavazzi committed Mar 16, 2020
1 parent 67b955b commit 9e233cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions renku_notebooks/util/kubernetes_.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,23 @@ def get_pod_status(pod):
status.update(conditions_summary)
return status

def get_pod_resources(pod):
try:
resources = pod.spec.containers[0].resources.requests
# translate the cpu weird numeric string to a normal number
# ref: https://kubernetes.io/docs/concepts/configuration/
# manage-compute-resources-container/#how-pods-with-resource-limits-are-run
if (
"cpu" in resources
and isinstance(resources["cpu"], str)
and str.endswith(resources["cpu"], "m")
and resources["cpu"][:-1].isdigit()
):
resources["cpu"] = str(int(resources["cpu"][:-1]) / 1000)
except (AttributeError, IndexError):
resources = {}
return resources

def get_server_url(pod):
url = "/jupyterhub/user/{username}/{servername}/".format(
username=pod.metadata.annotations["hub.jupyter.org/username"],
Expand All @@ -176,6 +193,7 @@ def get_server_url(pod):
"started": isoformat(pod.status.start_time),
"status": get_pod_status(pod),
"url": get_server_url(pod),
"resources": get_pod_resources(pod),
}
for pod in pods
}
Expand Down
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ def kubernetes_client(mocker):
},
],
},
"spec": {
"containers": [
{
"resources": {
"requests": {"cpu": "500m", "memory": "2147483648"}
}
}
]
},
}
]
}
Expand Down

0 comments on commit 9e233cf

Please sign in to comment.