Skip to content

Commit

Permalink
Merge pull request #1661 from minrk/build_max_age
Browse files Browse the repository at this point in the history
Fix build cleaner configuration
  • Loading branch information
manics committed Apr 20, 2023
2 parents 8738813 + 0a4304c commit 8ebe247
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
23 changes: 22 additions & 1 deletion binderhub/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,25 @@ def _validate_repo_providers(self, proposal):
""",
)

@observe("build_max_age")
def _build_max_age_changed(self, change):
if self.build_cleaner_class:
cleaner_name = self.build_cleaner_class.__name__
else:
cleaner_name = "CleanerName"

if cleaner_name in self.config:
cleaner_config = self.config[cleaner_name]
if "max_age" in cleaner_config:
# avoid warning about redundant deprecated config
# which can be kept for backward-compatibility
return

self.log.warning(
f"BinderHub.build_max_age is deprecated. Use `c.{cleaner_name}.max_age = {change.new}`"
)
self.config[cleaner_name].max_age = change.new

build_token_check_origin = Bool(
True,
config=True,
Expand Down Expand Up @@ -1024,7 +1043,9 @@ async def watch_builders(self):
Watch builders, run a cleanup function every build_cleanup_interval
"""
while self.build_cleaner_class:
cleaner = self.build_cleaner_class()
cleaner = self.build_cleaner_class(
kube=self.kube_client, namespace=self.build_namespace, parent=self
)
try:
await asyncio.wrap_future(self.executor.submit(cleaner.cleanup))
except Exception:
Expand Down
8 changes: 6 additions & 2 deletions binderhub/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,17 @@ def _default_kube(self):
kubernetes.config.load_kube_config()
return client.CoreV1Api()

namespace = Unicode(help="Kubernetes namespace", config=True)
namespace = Unicode(help="Kubernetes namespace")

@default("namespace")
def _default_namespace(self):
return os.getenv("BUILD_NAMESPACE", "default")

max_age = Integer(help="Maximum age of build pods to keep", config=True)
max_age = Integer(
3600 * 4,
help="Maximum age of build pods to keep",
config=True,
)

def cleanup(self):
"""Delete stopped build pods and build pods that have aged out"""
Expand Down

0 comments on commit 8ebe247

Please sign in to comment.