Skip to content

Commit

Permalink
[konflux] set a finalizer so that PLR perists
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwindasr committed Oct 10, 2024
1 parent c3eba53 commit 9166d05
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions doozer/doozerlib/backend/konflux_image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class KonfluxImageBuilder:
"aarch64": "linux/arm64",
}

ART_FINALIZER = "openshift.io/art-db"

def __init__(self, config: KonfluxImageBuilderConfig, logger: Optional[logging.Logger] = None) -> None:
self._config = config
self._logger = logger or LOGGER
Expand Down Expand Up @@ -126,6 +128,14 @@ async def build(self, metadata: ImageMetadata):
else:
metadata.build_status = True
break

# Remove finalizer that we added to the PipelineRun, since we managed to store the status to DB
finalizers = pipelinerun['metadata'].get('finalizers', [])
if KonfluxImageBuilder.ART_FINALIZER in finalizers:
finalizers.remove('openshift.io/art-db')
pipelinerun['metadata']['finalizers'] = finalizers
pipelinerun = await self._create_or_patch(dyn_client, pipelinerun, patch_only=True)
self._logger.info(f"openshift.io/art-db Finalizer removed from PipelineRun {pipelinerun_name}")
if not metadata.build_status and error:
raise error
finally:
Expand Down Expand Up @@ -434,6 +444,7 @@ def _new_pipelinerun(generate_name: str, application_name: str, component_name:
obj["metadata"]["annotations"]["build.appstudio.openshift.io/repo"] = f"{https_url}?rev={commit_sha}"
obj["metadata"]["labels"]["appstudio.openshift.io/application"] = application_name
obj["metadata"]["labels"]["appstudio.openshift.io/component"] = component_name
obj["metadata"]["finalizers"] = [KonfluxImageBuilder.ART_FINALIZER]

skip_checks_flag = False
for param in obj["spec"]["params"]:
Expand All @@ -456,7 +467,7 @@ def _new_pipelinerun(generate_name: str, application_name: str, component_name:
obj["spec"]["params"].append({"name": "build-platforms", "value": list(build_platforms)})
return obj

async def _create_or_patch(self, dyn_client: DynamicClient, manifest: dict):
async def _create_or_patch(self, dyn_client: DynamicClient, manifest: dict, patch_only: bool = False):
name = manifest["metadata"]["name"]
namespace = manifest["metadata"].get("namespace", self._config.namespace)
api_version = manifest["apiVersion"]
Expand All @@ -477,7 +488,7 @@ async def _create_or_patch(self, dyn_client: DynamicClient, manifest: dict):
else:
self._logger.warning(f"[DRY RUN] Would have created {api_version}/{kind} {namespace}/{name}")
return resource.ResourceInstance(dyn_client, manifest)
if found:
if found or patch_only:
self._logger.info(f"Patching {api_version}/{kind} {namespace}/{name}")
new = await exectools.to_thread(
api.patch,
Expand Down

0 comments on commit 9166d05

Please sign in to comment.