Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocp4-scan: ignore locks on dry-run mode #1124

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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