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

Replace ValidateFrom with pipelineSpec.Validate #1452

Merged
merged 1 commit into from
Oct 30, 2019

Conversation

dibyom
Copy link
Member

@dibyom dibyom commented Oct 22, 2019

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 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.

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:

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

Describe any user facing changes here, or delete this block.

Examples of user facing changes:
- API changes
- Bug fixes
- Any changes in behavior

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]>
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Oct 22, 2019
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 22, 2019
@dibyom dibyom changed the title Replace ValidateFrom with PipelineSpec.Validate Replace ValidateFrom with pipelineSpec.Validate Oct 22, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/pipelinerun/pipelinerun.go 83.5% 83.9% 0.4
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 95.2% 94.6% -0.6

@ghost
Copy link

ghost commented Oct 22, 2019

/lgtm

@tekton-robot tekton-robot assigned ghost Oct 22, 2019
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 22, 2019
// 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 {
Copy link
Member

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…

Copy link
Member Author

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:

  1. from tries to reference input - covered by spec.Validate
  2. "from resource doesn't exist" - covered by spec.Validate
  3. "from is bound to different resource" - need to double check what this case is doing 🤔

Copy link
Member Author

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

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
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 26, 2019
@vdemeester
Copy link
Member

Is there a race (in our tests or code) (see here)

    ---
    apiVersion: tekton.dev/v1alpha1
    kind: Task
    metadata:
      creationTimestamp: "2019-10-26T16:14:32Z"
      generation: 1
      name: status-task
      namespace: arendelle-5n7wl
      resourceVersion: "4775"
      selfLink: /apis/tekton.dev/v1alpha1/namespaces/arendelle-5n7wl/tasks/status-task
      uid: b1c92802-f80b-11e9-a134-42010a800114
    spec:
      steps:
      - args:
        - -c
        - echo hello
        command:
        - /bin/sh
        image: busybox@sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
        name: hello
        resources: {}
    
    ---
    apiVersion: tekton.dev/v1alpha1
    kind: TaskRun
    metadata:
      creationTimestamp: "2019-10-26T16:14:32Z"
      generation: 1
      name: status-taskrun
      namespace: arendelle-5n7wl
      resourceVersion: "4777"
      selfLink: /apis/tekton.dev/v1alpha1/namespaces/arendelle-5n7wl/taskruns/status-taskrun
      uid: b1cb2bff-f80b-11e9-a134-42010a800114
    spec:
      inputs: {}
      outputs: {}
      podTemplate: {}
      serviceAccountName: ""
      taskRef:
        kind: Task
        name: status-task
      timeout: 1h0m0s
    status:
      conditions:
      - lastTransitionTime: "2019-10-26T16:14:32Z"
        message: 'error when listing tasks for taskRun status-taskrun: task.tekton.dev
          "status-task" not found'
        reason: TaskRunResolutionFailed
        status: "False"
        type: Succeeded
      podName: ""
      startTime: "2019-10-26T16:14:32Z"

@vdemeester
Copy link
Member

/test pull-tekton-pipeline-integration-tests

2 similar comments
@dibyom
Copy link
Member Author

dibyom commented Oct 29, 2019

/test pull-tekton-pipeline-integration-tests

@dibyom
Copy link
Member Author

dibyom commented Oct 30, 2019

/test pull-tekton-pipeline-integration-tests

@tekton-robot tekton-robot merged commit fe47335 into tektoncd:master Oct 30, 2019
@bobcatfish
Copy link
Collaborator

Nice catch @dibyom !! 🎉

@vdemeester should we open an issue about that race? 🏇

@vdemeester
Copy link
Member

I guess we should 👼

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. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. 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.

5 participants