Skip to content

Commit 65466e4

Browse files
authored
Merge pull request #1626 from manics/ByteSpecification
Build memory limits/requests should be `ByteSpecification`
2 parents 3114927 + 9046454 commit 65466e4

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

binderhub/build.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from traitlets import Any, Bool, Dict, Integer, Unicode, default
2020
from traitlets.config import LoggingConfigurable
2121

22-
from .utils import KUBE_REQUEST_TIMEOUT, rendezvous_rank
22+
from .utils import KUBE_REQUEST_TIMEOUT, ByteSpecification, rendezvous_rank
2323

2424

2525
class ProgressEvent:
@@ -91,8 +91,10 @@ class BuildExecutor(LoggingConfigurable):
9191
config=True,
9292
)
9393

94-
memory_limit = Integer(
95-
0, help="Memory limit for the build process in bytes", config=True
94+
memory_limit = ByteSpecification(
95+
0,
96+
help="Memory limit for the build process in bytes (optional suffixes K M G T).",
97+
config=True,
9698
)
9799

98100
appendix = Unicode(
@@ -261,10 +263,10 @@ def _default_builder_info(self):
261263
config=True,
262264
)
263265

264-
memory_request = Integer(
266+
memory_request = ByteSpecification(
265267
0,
266268
help=(
267-
"Memory request of the build pod. "
269+
"Memory request of the build pod in bytes (optional suffixes K M G T). "
268270
"The actual building happens in the docker daemon, "
269271
"but setting request in the build pod makes sure that memory is reserved for the docker build "
270272
"in the node by the kubernetes scheduler."

binderhub/tests/test_build.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,31 @@ def test_sticky_builds_affinity():
201201
].preference.match_expressions[0].values[0] in ("node-a", "node-b")
202202

203203

204+
def test_build_memory_limits():
205+
# Setup some mock objects for the response from the k8s API
206+
mock_k8s_api = _list_image_builder_pods_mock()
207+
208+
build = KubernetesBuildExecutor(
209+
q=mock.MagicMock(),
210+
api=mock_k8s_api,
211+
name="test_build",
212+
namespace="build_namespace",
213+
repo_url="repo",
214+
ref="ref",
215+
build_image="image",
216+
image_name="name",
217+
push_secret="",
218+
memory_limit="2T",
219+
memory_request="123G",
220+
git_credentials="",
221+
docker_host="http://mydockerregistry.local",
222+
node_selector={},
223+
sticky_builds=True,
224+
)
225+
assert build.memory_limit == 2199023255552
226+
assert build.memory_request == 132070244352
227+
228+
204229
def test_git_credentials_passed_to_podspec_upon_submit():
205230
git_credentials = """{
206231
"client_id": "my_username",

0 commit comments

Comments
 (0)