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 Validation Error Merging StepTemplates with StepRef #7982

Conversation

chitrangpatel
Copy link
Contributor

@chitrangpatel chitrangpatel commented May 23, 2024

Prior to this, when validating a Step, we were merging the StepTemplate fields into the Step. For inlined-Steps,
this is fine. However, when referencing a StepAction, we end up merging StepTemplate with a StepRef.
This leads to broken validation. In reality this should be skipped at web-hook validation since the
StepAction has not been fetched yet and so there is not enough information at that time to do this validation correctly.
This is what this PR fixes. See the issue below for more details.

Fixes #7981

Changes

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
  • pre-commit Passed
  • 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

Fix Validation Error Merging StepTemplates with Step's Ref

/kind bug

@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/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 23, 2024
@tekton-robot tekton-robot requested review from dibyom and jerop May 23, 2024 23:00
@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/apis/pipeline/v1/merge.go 85.0% 85.4% 0.4
pkg/apis/pipeline/v1beta1/merge.go 85.0% 85.4% 0.4

@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/apis/pipeline/v1/merge.go 85.0% 85.4% 0.4
pkg/apis/pipeline/v1beta1/merge.go 85.0% 85.4% 0.4

@chitrangpatel chitrangpatel force-pushed the fix-validation-stepactions-steptemplates branch from a30fabd to 86fc5f7 Compare May 24, 2024 16:39
@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/apis/pipeline/v1/merge.go 85.0% 85.4% 0.4
pkg/apis/pipeline/v1beta1/merge.go 85.0% 85.4% 0.4

@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/apis/pipeline/v1/merge.go 85.0% 85.4% 0.4
pkg/apis/pipeline/v1beta1/merge.go 85.0% 85.4% 0.4

This PR fixes the validation error when using StepTemplates with Steps
referencing StepActions.

Fixes: tektoncd#7981
@chitrangpatel chitrangpatel force-pushed the fix-validation-stepactions-steptemplates branch from 86fc5f7 to d6e2559 Compare May 24, 2024 17:40
@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/apis/pipeline/v1/merge.go 85.0% 85.4% 0.4
pkg/apis/pipeline/v1beta1/merge.go 85.0% 85.4% 0.4

@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/apis/pipeline/v1/merge.go 85.0% 85.4% 0.4
pkg/apis/pipeline/v1beta1/merge.go 85.0% 85.4% 0.4

@chitrangpatel
Copy link
Contributor Author

/assign @JeromeJu @jerop

@@ -46,6 +46,11 @@ func MergeStepsWithStepTemplate(template *StepTemplate, steps []Step) ([]Step, e
}

for i, s := range steps {
// If the stepaction has not been fetched yet then do not merge.
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I'm following here - why does if s.Ref is empty determine if the stepaction has been fetched?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because users can either provide a ref to StepActions (in which case it is not nil) or inline the actionable fields e.g. image, command etc. (in which case ref is nil). There is already a validation check that users cannot provide both ref and image (for example).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And at webhook validation time, we have not yet done the remote resolution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At runtime, after we fetch the StepActions, we inline the content and set ref to nil explicitly. So when we validate at runtime, we can actually do this after the StepAction has been fetched. https://github.com/tektoncd/pipeline/blob/main/pkg/reconciler/taskrun/resources/taskspec.go#L145

@JeromeJu JeromeJu changed the title Fix Validation Error Merging StepTemplates with Step Ref Fix Validation Error Merging StepTemplates with StepRef May 27, 2024
@chitrangpatel chitrangpatel added this to the Pipeline v0.61 milestone May 27, 2024
@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 29, 2024
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 Jun 3, 2024
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

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

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,vdemeester]

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

@tekton-robot tekton-robot merged commit c3f8d70 into tektoncd:main Jun 3, 2024
12 of 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid Validation of StepTemplate with StepAction Ref
5 participants