-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support installing CRDs from yaml files in test package #51
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
Conversation
pwittrock
commented
Jun 19, 2018
- also rename test package to envtest
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
pkg/envtest/crd.go
Outdated
} | ||
|
||
// White list the file extensions that may contain CRDs | ||
crdExts := sets.NewString(".json", ".yaml") |
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 .yml
extension also be supported ?
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.
done
} | ||
|
||
// Check that it is actually a CRD | ||
if crd.Spec.Names.Kind == "" || crd.Spec.Group == "" { |
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 takeSpec.Scope
to consideration as well ?
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 don't thin so. This is really just to check if it was an unrelated type that happened to parse since go doesn't throw an error if the file is valid yaml but the schema doesn't match.
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 good, minor comments.
pkg/envtest/crd.go
Outdated
) | ||
|
||
// CRDOptions are the options for installing CRDs | ||
type CRDOptions 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.
CRDInstallOptions ? (then it will be self-documenting I guess and we won't need 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.
Done
pkg/envtest/crd.go
Outdated
// Read the CRD yamls into options.CRDs | ||
if err := readCRDFiles(&options); err != nil { | ||
return options.CRDs, 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.
why are we not returning nil (slice of CRDs) in case of error ?
|
||
// Create the CRDs in the apiserver | ||
if err := CreateCRDs(config, options.CRDs); err != nil { | ||
return options.CRDs, 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.
same question as above.
|
||
// Wait for the CRDs to appear as Resources in the apiserver | ||
if err := WaitForCRDs(config, options.CRDs, options); err != nil { | ||
return options.CRDs, 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.
same question as above.
if err != nil { | ||
return err | ||
} | ||
options.CRDs = append(options.CRDs, new...) |
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 get it now why we are returning non-nil list in case of error above. Ignore those comments.
pkg/envtest/crd.go
Outdated
|
||
// readCRDFiles reads the directories of CRDs in options.Paths and adds the CRD structs to options.CRDs | ||
func readCRDFiles(options *CRDOptions) error { | ||
if len(options.Paths) > 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.
This line is redundant. wondering if metalinter will catch 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.
I cleaned this up a bit to get the linter to pass and the tests working . PTAL
pkg/envtest/crd.go
Outdated
} | ||
// Poll until all resources are found | ||
return wait.PollImmediate(options.pollInterval, options.maxTime, func() (bool, error) { | ||
// Create a new clientset to avoid any client caching of discovery |
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.
putting it in a separate func will improve the readability and avoid errors with sharing the waitingFor
.
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.
done
pkg/envtest/crd.go
Outdated
} | ||
|
||
// Get the Resources for this GroupVersion | ||
resourceList, err := cs.Discovery().ServerResourcesForGroupVersion(gv.Group + "/" + gv.Version) |
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.
unrelated: I am thinking if we should have a method to discover resources in our new client interface ? or a way to get discoveryClient without getting the cs
.
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.
Added a todo
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.
Added a todo
pkg/envtest/crd.go
Outdated
// All resources found, do nothing | ||
if resources.Len() == 0 { | ||
delete(waitingFor, gv) | ||
continue |
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 wonder if it is safe to delete an element from map while iterating over 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.
Yes it is. I had the same question.
|
||
// Create each CRD | ||
for _, crd := range crds { | ||
if _, err := cs.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd); 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.
wondering if we can use pkg/client
do 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.
We could, but i need this for discovery anyway...
New changes are detected. LGTM label has been removed. |
- also rename test package to envtest
PTAL |
Support installing CRDs from yaml files in test package
Flesh out documentation on homepage
CARRY: KCP example