pipeline icon indicating copy to clipboard operation
pipeline copied to clipboard

Improve controller log message when non-existent variable

Open cmoulliard opened this issue 1 year ago • 5 comments

Todo

Improve the controller log message when non-existent variable is discovered:

Tekton Controller has reported this error: admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: non-existent variable in "#!/usr/bin/env bash\nset -eu\nset -o ...
...

See : Gist link

Such an issue can occur if a results param is missing (e.g. results.IMAGE_REF.path) from the Task Spec definition

IMAGE_REF: $(cat /var/workdir/IMAGE_REF)\"\ncat /var/workdir/IMAGE_REF > \"$(results.IMAGE_REF.path)\"\n\n
"": spec.pipelineSpec.tasks[3].taskSpec.steps[0].script

To reproduce the issue, deploy the following PipelineRun

apiVersion: "tekton.dev/v1"
kind: "PipelineRun"
metadata:
  annotations:
    tekton.dev/pipelines.minVersion: "0.60.x"
    tekton.dev/displayName: "Simple example of a Tekton pipeline echoing a message\
      \ and pushing a result"
    tekton.dev/platforms: "linux/amd64"
  labels:
    app.kubernetes.io/version: "0.1"
  name: "simple-job-results-file-script"
spec:
  pipelineSpec:
    tasks:
    - name: "say-hello"
      taskSpec:
        #results:
        #- description: "A Foo user"
        #  name: "FOO"
        steps:
        - image: "registry.access.redhat.com/ubi9@sha256:1ee4d8c50d14d9c9e9229d9a039d793fcbc9aa803806d194c957a397cf1d2b17"
          name: "run-script"
          script: |-
            #!/usr/bin/env bash

            set -e
            echo "-------------------------------------"
            echo "Say Hello" | tee "$(results.FOO.path)"
            echo "-------------------------------------"

then the controller will report

Error from server (BadRequest): error when creating "out/flows/tekton/example/pipelinerun-simple-job-results-file-script.yaml": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: non-existent variable in "#!/usr/bin/env bash\n\nset -e\necho \"-------------------------------------\"\necho \"Say Hello\" | tee \"$(results.FOO.path)\"\necho \"-------------------------------------\"": spec.pipelineSpec.tasks[0].taskSpec.steps[0].script

Remark: The bash script of my example is pretty basic but when it is bigger than a few lines, it is almost impossible for a user to figure out what the issue is

cmoulliard avatar Sep 16 '24 14:09 cmoulliard

@cmoulliard could you please provider more information about user case? I guess this is an improvement to the admission webhook?

chengjoey avatar Sep 23 '24 08:09 chengjoey

I guess this is an improvement to the admission webhook?

Yes as mentioned at the beginning of the Error => Tekton Controller has reported this error: admission webhook "validation.webhook.pipeline.tekton.dev" ...

cmoulliard avatar Sep 23 '24 11:09 cmoulliard

could you please provider more information about user case?

The use case is pretty simple. If a taskSpec part of a pipelineRun which executes a bash script is missing a result declaration, then the error I reported will take place.

See the test case I created within the issue's description @chengjoey

cmoulliard avatar Sep 23 '24 11:09 cmoulliard

/assign

i got what you mean, currently admission-webhook works fine because results.FOO is not defined, but the script is so long that it is hard to get what variable is missing.

chengjoey avatar Sep 30 '24 09:09 chengjoey

Would like to add that this is also relevant for regular parameters of a Task. The log does not state which parameter is missing, just that one is missing. In a script that has over a hundred lines that becomes a problem.

RobertDiebels avatar Oct 20 '24 15:10 RobertDiebels