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

controller-gen v0.9.0 does not generate CRDs for additional paths #680

Closed
sbueringer opened this issue May 25, 2022 · 2 comments · Fixed by #681
Closed

controller-gen v0.9.0 does not generate CRDs for additional paths #680

sbueringer opened this issue May 25, 2022 · 2 comments · Fixed by #681

Comments

@sbueringer
Copy link
Member

sbueringer commented May 25, 2022

The new controller-gen version only generates CRDs for the first specified path.

An example:

controller-gen-v0.9.0 \
                paths=./api/... \
                paths=./exp/api/... \
                crd:crdVersions=v1 \
                output:crd:dir=./config/crd/bases

Only CRDs from the ./api/ folder are generated/updated none of ./exp/api/... (i.e. the MachinePool CRD).

I took a closer look at the code and it looks like the metav1Pkg does not match when checking if MachinePool has ObjectMeta and TypeMeta:

if fieldPkg != metav1Pkg {

Not sure if it would be a correct fix, but by changing the line to

			if fieldPkg != nil && fieldPkg.PkgPath != metav1Pkg.PkgPath {

controller-gen was updating the MachinePool CRD again.

I think it's an additional issue, but after introducing this fix controller-gen did update the MachinePool CRD but it ignored the +kubebuilder:validation:MinLength=1 annotation (i.e. it didn't include minLength in the CRD anymore).

@sbueringer sbueringer changed the title controller-tools v0.9.0 does not generate CRDs for additional paths controller-gen v0.9.0 does not generate CRDs for additional paths May 25, 2022
@sbueringer
Copy link
Member Author

I think the issue was introduced via #663.

I reverted #663 locally (on top of the v0.9.0 release) and both issues were resolved.

@akutz can you please take a look when you've got some time? Thank you!

@akutz
Copy link
Contributor

akutz commented May 25, 2022

I am taking a look. This is definitely odd as the paths should arrive in the library call as a single slice.

akutz added a commit to akutz/controller-tools that referenced this issue May 25, 2022
This patch updates the way the CRD generator compares an imported
metav1 package. Previously the comparison occurred using a Golang
equality operator, !=, against two, in-memory data structures.
However, this fails when multiple root paths are loaded. Their
metav1 packages are identical, just not identical objects in
memory. This patch updates the comparison to compare the package
IDs, not the instance of the object.

Fixes kubernetes-sigs#680
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants