88import os
99import re
1010import secrets
11+ import warnings
1112from binascii import a2b_hex
1213from concurrent .futures import ThreadPoolExecutor
1314from glob import glob
4142from traitlets .config import Application
4243
4344from .base import AboutHandler , Custom404 , VersionHandler
44- from .build import Build , BuildExecutor , KubernetesBuildExecutor
45+ from .build import BuildExecutor , KubernetesBuildExecutor , KubernetesCleaner
4546from .builder import BuildHandler
4647from .config import ConfigHandler
4748from .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 = """
@@ -369,6 +383,8 @@ def _pod_quota_deprecated(self, change):
369383 log_tail_lines = Integer (
370384 100 ,
371385 help = """
386+ DEPRECATED: Use c.KubernetesBuildExecutor.log_tail_lines
387+
372388 Limit number of log lines to show when connecting to an already running build.
373389 """ ,
374390 config = True ,
@@ -378,6 +394,8 @@ def _pod_quota_deprecated(self, change):
378394 "binder-build-docker-config" ,
379395 allow_none = True ,
380396 help = """
397+ DEPRECATED: Use c.BuildExecutor.push_secret
398+
381399 A kubernetes secret object that provides credentials for pushing built images.
382400 """ ,
383401 config = True ,
@@ -401,6 +419,8 @@ def _pod_quota_deprecated(self, change):
401419 build_memory_request = ByteSpecification (
402420 0 ,
403421 help = """
422+ DEPRECATED: Use c.KubernetesBuildExecutor.memory_request
423+
404424 Amount of memory to request when scheduling a build
405425
406426 0 reserves no memory.
@@ -416,6 +436,8 @@ def _pod_quota_deprecated(self, change):
416436 build_memory_limit = ByteSpecification (
417437 0 ,
418438 help = """
439+ DEPRECATED: Use c.BuildExecutor.memory_limit
440+
419441 Max amount of memory allocated for each image build process.
420442
421443 0 sets no limit.
@@ -440,6 +462,8 @@ def _pod_quota_deprecated(self, change):
440462 "/var/run/docker.sock" ,
441463 config = True ,
442464 help = """
465+ DEPRECATED: Use c.KubernetesBuildExecutor.docker_host
466+
443467 The docker URL repo2docker should use to build the images.
444468
445469 Currently, only paths are supported, and they are expected to be available on
@@ -518,6 +542,8 @@ def _add_slash(self, proposal):
518542
519543 build_namespace = Unicode (
520544 help = """
545+ DEPRECATED: Use c.KubernetesBuildExecutor.namespace
546+
521547 Kubernetes namespace to spawn build pods in.
522548
523549 Note that the push_secret must refer to a secret in this namespace.
@@ -532,6 +558,8 @@ def _default_build_namespace(self):
532558 build_image = Unicode (
533559 "quay.io/jupyterhub/repo2docker:2022.10.0" ,
534560 help = """
561+ DEPRECATED: Use c.KubernetesBuildExecutor.build_image
562+
535563 The repo2docker image to be used for doing builds
536564 """ ,
537565 config = True ,
@@ -541,6 +569,8 @@ def _default_build_namespace(self):
541569 {},
542570 config = True ,
543571 help = """
572+ DEPRECATED: Use c.KubernetesBuildExecutor.node_selector
573+
544574 Select the node where build pod runs on.
545575 """ ,
546576 )
@@ -969,25 +999,21 @@ def stop(self):
969999 self .build_pool .shutdown ()
9701000
9711001 async def watch_build_pods (self ):
972- """Watch build pods
1002+ warnings .warn (
1003+ "watch_build_pods() is deprecated, use watch_builders()" , DeprecationWarning
1004+ )
1005+ await self .watch_builders ()
9731006
974- Every build_cleanup_interval:
975- - delete stopped build pods
976- - delete running build pods older than build_max_age
1007+ async def watch_builders (self ):
9771008 """
978- while True :
1009+ Watch builders, run a cleanup function every build_cleanup_interval
1010+ """
1011+ while self .build_cleaner_class :
1012+ cleaner = self .build_cleaner_class ()
9791013 try :
980- await asyncio .wrap_future (
981- self .executor .submit (
982- lambda : Build .cleanup_builds (
983- self .kube_client ,
984- self .build_namespace ,
985- self .build_max_age ,
986- )
987- )
988- )
1014+ await asyncio .wrap_future (self .executor .submit (cleaner .cleanup ))
9891015 except Exception :
990- app_log .exception ("Failed to cleanup build pods " )
1016+ app_log .exception ("Failed to cleanup builders " )
9911017 await asyncio .sleep (self .build_cleanup_interval )
9921018
9931019 def start (self , run_loop = True ):
@@ -998,7 +1024,7 @@ def start(self, run_loop=True):
9981024 )
9991025 self .http_server .listen (self .port )
10001026 if self .builder_required :
1001- asyncio .ensure_future (self .watch_build_pods ())
1027+ asyncio .ensure_future (self .watch_builders ())
10021028 if run_loop :
10031029 tornado .ioloop .IOLoop .current ().start ()
10041030
0 commit comments