Skip to content

Commit fff83b2

Browse files
committed
Default to traitlets based KubernetesBuildExecutor
1 parent 2ba938b commit fff83b2

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

binderhub/app.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import re
1010
import secrets
11+
import warnings
1112
from binascii import a2b_hex
1213
from concurrent.futures import ThreadPoolExecutor
1314
from glob import glob
@@ -41,7 +42,7 @@
4142
from traitlets.config import Application
4243

4344
from .base import AboutHandler, Custom404, VersionHandler
44-
from .build import Build, BuildExecutor
45+
from .build import BuildExecutor, KubernetesBuildExecutor, KubernetesCleaner
4546
from .builder import BuildHandler
4647
from .config import ConfigHandler
4748
from .events import EventLog
@@ -229,6 +230,8 @@ def _valid_badge_base_url(self, proposal):
229230

230231
appendix = Unicode(
231232
help="""
233+
DEPRECATED: Use c.BuildExecutor.appendix
234+
232235
Appendix to pass to repo2docker
233236
234237
A multi-line string of Docker directives to run.
@@ -248,6 +251,8 @@ def _valid_badge_base_url(self, proposal):
248251
sticky_builds = Bool(
249252
False,
250253
help="""
254+
DEPRECATED: Use c.KubernetesBuildExecutor.sticky_builds
255+
251256
Attempt to assign builds for the same repository to the same node.
252257
253258
In order to speed up re-builds of a repository all its builds will
@@ -270,7 +275,7 @@ def _valid_badge_base_url(self, proposal):
270275
)
271276

272277
build_class = Type(
273-
Build,
278+
KubernetesBuildExecutor,
274279
klass=BuildExecutor,
275280
help="""
276281
The class used to build repo2docker images.
@@ -280,6 +285,15 @@ def _valid_badge_base_url(self, proposal):
280285
config=True,
281286
)
282287

288+
build_cleaner_class = Type(
289+
KubernetesCleaner,
290+
allow_none=True,
291+
help="""
292+
The class used to cleanup builders.
293+
""",
294+
config=True,
295+
)
296+
283297
registry_class = Type(
284298
DockerRegistry,
285299
help="""
@@ -357,6 +371,8 @@ def _pod_quota_deprecated(self, change):
357371
log_tail_lines = Integer(
358372
100,
359373
help="""
374+
DEPRECATED: Use c.KubernetesBuildExecutor.log_tail_lines
375+
360376
Limit number of log lines to show when connecting to an already running build.
361377
""",
362378
config=True,
@@ -366,6 +382,8 @@ def _pod_quota_deprecated(self, change):
366382
"binder-build-docker-config",
367383
allow_none=True,
368384
help="""
385+
DEPRECATED: Use c.BuildExecutor.push_secret
386+
369387
A kubernetes secret object that provides credentials for pushing built images.
370388
""",
371389
config=True,
@@ -389,6 +407,8 @@ def _pod_quota_deprecated(self, change):
389407
build_memory_request = ByteSpecification(
390408
0,
391409
help="""
410+
DEPRECATED: Use c.KubernetesBuildExecutor.memory_request
411+
392412
Amount of memory to request when scheduling a build
393413
394414
0 reserves no memory.
@@ -404,6 +424,8 @@ def _pod_quota_deprecated(self, change):
404424
build_memory_limit = ByteSpecification(
405425
0,
406426
help="""
427+
DEPRECATED: Use c.BuildExecutor.memory_limit
428+
407429
Max amount of memory allocated for each image build process.
408430
409431
0 sets no limit.
@@ -428,6 +450,8 @@ def _pod_quota_deprecated(self, change):
428450
"/var/run/docker.sock",
429451
config=True,
430452
help="""
453+
DEPRECATED: Use c.KubernetesBuildExecutor.docker_host
454+
431455
The docker URL repo2docker should use to build the images.
432456
433457
Currently, only paths are supported, and they are expected to be available on
@@ -502,6 +526,8 @@ def _add_slash(self, proposal):
502526

503527
build_namespace = Unicode(
504528
help="""
529+
DEPRECATED: Use c.KubernetesBuildExecutor.namespace
530+
505531
Kubernetes namespace to spawn build pods in.
506532
507533
Note that the push_secret must refer to a secret in this namespace.
@@ -516,6 +542,8 @@ def _default_build_namespace(self):
516542
build_image = Unicode(
517543
"quay.io/jupyterhub/repo2docker:2022.10.0",
518544
help="""
545+
DEPRECATED: Use c.KubernetesBuildExecutor.build_image
546+
519547
The repo2docker image to be used for doing builds
520548
""",
521549
config=True,
@@ -525,6 +553,8 @@ def _default_build_namespace(self):
525553
{},
526554
config=True,
527555
help="""
556+
DEPRECATED: Use c.KubernetesBuildExecutor.node_selector
557+
528558
Select the node where build pod runs on.
529559
""",
530560
)
@@ -953,25 +983,21 @@ def stop(self):
953983
self.build_pool.shutdown()
954984

955985
async def watch_build_pods(self):
956-
"""Watch build pods
986+
warnings.warn(
987+
"watch_build_pods() is deprecated, use watch_builders()", DeprecationWarning
988+
)
989+
await self.watch_builders()
957990

958-
Every build_cleanup_interval:
959-
- delete stopped build pods
960-
- delete running build pods older than build_max_age
991+
async def watch_builders(self):
961992
"""
962-
while True:
993+
Watch builders, run a cleanup function every build_cleanup_interval
994+
"""
995+
while self.build_cleaner_class:
996+
cleaner = self.build_cleaner_class()
963997
try:
964-
await asyncio.wrap_future(
965-
self.executor.submit(
966-
lambda: Build.cleanup_builds(
967-
self.kube_client,
968-
self.build_namespace,
969-
self.build_max_age,
970-
)
971-
)
972-
)
998+
await asyncio.wrap_future(self.executor.submit(cleaner.cleanup))
973999
except Exception:
974-
app_log.exception("Failed to cleanup build pods")
1000+
app_log.exception("Failed to cleanup builders")
9751001
await asyncio.sleep(self.build_cleanup_interval)
9761002

9771003
def start(self, run_loop=True):
@@ -982,7 +1008,7 @@ def start(self, run_loop=True):
9821008
)
9831009
self.http_server.listen(self.port)
9841010
if self.builder_required:
985-
asyncio.ensure_future(self.watch_build_pods())
1011+
asyncio.ensure_future(self.watch_builders())
9861012
if run_loop:
9871013
tornado.ioloop.IOLoop.current().start()
9881014

helm-chart/binderhub/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ service:
4141

4242
config:
4343
BinderHub: {}
44+
KubernetesBuildExecutor: {}
4445

4546
extraConfig: {}
4647

0 commit comments

Comments
 (0)