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

Separate logic to follow references from TaskRun resource validation #261

Merged

Conversation

bobcatfish
Copy link
Collaborator

In the TaskRun reconciler, there were several different places where logic exists to retrieve references Tasks and Resources; now we use a library that allows us to retrieve these references up front and use them instead of using Listers everywhere.

We now use the resolved TaskRun when validating the TaskRun, so we no longer need access to the reconciler or to do any listing when validating the TaskRun.

This is a step along the way to #213. Next we can do a similar refactoring to the PipelineRun validation. (The goal is that we can share the validation logic, since it's looking at the same thing just the structure of the input objects is different.) We'll probably also separate the param validation out from the resource validation.

The current validation will miss the case where extra resources or parameters that aren't needed are supplied (this was the case already).

@knative-prow-robot knative-prow-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 22, 2018
@knative-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bobcatfish

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 22, 2018
// ResolveTaskRun looks up CRDs referenced by the TaskRun and returns an instance
// of TaskRunResource with all of the relevant data populated. If referenced CRDs can't
// be found, an error is returned.
func ResolveTaskRun(tr *v1alpha1.TaskRunSpec, gt GetTask, gr GetResource) (*ResolvedTaskRun, error) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: any reason to use such short variable names ? Using getTask, getResource would make the following code a bit easier to read 👼

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure I'll change it!

I'm always torn between whether to use shorter or longer names - I feel like Go code in general seems to prefer shorter names, but it looks like I did it at the expense of readability here :D

Copy link
Member

Choose a reason for hiding this comment

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

@bobcatfish I tend to use https://github.com/golang/go/wiki/CodeReviewComments as a guideline, adding to this a "try to not have too close variable names" 👼 😝

The basic rule: the further from its declaration that a name is used, the more descriptive the name must be. For a method receiver, one or two letters is sufficient. Common variables such as loop indices and readers can be a single letter (i, r). More unusual things and global variables need more descriptive names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh nice, that's great advice!! thanks for the link :D

// ReasonFailedValidation indicated that the reason for failure status is
// that pipelinerun failed runtime validation
// that taskrun failed runtime validation
Copy link
Member

Choose a reason for hiding this comment

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

🕺

In the TaskRun reconciler, there are several different places where
logic exists to retrieve references Tasks and Resources; this library
will allow us to retrieve these references up front and use them instead
of using Listers everywhere.

This is a step toward fixing tektoncd#213 (the goal is to reuse and simplify
this logic).
With this change, we can use the resolved TaskRun when validating the
TaskRun, so we no longer need access to the reconciler or to do any
listing when validating the TaskRun.

This is a step along the way to tektoncd#213. Next we can do a similar
refactoring to the PipelineRun validation. (The goal is that we can
share the validation logic, since it's looking at the same thing just
the structure of the input objects is different.) We'll probably also
separate the param validation out from the resource validation.

The current validation will miss the case where extra resources or
parameters that aren't needed are supplied (this was the case already).
@knative-metrics-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/taskrun/resources/taskrunresolution.go Do not exist 100.0%
pkg/reconciler/v1alpha1/taskrun/taskrun.go 74.4% 73.2% -1.2
pkg/reconciler/v1alpha1/taskrun/validate.go 92.9% 100.0% 7.1

@nader-ziada
Copy link
Member

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 26, 2018
@knative-prow-robot knative-prow-robot merged commit b9be159 into tektoncd:master Nov 26, 2018
chmouel pushed a commit to chmouel/tektoncd-pipeline that referenced this pull request Dec 13, 2019
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. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants