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

Fix enum validation with multiple param references #7481

Merged

Conversation

QuanZhang-William
Copy link
Member

Changes

Fixes #7476. TEP-0144 requires that the pipeline-level enum must be a subset of referenced task-level enum.

Prior to this commit, the enum subset validation logic assumes that a task-level param only referenced only one pipeline-level enum, and does not support scenario where multiple pipeline-level enums are referenced (e.g., "$(params.p1) and $(params.p2)").

This commit adds the handling logic for such compound references, skipping the subset validation in this scenario as there is no directly associated params at pipeline level.

/kind bug

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

bug fix: allow task-level param references multiple pipeline-level params with enum

Fixes [tektoncd#7476][7476]. TEP-0144 requires that the pipeline-level `enum` must be a subset of referenced task-level `enum`.

Prior to this commit, the enum subset validation logic assumes that a task-level param only referenced only one pipeline-level `enum`,
and does not support scenario where multiple pipeline-level `enums` are referenced (e.g., "$(params.p1) and $(params.p2)").

This commit adds the handling logic for such compound references, skipping the subset validation in this scenario as there is no directly associated
params at pipeline level.

/kind bug

[7476]: tektoncd#7476
@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 11, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 96.4% 96.7% 0.3

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 96.4% 96.7% 0.3

@QuanZhang-William
Copy link
Member Author

/retest

Comment on lines +351 to +363
params:
- name: message1
enum: ["v1"]
- name: message2
enum: ["v2"]
tasks:
- name: task1
params:
- name: message
value: "$(params.message1) and $(params.message2)"
taskSpec:
params: message
enum: [...] # the message enum is not required to be a subset of message1 or message2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, if for the task, we have an enum that requires a url to beabc/foo, and the pipeline passes a $(params.url-part1)/$(params.url-part2) param to the task's param.
The PR will skip the validation right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. There are 2 kinds of check we do

  • Validate user input against enums. At pipeline level, we will validate message1 and message2 individually; at task-level, we validate the value of message is in it own enum (the compound value). This PR does not change this behavior.
  • Subset validation: prior to the change, we require that the pipeline-level param enum must be a subset of the task-level enum referencing it. If a task-level param referenes a single pipeline-level param, it is easy and we still validate it. However, if it references multiple pipeline-level params, like this one, we will skip the subset validation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is the subset validaition, I thought it is the first one

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 11, 2023
@dohoangkhiem
Copy link

Thanks for speedy solution, can we merge this fix @QuanZhang-William :) , as I needed to workaround (like using script instead of value to circumvent this issue)

@QuanZhang-William
Copy link
Member Author

QuanZhang-William commented Dec 13, 2023

Thanks for speedy solution, can we merge this fix @QuanZhang-William :) , as I needed to workaround (like using script instead of value to circumvent this issue)

Hi @dohoangkhiem 👋 . I have pinged some reviewers to review and merge this PR. As a workaround, would disabling the param enum feature by setting enable-param-enum:false help? I think it will unblock your pipeline (even though without the enum feature...)

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JeromeJu, Yongxuanzhang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JeromeJu,Yongxuanzhang]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 14, 2023
@tekton-robot tekton-robot merged commit 8e9fd46 into tektoncd:main Dec 14, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum validation failed when Task Param referenced multiple Pipeline Params
6 participants