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 CRD validation #130

Merged
merged 8 commits into from
Oct 13, 2018

Conversation

shashwathi
Copy link
Contributor

@shashwathi shashwathi commented Oct 11, 2018

Fixes #33

  • Added taskrun CRD validation
  • Added tests for metadata validation

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. 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 11, 2018
@shashwathi
Copy link
Contributor Author

/assign @pivotal-nader-ziada
/assign @bobcatfish

}},
},
},
// TODO(shashwathi): wrong error msg
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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

@shashwathi
Copy link
Contributor Author

@pivotal-nader-ziada @dlorenc : addressed your comments

Copy link
Collaborator

@bobcatfish bobcatfish left a 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)
}
}
}
Copy link
Collaborator

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.
Copy link
Collaborator

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
}
Copy link
Collaborator

@bobcatfish bobcatfish Oct 11, 2018

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

Copy link
Collaborator

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 🤔

Copy link
Contributor Author

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 👍

Copy link
Collaborator

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))
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

tests := []struct {
name string
spec *TaskRunSpec
wantErr *apis.FieldError
Copy link
Collaborator

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,
},
},
},
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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,
Copy link
Collaborator

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",
Copy link
Collaborator

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

Copy link
Contributor Author

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")
}
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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!

@knative-prow-robot
Copy link

@bobcatfish: cat image

In response to this:

Thanks for adding this @shashwathi ! Very thorough validation! :D (and testing!!) I just have a bunch of minor comments

/meow space

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.

@nader-ziada
Copy link
Member

nader-ziada commented Oct 12, 2018

/approve

@shashwathi
Copy link
Contributor Author

@bobcatfish : Addressed your comments. Let me know if there is anything else

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.

/approve

@knative-prow-robot
Copy link

[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:
  • OWNERS [pivotal-nader-ziada,tejal29]

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 Oct 12, 2018
}
})
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

<3 the tests!!

@bobcatfish
Copy link
Collaborator

I am happy to /lgtm - i think there's a conflict that has to get resolved first tho 😩

Shash Reddy added 2 commits October 12, 2018 21:37
- Add tests for metadata validation
- Add tests for taskrun validation CRD
Shash Reddy and others added 6 commits October 12, 2018 21:38
- 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
@shashwathi
Copy link
Contributor Author

@bobcatfish : Resolved the conflicts.

@nader-ziada
Copy link
Member

@bobcatfish I'm going to lgtm it since you said you are all good with it and now the conflicts are resolved

/lgtm

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