-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Replace ValidateFrom with pipelineSpec.Validate #1452
Conversation
While working on tektoncd#1256 I noticed that we had two different functions to validate that the `from` field. One was being used by the webhook, and the other in the reconciler. I replaced the `ValidateFrom` in the reconciler with the more general `Validate` that validates the entire pipeline spec, not just one field. In addition, I fixed some of the reconciler tests that were now failing due to having an invalid pipeline spec e.g. pipeline tasks with no name. Signed-off-by: Dibyo Mukherjee <[email protected]>
The following is the coverage report on pkg/.
|
/lgtm |
// it corresponds to must actually exist in the `Pipeline`. The `PipelineResource` that is bound to the input | ||
// must be the same `PipelineResource` that was bound to the output of the previous `Task`. If the state is | ||
// not valid, it will return an error. | ||
func ValidateFrom(state PipelineRunState) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the PipelineSpec
validateFrom
function.
func validateFrom(tasks []PipelineTask) error {
taskOutputs := map[string][]PipelineTaskOutputResource{}
for _, task := range tasks {
var to []PipelineTaskOutputResource
if task.Resources != nil {
to = make([]PipelineTaskOutputResource, len(task.Resources.Outputs))
copy(to, task.Resources.Outputs)
}
taskOutputs[task.Name] = to
}
for _, t := range tasks {
if t.Resources != nil {
for _, rd := range t.Resources.Inputs {
for _, pb := range rd.From {
outputs, found := taskOutputs[pb]
if !found {
return xerrors.Errorf("expected resource %s to be from task %s, but task %s doesn't exist", rd.Resource, pb, pb)
}
if !isOutput(outputs, rd.Resource) {
return xerrors.Errorf("the resource %s from %s must be an output but is an input", rd.Resource, pb)
}
}
}
}
}
return nil
}
In the PipelineSpec
validation, we don't check the sameBinding
case 🤔 I am not entirely sure what this check was about but we may be missing something…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the test cases for the sameBinding case i.e. the ones that test that the error contains the word ambiguous, there are 3 test cases:
- from tries to reference input - covered by spec.Validate
- "from resource doesn't exist" - covered by spec.Validate
- "from is bound to different resource" - need to double check what this case is doing 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so case 3 is from say task B has a from that says use resource "foo" from Task A while Task A produces a resource named "bar". I think pipelineSpec.Validate covers this. So, I think all 3 cases of "same binding" are covered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: 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:
Approvers can indicate their approval by writing |
Is there a race (in our tests or code) (see here)
|
/test pull-tekton-pipeline-integration-tests |
2 similar comments
/test pull-tekton-pipeline-integration-tests |
/test pull-tekton-pipeline-integration-tests |
Nice catch @dibyom !! 🎉 @vdemeester should we open an issue about that race? 🏇 |
I guess we should 👼 |
Changes
While working on #1256 I noticed that we had two different functions
to validate that the
from
field. One was being used by the webhook,and the other in the reconciler. I replaced the
ValidateFrom
in thereconciler with the more general
Validate
that validates the entirepipeline spec, not just one field. In addition, I fixed some of the
reconciler tests that were now failing due to having an invalid pipeline
spec e.g. pipeline tasks with no name.
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide for more details.
Double check this list of stuff that's easy to miss:
cmd
dir, please updatethe release Task to build and release this image.
Reviewer Notes
If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.
Release Notes