Skip to content

Commit

Permalink
Remove pipeline after build finishes
Browse files Browse the repository at this point in the history
CLOUDBLD-10155

To prevent finished pipelines (successfully or not) from taking up
resources, delete them as soon as possible.

Signed-off-by: Adam Cmiel <acmiel@redhat.com>
  • Loading branch information
chmeliik committed Jun 9, 2022
1 parent 7df3f84 commit 2039de1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions koji_containerbuild/plugins/builder_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ def upload_build_results_as_annotations(self, build_results):
logger=self.logger)

def handle_build_response(self, build_id, platforms: list = None):
try:
return self._handle_build_response(build_id, platforms)
finally:
self.osbs().remove_build(build_id)

def _handle_build_response(self, build_id, platforms: list = None):
self.logger.debug("OSBS build id: %r", build_id)

# When builds are cancelled the builder plugin process gets SIGINT and SIGKILL
Expand Down
7 changes: 7 additions & 0 deletions tests/test_builder_containerbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ def _mock_osbs(self, koji_build_id, src, koji_task_id, source=False,
create_build_args.setdefault('target', 'target-name')
create_build_args.setdefault('scratch', False)

# validation exception => the build did not start
build_not_started = build_not_started or with_osbsvalidationexception

if not source:
create_build_args.setdefault('component', 'fedora-docker')
create_build_args.setdefault('git_uri', src['git_uri'])
Expand Down Expand Up @@ -385,6 +388,10 @@ def _mock_osbs(self, koji_build_id, src, koji_task_id, source=False,
.should_receive('get_build_error_message')
.and_return("build error"))
(flexmock(osbs.api.OSBS).should_receive('wait_for_build_to_finish').and_return(None))
(flexmock(osbs.api.OSBS)
.should_receive('remove_build')
.times(0 if build_not_started else 1)
.and_return({'kind': 'Status', 'apiVersion': 'v1', 'status': 'Success'}))

def _mock_folders(self, tmpdir, dockerfile_content=None, additional_tags_content=None):
if dockerfile_content is None:
Expand Down

0 comments on commit 2039de1

Please sign in to comment.