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
45+ from .build import BuildExecutor , KubernetesBuildExecutor , KubernetesCleaner
4546from .builder import BuildHandler
4647from .config import ConfigHandler
4748from .events import EventLog
@@ -228,6 +229,8 @@ def _valid_badge_base_url(self, proposal):
228229
229230 appendix = Unicode (
230231 help = """
232+ DEPRECATED: Use c.BuildExecutor.appendix
233+
231234 Appendix to pass to repo2docker
232235
233236 A multi-line string of Docker directives to run.
@@ -247,6 +250,8 @@ def _valid_badge_base_url(self, proposal):
247250 sticky_builds = Bool (
248251 False ,
249252 help = """
253+ DEPRECATED: Use c.KubernetesBuildExecutor.sticky_builds
254+
250255 Attempt to assign builds for the same repository to the same node.
251256
252257 In order to speed up re-builds of a repository all its builds will
@@ -269,7 +274,7 @@ def _valid_badge_base_url(self, proposal):
269274 )
270275
271276 build_class = Type (
272- Build ,
277+ KubernetesBuildExecutor ,
273278 klass = BuildExecutor ,
274279 help = """
275280 The class used to build repo2docker images.
@@ -279,6 +284,15 @@ def _valid_badge_base_url(self, proposal):
279284 config = True ,
280285 )
281286
287+ build_cleaner_class = Type (
288+ KubernetesCleaner ,
289+ allow_none = True ,
290+ help = """
291+ The class used to cleanup builders.
292+ """ ,
293+ config = True ,
294+ )
295+
282296 registry_class = Type (
283297 DockerRegistry ,
284298 help = """
@@ -336,6 +350,8 @@ def _valid_badge_base_url(self, proposal):
336350 log_tail_lines = Integer (
337351 100 ,
338352 help = """
353+ DEPRECATED: Use c.KubernetesBuildExecutor.log_tail_lines
354+
339355 Limit number of log lines to show when connecting to an already running build.
340356 """ ,
341357 config = True ,
@@ -345,6 +361,8 @@ def _valid_badge_base_url(self, proposal):
345361 "binder-build-docker-config" ,
346362 allow_none = True ,
347363 help = """
364+ DEPRECATED: Use c.BuildExecutor.push_secret
365+
348366 A kubernetes secret object that provides credentials for pushing built images.
349367 """ ,
350368 config = True ,
@@ -368,6 +386,8 @@ def _valid_badge_base_url(self, proposal):
368386 build_memory_request = ByteSpecification (
369387 0 ,
370388 help = """
389+ DEPRECATED: Use c.KubernetesBuildExecutor.memory_request
390+
371391 Amount of memory to request when scheduling a build
372392
373393 0 reserves no memory.
@@ -383,6 +403,8 @@ def _valid_badge_base_url(self, proposal):
383403 build_memory_limit = ByteSpecification (
384404 0 ,
385405 help = """
406+ DEPRECATED: Use c.BuildExecutor.memory_limit
407+
386408 Max amount of memory allocated for each image build process.
387409
388410 0 sets no limit.
@@ -407,6 +429,8 @@ def _valid_badge_base_url(self, proposal):
407429 "/var/run/docker.sock" ,
408430 config = True ,
409431 help = """
432+ DEPRECATED: Use c.KubernetesBuildExecutor.docker_host
433+
410434 The docker URL repo2docker should use to build the images.
411435
412436 Currently, only paths are supported, and they are expected to be available on
@@ -481,6 +505,8 @@ def _add_slash(self, proposal):
481505
482506 build_namespace = Unicode (
483507 help = """
508+ DEPRECATED: Use c.KubernetesBuildExecutor.namespace
509+
484510 Kubernetes namespace to spawn build pods in.
485511
486512 Note that the push_secret must refer to a secret in this namespace.
@@ -495,6 +521,8 @@ def _default_build_namespace(self):
495521 build_image = Unicode (
496522 "quay.io/jupyterhub/repo2docker:2022.02.0" ,
497523 help = """
524+ DEPRECATED: Use c.KubernetesBuildExecutor.build_image
525+
498526 The repo2docker image to be used for doing builds
499527 """ ,
500528 config = True ,
@@ -504,6 +532,8 @@ def _default_build_namespace(self):
504532 {},
505533 config = True ,
506534 help = """
535+ DEPRECATED: Use c.KubernetesBuildExecutor.node_selector
536+
507537 Select the node where build pod runs on.
508538 """ ,
509539 )
@@ -929,25 +959,21 @@ def stop(self):
929959 self .build_pool .shutdown ()
930960
931961 async def watch_build_pods (self ):
932- """Watch build pods
962+ warnings .warn (
963+ "watch_build_pods() is deprecated, use watch_builders()" , DeprecationWarning
964+ )
965+ await self .watch_builders ()
933966
934- Every build_cleanup_interval:
935- - delete stopped build pods
936- - delete running build pods older than build_max_age
967+ async def watch_builders (self ):
937968 """
938- while True :
969+ Watch builders, run a cleanup function every build_cleanup_interval
970+ """
971+ while self .build_cleaner_class :
972+ cleaner = self .build_cleaner_class ()
939973 try :
940- await asyncio .wrap_future (
941- self .executor .submit (
942- lambda : Build .cleanup_builds (
943- self .kube_client ,
944- self .build_namespace ,
945- self .build_max_age ,
946- )
947- )
948- )
974+ await asyncio .wrap_future (self .executor .submit (cleaner .cleanup ))
949975 except Exception :
950- app_log .exception ("Failed to cleanup build pods " )
976+ app_log .exception ("Failed to cleanup builders " )
951977 await asyncio .sleep (self .build_cleanup_interval )
952978
953979 def start (self , run_loop = True ):
@@ -958,7 +984,7 @@ def start(self, run_loop=True):
958984 )
959985 self .http_server .listen (self .port )
960986 if self .builder_required :
961- asyncio .ensure_future (self .watch_build_pods ())
987+ asyncio .ensure_future (self .watch_builders ())
962988 if run_loop :
963989 tornado .ioloop .IOLoop .current ().start ()
964990
0 commit comments