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
@@ -247,6 +248,8 @@ def _valid_badge_base_url(self, proposal):
247248 sticky_builds = Bool (
248249 False ,
249250 help = """
251+ DEPRECATED: Use c.KubernetesBuildExecutor.sticky_builds
252+
250253 Attempt to assign builds for the same repository to the same node.
251254
252255 In order to speed up re-builds of a repository all its builds will
@@ -269,7 +272,7 @@ def _valid_badge_base_url(self, proposal):
269272 )
270273
271274 build_class = Type (
272- Build ,
275+ KubernetesBuildExecutor ,
273276 klass = BuildExecutor ,
274277 help = """
275278 The class used to build repo2docker images.
@@ -279,6 +282,15 @@ def _valid_badge_base_url(self, proposal):
279282 config = True ,
280283 )
281284
285+ build_cleaner_class = Type (
286+ KubernetesCleaner ,
287+ allow_none = True ,
288+ help = """
289+ The class used to cleanup builders.
290+ """ ,
291+ config = True ,
292+ )
293+
282294 registry_class = Type (
283295 DockerRegistry ,
284296 help = """
@@ -336,6 +348,8 @@ def _valid_badge_base_url(self, proposal):
336348 log_tail_lines = Integer (
337349 100 ,
338350 help = """
351+ DEPRECATED: Use c.KubernetesBuildExecutor.log_tail_lines
352+
339353 Limit number of log lines to show when connecting to an already running build.
340354 """ ,
341355 config = True ,
@@ -345,6 +359,8 @@ def _valid_badge_base_url(self, proposal):
345359 "binder-build-docker-config" ,
346360 allow_none = True ,
347361 help = """
362+ DEPRECATED: Use c.BuildExecutor.push_secret
363+
348364 A kubernetes secret object that provides credentials for pushing built images.
349365 """ ,
350366 config = True ,
@@ -368,6 +384,8 @@ def _valid_badge_base_url(self, proposal):
368384 build_memory_request = ByteSpecification (
369385 0 ,
370386 help = """
387+ DEPRECATED: Use c.KubernetesBuildExecutor.memory_request
388+
371389 Amount of memory to request when scheduling a build
372390
373391 0 reserves no memory.
@@ -383,6 +401,8 @@ def _valid_badge_base_url(self, proposal):
383401 build_memory_limit = ByteSpecification (
384402 0 ,
385403 help = """
404+ DEPRECATED: Use c.BuildExecutor.memory_limit
405+
386406 Max amount of memory allocated for each image build process.
387407
388408 0 sets no limit.
@@ -407,6 +427,8 @@ def _valid_badge_base_url(self, proposal):
407427 "/var/run/docker.sock" ,
408428 config = True ,
409429 help = """
430+ DEPRECATED: Use c.KubernetesBuildExecutor.docker_host
431+
410432 The docker URL repo2docker should use to build the images.
411433
412434 Currently, only paths are supported, and they are expected to be available on
@@ -481,6 +503,8 @@ def _add_slash(self, proposal):
481503
482504 build_namespace = Unicode (
483505 help = """
506+ DEPRECATED: Use c.KubernetesBuildExecutor.namespace
507+
484508 Kubernetes namespace to spawn build pods in.
485509
486510 Note that the push_secret must refer to a secret in this namespace.
@@ -495,6 +519,8 @@ def _default_build_namespace(self):
495519 build_image = Unicode (
496520 "quay.io/jupyterhub/repo2docker:2022.02.0" ,
497521 help = """
522+ DEPRECATED: Use c.KubernetesBuildExecutor.build_image
523+
498524 The repo2docker image to be used for doing builds
499525 """ ,
500526 config = True ,
@@ -504,6 +530,8 @@ def _default_build_namespace(self):
504530 {},
505531 config = True ,
506532 help = """
533+ DEPRECATED: Use c.KubernetesBuildExecutor.node_selector
534+
507535 Select the node where build pod runs on.
508536 """ ,
509537 )
@@ -929,25 +957,21 @@ def stop(self):
929957 self .build_pool .shutdown ()
930958
931959 async def watch_build_pods (self ):
932- """Watch build pods
960+ warnings .warn (
961+ "watch_build_pods() is deprecated, use watch_builders()" , DeprecationWarning
962+ )
963+ await self .watch_builders ()
933964
934- Every build_cleanup_interval:
935- - delete stopped build pods
936- - delete running build pods older than build_max_age
965+ async def watch_builders (self ):
937966 """
938- while True :
967+ Watch builders, run a cleanup function every build_cleanup_interval
968+ """
969+ while self .build_cleaner_class :
970+ cleaner = self .build_cleaner_class ()
939971 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- )
972+ await asyncio .wrap_future (self .executor .submit (cleaner .cleanup ))
949973 except Exception :
950- app_log .exception ("Failed to cleanup build pods " )
974+ app_log .exception ("Failed to cleanup builders " )
951975 await asyncio .sleep (self .build_cleanup_interval )
952976
953977 def start (self , run_loop = True ):
@@ -958,7 +982,7 @@ def start(self, run_loop=True):
958982 )
959983 self .http_server .listen (self .port )
960984 if self .builder_required :
961- asyncio .ensure_future (self .watch_build_pods ())
985+ asyncio .ensure_future (self .watch_builders ())
962986 if run_loop :
963987 tornado .ioloop .IOLoop .current ().start ()
964988
0 commit comments