Skip to content

Commit 92cb243

Browse files
authored
fix: properly consider running buildrun condition (#1006)
1 parent bcefdc6 commit 92cb243

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

components/renku_data_services/k8s/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,14 @@ class APIObjectInCluster:
243243
@property
244244
def user_id(self) -> str | None:
245245
"""Extract the user id from annotations."""
246+
labels = cast(dict[str, str], self.obj.metadata.get("labels", {}))
246247
match self.obj.singular:
247248
case "jupyterserver":
248-
return cast(str, self.obj.metadata.labels["renku.io/userId"])
249+
return labels.get("renku.io/userId", None)
249250
case "amaltheasession":
250-
return cast(str, self.obj.metadata.labels["renku.io/safe-username"])
251+
return labels.get("renku.io/safe-username", None)
251252
case "buildrun":
252-
return cast(str, self.obj.metadata.labels["renku.io/safe-username"])
253+
return labels.get("renku.io/safe-username", None)
253254

254255
case "taskrun":
255256
return DUMMY_TASK_RUN_USER_ID

components/renku_data_services/session/k8s_client.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,25 @@ async def update_image_build_status(self, buildrun_name: str, user_id: str) -> m
223223
return models.ShipwrightBuildStatusUpdate(update=None)
224224

225225
conditions = k8s_build_status.conditions
226+
# NOTE: You can get a condition like this in some cases during autoscaling or for other reasons
227+
# message: Not all Steps in the Task have finished executing
228+
# reason: Running
229+
# status: Unknown
230+
# /type: Succeeded
231+
# In this case we want to keep waiting - the buildrun is still running.
232+
# A fully successful completion condition looks like this:
233+
# reason: Succeeded
234+
# status: True
235+
# /type: Succeeded
236+
# See https://shipwright.io/docs/build/buildrun/#understanding-the-state-of-a-buildrun
237+
# NOTE: In the examples above I put / before the type field because mypy parses that and fails.
238+
# So I needed something to keep mypy happy. The real name of the field is "type"
226239
condition = next(filter(lambda c: c.type == "Succeeded", conditions or []), None)
227240

241+
if condition is not None and condition.reason in ["Running", "Pending"]:
242+
# The buildrun is still running or pending
243+
return models.ShipwrightBuildStatusUpdate(update=None)
244+
228245
buildSpec = k8s_build_status.buildSpec
229246
output = buildSpec.output if buildSpec else None
230247
result_image = output.image if output else "unknown"
@@ -238,7 +255,7 @@ async def update_image_build_status(self, buildrun_name: str, user_id: str) -> m
238255
result_repository_git_commit_sha = git_obj_2.commitSha if git_obj_2 else None
239256
result_repository_git_commit_sha = result_repository_git_commit_sha or "unknown"
240257

241-
if condition is not None and condition.status == "True":
258+
if condition is not None and condition.reason == "Succeeded" and condition.status == "True":
242259
return models.ShipwrightBuildStatusUpdate(
243260
update=models.ShipwrightBuildStatusUpdateContent(
244261
status=models.BuildStatus.succeeded,

0 commit comments

Comments
 (0)