Page MenuHomePhabricator

[tbs][cli] When a pipelinerun is created, it has no 'status' so we should not break on it
Closed, ResolvedPublic

Description

When creating a new pipelinerun, there's a split second (depending on the controller picking it up) in which the run itself has no status yet:

dcaro@vulcanus$ kubectl get -n image-build pipelinerun -o yaml
apiVersion: v1
items:
- apiVersion: tekton.dev/v1beta1
  kind: PipelineRun
  metadata:
    creationTimestamp: "2022-11-02T09:24:51Z"
    generateName: minikube-user-buildpacks-pipelinerun-
    generation: 1
    labels:
      user: minikube-user
    managedFields:
    - apiVersion: tekton.dev/v1beta1
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:generateName: {}
          f:labels:
            .: {}
            f:user: {}
        f:spec:
          .: {}
          f:params: {}
          f:pipelineRef:
            .: {}
            f:name: {}
          f:serviceAccountName: {}
          f:workspaces: {}
      manager: python-requests
      operation: Update
      time: "2022-11-02T09:24:51Z"
    name: minikube-user-buildpacks-pipelinerun-mkgjp
    namespace: image-build
    resourceVersion: "644"
    uid: aa818cee-c3a8-4a68-b83c-0f4e0ff2520e
  spec:
    params:
    - name: BUILDER_IMAGE
      value: docker-registry.tools.wmflabs.org/toolforge-bullseye0-builder
    - name: APP_IMAGE
      value: harbor.tools.wmflabs.org/minikube-user/dcaro:latest
    - name: SOURCE_URL
      value: https://github.com/david-caro/wm-lol
    - name: USER_ID
      value: "61312"
    - name: GROUP_ID
      value: "61312"
    pipelineRef:
      name: buildpacks
    serviceAccountName: buildpacks-service-account
    workspaces:
    - emptyDir: {}
      name: source-ws
    - emptyDir: {}
      name: cache-ws
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

But we depend on it and crash:

dcaro@vulcanus$ toolforge build-list
run_name        status  start_time      end_time        source_url      repo_url        image_name      image_tag       builder_image
Traceback (most recent call last):
  File "/home/dcaro/.virtualenvs/toolforge-cli-python3/bin/toolforge", line 8, in <module>
    sys.exit(main())
  File "/home/dcaro/Work/wikimedia/toolforge-cli/toolforge_cli/cli.py", line 538, in main
    toolforge()
  File "/home/dcaro/.virtualenvs/toolforge-cli-python3/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/dcaro/.virtualenvs/toolforge-cli-python3/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/dcaro/.virtualenvs/toolforge-cli-python3/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/dcaro/.virtualenvs/toolforge-cli-python3/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dcaro/.virtualenvs/toolforge-cli-python3/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/dcaro/Work/wikimedia/toolforge-cli/toolforge_cli/cli.py", line 347, in build_list
    for run in sorted(runs, key=lambda run: run["status"]["startTime"], reverse=True):
  File "/home/dcaro/Work/wikimedia/toolforge-cli/toolforge_cli/cli.py", line 347, in <lambda>
    for run in sorted(runs, key=lambda run: run["status"]["startTime"], reverse=True):
KeyError: 'status'

This task is to handle these gracefully and add something like "not started" instead.

Event Timeline

Slst2020 renamed this task from [tbs][cli] Wen a pipelinerun is created, it has no 'status' so we should not break on it to [tbs][cli] When a pipelinerun is created, it has no 'status' so we should not break on it.Nov 10 2022, 2:42 PM
Slst2020 claimed this task.
Slst2020 updated the task description. (Show Details)
Slst2020 changed the task status from Open to In Progress.Nov 15 2022, 8:10 AM

Change 858549 had a related patch set uploaded (by Slavina Stefanova; author: Slavina Stefanova):

[cloud/toolforge/toolforge-cli@main] cli: handle build-list output from pipeline runs without status

https://gerrit.wikimedia.org/r/858549

Slst2020 changed the task status from In Progress to Open.Nov 18 2022, 9:28 AM
Slst2020 moved this task from In Progress to Done on the Toolforge Build Service (Iteration 04) board.
Slst2020 moved this task from Done to In Review on the Toolforge Build Service (Iteration 04) board.

Change 858549 merged by jenkins-bot:

[cloud/toolforge/toolforge-cli@main] cli: handle build-list output from pipeline runs without status

https://gerrit.wikimedia.org/r/858549