Merge pull request #128 from sbidoul/make-cleanup-optional

Make cleanup job optional via a global setting
This commit is contained in:
Stéphane Bidoul 2025-09-14 11:17:55 +02:00 committed by GitHub
commit 7e160510a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View file

@ -259,8 +259,16 @@ class Build(BaseModel):
job_kind=k8s.DeploymentMode.initialize, job_kind=k8s.DeploymentMode.initialize,
) )
async def _delete_deployment_resources(self) -> None:
await k8s.delete_deployment_resources(self.name)
_logger.debug("Removing finalizer for %s.", self)
await self._patch(remove_finalizers=True, not_found_ok=True)
async def cleanup(self) -> None: async def cleanup(self) -> None:
"""Launch the cleanup job.""" """Launch the cleanup job."""
if settings.no_cleanup_job:
await self._delete_deployment_resources()
return
# Kill the initialization job to reduce conflict with the cleanup job, such as # Kill the initialization job to reduce conflict with the cleanup job, such as
# the database being created by the initialization after the cleanup job has # the database being created by the initialization after the cleanup job has
# completed. # completed.
@ -319,9 +327,7 @@ class Build(BaseModel):
async def on_cleanup_succeeded(self) -> None: async def on_cleanup_succeeded(self) -> None:
_logger.info(f"Cleanup job succeeded for {self}, deleting resources.") _logger.info(f"Cleanup job succeeded for {self}, deleting resources.")
await k8s.delete_deployment_resources(self.name) await self._delete_deployment_resources()
_logger.debug("Removing finalizer for %s.", self)
await self._patch(remove_finalizers=True, not_found_ok=True)
async def on_cleanup_failed(self) -> None: async def on_cleanup_failed(self) -> None:
_logger.error(f"Cleanup job failed for {self}, manual intervention required.") _logger.error(f"Cleanup job failed for {self}, manual intervention required.")

View file

@ -89,6 +89,9 @@ class Settings(BaseSettings):
deployment_resource_types: str = ( deployment_resource_types: str = (
"deployment,service,ingress,configmap,secret,pvc,job" "deployment,service,ingress,configmap,secret,pvc,job"
) )
# Set to true if there is no cleanup job, and merely deleting the resources
# is enough.
no_cleanup_job: bool = False
def get_build_settings(self, repo: str, target_branch: str) -> list[BuildSettings]: def get_build_settings(self, repo: str, target_branch: str) -> list[BuildSettings]:
for repo_settings in self.repos: for repo_settings in self.repos: