From b5d0a7a524bd7d1e14d96c07596f4c6e1e40bc2d Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 22 Jan 2023 21:28:06 +0000 Subject: [PATCH 1/2] Build memory limits/requests should be `ByteSpecification` --- binderhub/build.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/binderhub/build.py b/binderhub/build.py index 5e0234f0d..22fac12f0 100644 --- a/binderhub/build.py +++ b/binderhub/build.py @@ -19,7 +19,7 @@ from traitlets import Any, Bool, Dict, Integer, Unicode, default from traitlets.config import LoggingConfigurable -from .utils import KUBE_REQUEST_TIMEOUT, rendezvous_rank +from .utils import KUBE_REQUEST_TIMEOUT, ByteSpecification, rendezvous_rank class ProgressEvent: @@ -91,8 +91,10 @@ class BuildExecutor(LoggingConfigurable): config=True, ) - memory_limit = Integer( - 0, help="Memory limit for the build process in bytes", config=True + memory_limit = ByteSpecification( + 0, + help="Memory limit for the build process in bytes (optional suffixes K M G T).", + config=True, ) appendix = Unicode( @@ -261,10 +263,10 @@ def _default_builder_info(self): config=True, ) - memory_request = Integer( + memory_request = ByteSpecification( 0, help=( - "Memory request of the build pod. " + "Memory request of the build pod in bytes (optional suffixes K M G T). " "The actual building happens in the docker daemon, " "but setting request in the build pod makes sure that memory is reserved for the docker build " "in the node by the kubernetes scheduler." From 9046454d6aaca213e53bbccb08a5ed3727f8050a Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 22 Jan 2023 21:39:37 +0000 Subject: [PATCH 2/2] Test build memory limits --- binderhub/tests/test_build.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/binderhub/tests/test_build.py b/binderhub/tests/test_build.py index e2ef2fba3..7f7a795ea 100644 --- a/binderhub/tests/test_build.py +++ b/binderhub/tests/test_build.py @@ -201,6 +201,31 @@ def test_sticky_builds_affinity(): ].preference.match_expressions[0].values[0] in ("node-a", "node-b") +def test_build_memory_limits(): + # Setup some mock objects for the response from the k8s API + mock_k8s_api = _list_image_builder_pods_mock() + + build = KubernetesBuildExecutor( + q=mock.MagicMock(), + api=mock_k8s_api, + name="test_build", + namespace="build_namespace", + repo_url="repo", + ref="ref", + build_image="image", + image_name="name", + push_secret="", + memory_limit="2T", + memory_request="123G", + git_credentials="", + docker_host="http://mydockerregistry.local", + node_selector={}, + sticky_builds=True, + ) + assert build.memory_limit == 2199023255552 + assert build.memory_request == 132070244352 + + def test_git_credentials_passed_to_podspec_upon_submit(): git_credentials = """{ "client_id": "my_username",