Skip to content

Commit ab236a9

Browse files
authored
Merge pull request #1144 from minrk/build-resource-request
add build_memory_request config
2 parents 19a37fe + 9447e17 commit ab236a9

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

binderhub/app.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,20 +306,34 @@ def _valid_badge_base_url(self, proposal):
306306
config=True
307307
)
308308

309+
build_memory_request = ByteSpecification(
310+
0,
311+
help="""
312+
Amount of memory to request when scheduling a build
313+
314+
0 reserves no memory.
315+
316+
This is used as the request for the pod that is spawned to do the building,
317+
even though the pod itself will not be using that much memory
318+
since the docker building is happening outside the pod.
319+
However, it makes kubernetes aware of the resources being used,
320+
and lets it schedule more intelligently.
321+
""",
322+
config=True,
323+
)
309324
build_memory_limit = ByteSpecification(
310325
0,
311326
help="""
312327
Max amount of memory allocated for each image build process.
313328
314329
0 sets no limit.
315330
316-
This is used as both the memory limit & request for the pod
317-
that is spawned to do the building, even though the pod itself
318-
will not be using that much memory since the docker building is
319-
happening outside the pod. However, it makes kubernetes aware of
320-
the resources being used, and lets it schedule more intelligently.
331+
This is applied to the docker build itself via repo2docker,
332+
though it is also applied to our pod that submits the build,
333+
even though that pod will rarely consume much memory.
334+
Still, it makes it easier to see the resource limits in place via kubernetes.
321335
""",
322-
config=True
336+
config=True,
323337
)
324338

325339
debug = Bool(
@@ -598,6 +612,7 @@ def initialize(self, *args, **kwargs):
598612
'extra_footer_scripts': self.extra_footer_scripts,
599613
'jinja2_env': jinja_env,
600614
'build_memory_limit': self.build_memory_limit,
615+
'build_memory_request': self.build_memory_request,
601616
'build_docker_host': self.build_docker_host,
602617
'base_url': self.base_url,
603618
'badge_base_url': self.badge_base_url,

binderhub/build.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,28 @@ class Build:
3636
API instead of having to invent our own locking code.
3737
3838
"""
39-
def __init__(self, q, api, name, namespace, repo_url, ref, git_credentials, build_image,
40-
image_name, push_secret, memory_limit, docker_host, node_selector,
41-
appendix='', log_tail_lines=100, sticky_builds=False):
39+
40+
def __init__(
41+
self,
42+
q,
43+
api,
44+
name,
45+
*,
46+
namespace,
47+
repo_url,
48+
ref,
49+
build_image,
50+
docker_host,
51+
image_name,
52+
git_credentials=None,
53+
push_secret=None,
54+
memory_limit=0,
55+
memory_request=0,
56+
node_selector=None,
57+
appendix="",
58+
log_tail_lines=100,
59+
sticky_builds=False,
60+
):
4261
self.q = q
4362
self.api = api
4463
self.repo_url = repo_url
@@ -50,6 +69,7 @@ def __init__(self, q, api, name, namespace, repo_url, ref, git_credentials, buil
5069
self.build_image = build_image
5170
self.main_loop = IOLoop.current()
5271
self.memory_limit = memory_limit
72+
self.memory_request = memory_request
5373
self.docker_host = docker_host
5474
self.node_selector = node_selector
5575
self.appendix = appendix
@@ -255,7 +275,7 @@ def submit(self):
255275
volume_mounts=volume_mounts,
256276
resources=client.V1ResourceRequirements(
257277
limits={'memory': self.memory_limit},
258-
requests={'memory': self.memory_limit}
278+
requests={'memory': self.memory_request},
259279
),
260280
env=env
261281
)

binderhub/builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ async def get(self, provider_prefix, _unescaped_spec):
357357
push_secret=push_secret,
358358
build_image=self.settings['build_image'],
359359
memory_limit=self.settings['build_memory_limit'],
360+
memory_request=self.settings['build_memory_request'],
360361
docker_host=self.settings['build_docker_host'],
361362
node_selector=self.settings['build_node_selector'],
362363
appendix=appendix,

0 commit comments

Comments
 (0)