-
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
TaskRun Validation - Controller Side #208
TaskRun Validation - Controller Side #208
Conversation
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 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 |
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.
- 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 |
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.
- nit: override
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
c, _, clients := test.GetTaskRunController(d) | ||
// c, _, _ := test.GetTaskRunController(d) |
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.
- 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 { |
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.
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 { |
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.
- you can just return validateTaskRunAndTask here.
}, | ||
Spec: v1alpha1.TaskRunSpec{ | ||
TaskRef: v1alpha1.TaskRef{ | ||
// |
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.
- nit: remove
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
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.
- 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", |
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.
nit: this reason is not used anywhere. can we drop it?
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.
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.
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.
Same nit as @tejal29 otherwise looks good ;)
}, | ||
Spec: v1alpha1.TaskRunSpec{ | ||
TaskRef: v1alpha1.TaskRef{ | ||
// |
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.
- 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") |
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.
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 |
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.
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
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.
going to leave as is for now, will refactor PipelineRun and TaskRun comments when the refactor goes in combining their logic
all requested changes addressed/changed |
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: 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:
Approvers can indicate their approval by writing |
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.
The following is the coverage report on pkg/.
|
/lgtm |
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.