Skip to content

Commit

Permalink
Merge pull request #1124 from locriandev/ocp4-scan-konflux
Browse files Browse the repository at this point in the history
ocp4-scan: ignore locks on dry-run mode
  • Loading branch information
openshift-merge-bot[bot] authored Nov 15, 2024
2 parents 23c99bf + f0dad1c commit ca4ed4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
33 changes: 15 additions & 18 deletions pyartcd/pyartcd/pipelines/ocp4_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def __init__(self, runtime: Runtime, version: str, data_path: Optional[str] = No
self.changes = {}
self.issues = []
self._doozer_working = self.runtime.working_dir / "doozer_working"
self.locked = True # True by default; if not locked, run() will set it to False
self.skipped = True # True by default; if not locked, run() will set it to False

async def run(self):
# If we get here, lock could be acquired
self.locked = False
self.skipped = False
self.logger.info('Building: %s', self.version)

# KUBECONFIG env var must be defined in order to scan sources
Expand Down Expand Up @@ -171,27 +171,26 @@ async def _rhcos_inconsistent(self):

@cli.command('ocp4-scan')
@click.option('--version', required=True, help='OCP version to scan')
@click.option('--ignore-locks', is_flag=True, default=False,
help='Do not wait for other builds in this version to complete (only allowed in dry-run mode)')
@pass_runtime
@click_coroutine
async def ocp4_scan(runtime: Runtime, version: str, ignore_locks: bool):
lock = Lock.SCAN
lock_name = lock.value.format(version=version)
lock_identifier = jenkins.get_build_path()
if not lock_identifier:
runtime.logger.warning('Env var BUILD_URL has not been defined: a random identifier will be used for the locks')

async def ocp4_scan(runtime: Runtime, version: str):
pipeline = Ocp4ScanPipeline(runtime, version)
jenkins.init_jenkins()

if ignore_locks:
# Already checked by aos-cd-jobs, but you never know...
if not runtime.dry_run:
raise RuntimeError('--ignore-locks can only by used with --dry-run')
if runtime.dry_run:
await pipeline.run()

else:
lock = Lock.SCAN
lock_name = lock.value.format(version=version)
lock_identifier = jenkins.get_build_path()
if not lock_identifier:
runtime.logger.warning('Env var BUILD_URL has not been defined: a random identifier will be used for the locks')

# Scheduled builds are already being skipped if the lock is already acquired.
# For manual builds, we need to check if the build and scan locks are already acquired,
# and skip the current build if that's the case.
# Should that happen, signal it by appending a [SKIPPED][LOCKED] to the build title
async def run_with_build_lock():
build_lock = Lock.BUILD
build_lock_name = build_lock.value.format(version=version)
Expand All @@ -211,7 +210,5 @@ async def run_with_build_lock():
skip_if_locked=True
)

# This should not happen, as the schedule build already checked for existing locks
# It doesn't hurt to check once more though
if pipeline.locked:
if pipeline.skipped:
jenkins.update_title(' [SKIPPED][LOCKED]')
21 changes: 8 additions & 13 deletions pyartcd/pyartcd/pipelines/ocp4_scan_konflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,11 @@ async def get_changes(self):
help='Doozer data path git [branch / tag / sha] to use')
@click.option('--image-list', required=False,
help='Comma/space-separated list to of images to scan, empty to scan all')
@click.option('--ignore-locks', is_flag=True, default=False,
help='Do not wait for other builds in this version to complete (only allowed in dry-run mode)')
@pass_runtime
@click_coroutine
async def ocp4_scan(runtime: Runtime, version: str, assembly: str, data_path: str, data_gitref,
image_list: str, ignore_locks: bool):
async def ocp4_scan(runtime: Runtime, version: str, assembly: str, data_path: str, data_gitref, image_list: str):
jenkins.init_jenkins()

lock = Lock.SCAN_KONFLUX
lock_name = lock.value.format(version=version)
lock_identifier = jenkins.get_build_path()
if not lock_identifier:
runtime.logger.warning('Env var BUILD_URL has not been defined: a random identifier will be used for the locks')

pipeline = Ocp4ScanPipeline(
runtime=runtime,
version=version,
Expand All @@ -147,12 +138,16 @@ async def ocp4_scan(runtime: Runtime, version: str, assembly: str, data_path: st
image_list=image_list,
)

if ignore_locks:
if not runtime.dry_run:
raise RuntimeError('--ignore-locks can only by used with --dry-run')
if runtime.dry_run:
await pipeline.run()

else:
lock = Lock.SCAN_KONFLUX
lock_name = lock.value.format(version=version)
lock_identifier = jenkins.get_build_path()
if not lock_identifier:
runtime.logger.warning('Env var BUILD_URL has not been defined: a random identifier will be used for the locks')

# Scheduled builds are already being skipped if the lock is already acquired.
# For manual builds, we need to check if the build and scan locks are already acquired,
# and skip the current build if that's the case.
Expand Down

0 comments on commit ca4ed4c

Please sign in to comment.