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

TaskRun Validation - Controller Side #208

Merged
merged 1 commit into from
Nov 1, 2018
Merged

TaskRun Validation - Controller Side #208

merged 1 commit into from
Nov 1, 2018

Conversation

aaron-prindle
Copy link
Contributor

@aaron-prindle aaron-prindle commented Oct 31, 2018

What is the problem being solved?
Fixes #188, TaskRun Validation - Controller Side. This PR adds additional TaskRun validation to the TaskRun controller which checks that referenced Params and Resources exist and that they are bound properly from the Task.

Why is this the best approach?
This approach follows the style and convention for a similar issues, #162, PipelineRun validation.

What other approaches did you consider?
N/A

What side effects will this approach have?
It is possible that some demo/sample yaml which use to execute will no longer work as we have this additional validation.

What future work remains to be done?
For the TaskRun controller, I believe that this validation is sufficient. In the future we should extend validation to all of our primitive types, especially PipelineResource.

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 31, 2018
@aaron-prindle aaron-prindle changed the title What is the problem being solved? TaskRun Validation - Controller Side Oct 31, 2018
Copy link
Contributor

@tejal29 tejal29 left a comment

Choose a reason for hiding this comment

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

lgtm except for few small nits.

@@ -294,7 +309,7 @@ func (c *Reconciler) createBuild(tr *v1alpha1.TaskRun, pvcName string) (*buildv1
},
})

// Override the entrypoint so that we can use our custom
// Oerride the entrypoint so that we can use our custom
Copy link
Contributor

@tejal29 tejal29 Oct 31, 2018

Choose a reason for hiding this comment

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

  • nit: override

@@ -319,7 +334,7 @@ func (c *Reconciler) createBuild(tr *v1alpha1.TaskRun, pvcName string) (*buildv1
Spec: *bSpec,
}
// Pass service account name from taskrun to build
// if task specifies service account name override with taskrun SA
// if task specifies service account name oerride with taskrun SA
Copy link
Contributor

@tejal29 tejal29 Oct 31, 2018

Choose a reason for hiding this comment

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

  • nit: override

},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
c, _, clients := test.GetTaskRunController(d)
// c, _, _ := test.GetTaskRunController(d)
Copy link
Contributor

@tejal29 tejal29 Oct 31, 2018

Choose a reason for hiding this comment

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

  • nit: remove.

err := c.Reconciler.Reconcile(context.Background(), getRunName(tc.taskRun))
// When a TaskRun is invalid and can't run, we don't want to return an error because
// an error will tell the Reconciler to keep trying to reconcile; instead we want to stop
// and forget about the Run.
if err != nil {
t.Errorf("Did not expect to see error when reconciling invalid TaskRun but saw %q", err)
}
if len(clients.Build.Actions()) != 1 {
t.Errorf("expected no actions to be created by the reconciler, got %v", clients.Build.Actions())
if len(clients.Build.Actions()) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice catch! shdn't have created a build for invalid task.

return fmt.Errorf("Error listing task ref %s: %v",
tr.Spec.TaskRef.Name, err)
}
if err := validateTaskRunAndTask(c, *tr, t, tr.Namespace); err != nil {
Copy link
Contributor

@tejal29 tejal29 Oct 31, 2018

Choose a reason for hiding this comment

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

  • you can just return validateTaskRunAndTask here.

},
Spec: v1alpha1.TaskRunSpec{
TaskRef: v1alpha1.TaskRef{
//
Copy link
Contributor

@tejal29 tejal29 Oct 31, 2018

Choose a reason for hiding this comment

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

  • nit: remove

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Copy link
Contributor

@tejal29 tejal29 Oct 31, 2018

Choose a reason for hiding this comment

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

  • for completeness, can we add a test for valid TaskRun and then make sure validateTaskRun does not return err. Ignore if this comment if this is already tested somewhere else.

}, {
name: "resource-mismatch",
taskrun: trs[3],
reason: "input-resource-mismatch",
Copy link
Contributor

@tejal29 tejal29 Oct 31, 2018

Choose a reason for hiding this comment

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

nit: this reason is not used anywhere. can we drop it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can drop it, i think it supposed to be a helpful descriptor for the test. I am copying the test format used in PipelineRun. I will leave this as is for now.

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.

Same nit as @tejal29 otherwise looks good ;)

},
Spec: v1alpha1.TaskRunSpec{
TaskRef: v1alpha1.TaskRef{
//
Copy link
Member

@vdemeester vdemeester Oct 31, 2018

Choose a reason for hiding this comment

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

  • nit: remove (aussi)

@@ -130,7 +132,6 @@ func (r TaskTriggerRef) Validate(path string) *apis.FieldError {

if taskType == allowedType {
if allowedType == strings.ToLower(string(TaskTriggerTypePipelineRun)) && r.Name == "" {
fmt.Println("HERE")
Copy link
Collaborator

Choose a reason for hiding this comment

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

happens to the best of us :D

func (t *TaskRun) Validate() *apis.FieldError {
if err := validateObjectMetadata(t.GetObjectMeta()).ViaField("metadata"); err != nil {
return err
}
return t.Spec.Validate()
}

// Validate taskrun spec
Copy link
Collaborator

Choose a reason for hiding this comment

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

i know the linters want this, but if we're going to include a comment here, can we add some more information? maybe one or both of:

  • Talk about how this is going to be used (called by the controller on creation?)
  • Talk about what it means for the TaskRun to be valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

going to leave as is for now, will refactor PipelineRun and TaskRun comments when the refactor goes in combining their logic

@knative-prow-robot knative-prow-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 31, 2018
@aaron-prindle
Copy link
Contributor Author

all requested changes addressed/changed

Copy link
Contributor

@tejal29 tejal29 left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 1, 2018
@knative-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aaron-prindle, tejal29, 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 [aaron-prindle,tejal29]

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

What is the problem being solved?
Fixes #188, TaskRun Validation - Controller Side.  This PR adds additional TaskRun validation to the TaskRun controller which checks that referenced Params and Resources exist and that they are bound properly from the Task.

Why is this the best approach?
This approach follows the style and convention for a similar issues, #162, PipelineRun validation.

What other approaches did you consider?
N/A

What side effects will this approach have?
It is possible that some demo/sample yaml which use to execute will no longer work as we have this additional validation.

What future work remains to be done?
For the TaskRun controller, I believe that this validation is sufficient.  In the future we should extend validation to all of our primitive types, especially PipelineResource.
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Nov 1, 2018
@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/apis/pipeline/v1alpha1/taskrun_validation.go 93.2% 93.1% -0.1
pkg/reconciler/v1alpha1/taskrun/taskrun.go 76.4% 72.7% -3.7
pkg/reconciler/v1alpha1/taskrun/validate.go Do not exist 92.9%

@tejal29
Copy link
Contributor

tejal29 commented Nov 1, 2018

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 1, 2018
@knative-prow-robot knative-prow-robot merged commit 9ae0688 into tektoncd:master Nov 1, 2018
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.

6 participants