-
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 CRD validation #130
Taskrun CRD validation #130
Conversation
/assign @pivotal-nader-ziada |
}}, | ||
}, | ||
}, | ||
// TODO(shashwathi): wrong error msg |
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.
can we fix the error msg?
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.
Damn I was suppose to fix it before sending PR :D
} | ||
|
||
// check for input resources | ||
if err := checkForipelineResourceDuplicates(ts.Inputs.Resources, "spec.Inputs.Resources.Name"); 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.
Looks like there's a typo here, the P in Pipeline is missing
@pivotal-nader-ziada @dlorenc : addressed your comments |
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.
Thanks for adding this @shashwathi ! Very thorough validation! :D (and testing!!) I just have a bunch of minor comments
/meow space
t.Errorf("Failed to validate object meta data: %s", err) | ||
} | ||
} | ||
} |
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.
wooot more coverage :D
var _ apis.Validatable = (*TaskRun)(nil) | ||
var _ apis.Defaultable = (*TaskRun)(nil) | ||
|
||
// Assert that Task implements the GenericCRD interface. |
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 think the comments here should say TaskRun
(or just "it" so we dont have to update it each time we copy it XD)
var emptyTarget = ResultTarget{} | ||
if r == emptyTarget { | ||
return 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.
My comment is completely outside the scope of your work so feel free to ignore me but i think maybe the results section should move into status
.
In 9031ed4#diff-b3fd75c449b28741c42f5ff5acc116ac I got a bit confused and removed it from the examples, since we are now requiring a reference to PipelineParams
- but since the logs will be written to some subdir at those endpoints (probably) it's still useful to include them, however maybe the controller can decide the final location and report it in the status
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 should probably just create an issue for this 🤔
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.
Yeah lets make a separate issue for that 👍
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.
kk created #146 sorry for ranting here about it XD
} | ||
// If set then verify all variables pass the validation | ||
if r.Name == "" { | ||
return apis.ErrMissingField(fmt.Sprintf("%s.name", path)) |
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.
im not sure what i think about checking that any field that is required and is a string isn't empty 🤔 one alternative would be to allow the usages to fail instead, seems a bit tedious to do this for every string field
on the other hand maybe it's always better to fail earlier?
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.
That is the purpose for webhook validation, fail early to provide fast feedback about the object field validation.
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.
kk!
// Check the unique combination of resource+version. Covers the use case of inputs with same resource name | ||
// and different versions | ||
key := fmt.Sprintf("%s%s", r.ResourceRef.Name, r.Version) | ||
if _, ok := encountered[strings.ToLower(key)]; ok { |
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.
https://github.com/knative/build-pipeline/blob/master/pkg/apis/pipeline/v1alpha1/task_validation.go#L72 should probably be case insensitive also 🤔
tests := []struct { | ||
name string | ||
spec *TaskRunSpec | ||
wantErr *apis.FieldError |
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 thing, maybe a success case too?
Type: TaskTriggerTypePipelineRun, | ||
}, | ||
}, | ||
}, |
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.
id rather have a separate test function completely for the success cases, i think it makes the tests much easier to understand (like I made @dlorenc do in https://github.com/knative/build-pipeline/blob/master/pkg/apis/pipeline/v1alpha1/task_validation_test.go)
first reading this i actually didnt think there were any success cases
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.
Yeah that makes sense. I have updated tests to have clear distinction between valid and invalid test cases.
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.
sounds good, thanks @shashwathi !
}, | ||
Trigger: TaskTrigger{ | ||
TriggerRef: TaskTriggerRef{ | ||
Type: TaskTriggerTypePipelineRun, |
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.
if the type is pipelinerun
there should be a name
field as well with the name of the pipelinerun
wantErr: apis.ErrMissingField("spec.results.runs.URL"), | ||
}, | ||
{ | ||
name: "valid task type result", |
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.
one idea to reduced the boilerplate in the testcases would be to test validation of the individual types in separate tests, e.g. have a set of tests just for Results
, one just for Inputs
, one just for Params
, etc., then instead of having to instantiate an entire TaskRun
each time, you could just instantiate the section you need to validate
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 did think about that but I am generally not a fan of testing private functions. Probably I could make Validate
functions on each of the types and separate the cases. That might be lot easier to read.
// Check for TaskRef | ||
if ts.TaskRef.Name == "" { | ||
return apis.ErrMissingField("spec.taskref.name") | ||
} |
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.
should we also validate that the referenced Task
exists?
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 that kind of validation, pipeline client is required. In depth validation of related object existence could be done in taskrun controller.
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.
ah interesting, okay good to know!
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/approve |
@bobcatfish : Addressed your comments. Let me know if there is anything else |
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pivotal-nader-ziada, shashwathi, tejal29 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 |
} | ||
}) | ||
} | ||
} |
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.
<3 the tests!!
I am happy to |
- Add tests for metadata validation - Add tests for taskrun validation CRD
af5e1e8
to
90cec7b
Compare
- Applying any taskrun object will invoke the validate function
- Fix typo - Remove redundant field in kritis.yaml that did not comply with task run validation - Fix TODO in test
- TaskRun.trigger.Type is accepted with any capitalization
- Split taskrunspec validation into smaller validation for easy testing and readability - Update task validation to be consistent - Update tests to test individual objects under taskrun
@bobcatfish : Resolved the conflicts. |
@bobcatfish I'm going to /lgtm |
Fixes #33