-
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
Enhance v1beta1 validation code for task 🍸 #3185
Enhance v1beta1 validation code for task 🍸 #3185
Conversation
/hold |
/kind cleanup |
The following is the coverage report on the affected files.
|
1c8ecef
to
8cb3adc
Compare
The following is the coverage report on the affected files.
|
8cb3adc
to
39a21ec
Compare
@@ -44,6 +44,22 @@ func ValidateVariable(name, value, prefix, locationName, path string, vars sets. | |||
return nil | |||
} | |||
|
|||
func ValidateVariableP(value, prefix string, vars sets.String) *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.
This is a temporary simplified function that would replace ValidateVariable
. Didn't change ValidateVariable
because it is used elswhere 🙃
The following is the coverage report on the affected files.
|
39a21ec
to
772f289
Compare
return errs | ||
} | ||
|
||
func (p ParamSpec) ValidateType() *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.
This should move on a different _validation.go
file 😉
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.
yup would be great to move such functions 🙏
The following is the coverage report on the affected files.
|
772f289
to
e75fa6b
Compare
|
||
func (tr TaskResult) Validate(_ context.Context) *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.
This might also go in a separate _validation.go
file
The following is the coverage report on the affected files.
|
e75fa6b
to
2fa0253
Compare
The following is the coverage report on the affected files.
|
2fa0253
to
cfec788
Compare
Should be good to go for |
The following is the coverage report on the affected files.
|
cfec788
to
0ae1c0a
Compare
The following is the coverage report on the affected files.
|
0ae1c0a
to
5764051
Compare
The following is the coverage report on the affected files.
|
/hold cancel |
} | ||
if err := validateTaskResources(tr.Outputs, "outputs"); err != nil { | ||
return err | ||
func (tr *TaskResources) Validate(ctx context.Context) (errs *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.
pointer named return value 😞, could this result in reference to nil
on line 30 or 31?
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.
yes and no, that's the beauty of it 😛 (and this part of knative.dev/pkg
)
See https://pkg.go.dev/knative.dev/[email protected]/apis#FieldError.Also (implementation is here).
func (fe *FieldError) isEmpty() bool {
if fe == nil {
return true
}
return fe.Message == "" && fe.Details == "" && len(fe.errors) == 0 && len(fe.Paths) == 0
}
It won't ever panic, because it knows how to act on a nil
struct 😉
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.
Huge cleanup and improvement, error message are more meaningful with indices 🙏
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pritidesai 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 |
errs = errs.Also(validateTaskVariable(step.WorkingDir, prefix, vars).ViaField("workingDir")) | ||
errs = errs.Also(validateTaskVariable(step.Script, prefix, vars).ViaField("script")) | ||
for i, cmd := range step.Command { | ||
errs = errs.Also(validateTaskVariable(cmd, prefix, vars).ViaFieldIndex("command", i)) |
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: could have been into a common function (line 296 - 308) which is also appearing above
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
This make a better use of knative.dev/pkg apis errors package in order to make the code simpler, *and* the report better. - This allows reporting multiple validation error at once — so, one failure message (webhook error) would be more useful to the user. - This enhance the report as it displays more information, like `resources.inputs[0].invalidsource.type` instead of `resources.inputs.source.type` (the index appear, it's easier for the user to know where the error is). - This reduce `if err != nil` path, simplifying the code. This only tackle this for task_validation, and should be followed-up with other refactoring on the different `*_validation.go` files. Signed-off-by: Vincent Demeester <[email protected]>
5764051
to
7e08dc0
Compare
The following is the coverage report on the affected files.
|
/test pull-tekton-pipeline-integration-tests |
1 similar comment
/test pull-tekton-pipeline-integration-tests |
/lgtm |
Changes
Opening this to gather some feedback.
This make a better use of knative.dev/pkg apis errors package in order
to make the code simpler, and the report better.
failure message (webhook error) would be more useful to the user.
resources.inputs[0].invalidsource.type
instead ofresources.inputs.source.type
(the index appear, it's easier for theuser to know where the error is).
if err != nil
path, simplifying the code./hold
Tests that depends on some of this may fail, I need to fix itvalidateVariables
— it's now used there 😉Task
part (without moving too much code away), follow-up includesv1beta1
package/cc @afrittoli @bobcatfish @sbwsg @nikhil-thomas
Signed-off-by: Vincent Demeester [email protected]
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:
cmd
dir, please updatethe release Task to build and release this image.
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