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 crd generation does not work across modules layouts #516

Closed
phantomjinx opened this issue Nov 11, 2020 · 10 comments · Fixed by #663
Closed

controller-gen crd generation does not work across modules layouts #516

phantomjinx opened this issue Nov 11, 2020 · 10 comments · Fixed by #663
Assignees
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@phantomjinx
Copy link

The operator-sdk documentation lays out an operator go project with api in the root directory. It also creates a Makefile with the rule make manifests defined as

$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

so relying on controller-gen for generation of the operator CRDs.

While migrating an operator project to using this CRD generation, there exists an issue with apis that have been modularized, ie. api directory with their own mod.go file.

I've created a repository demonstrating the problem using the memcached-operator example.

  • An api is generated with a version "v1" and given the kind "memcached";
  • A 2nd api is generated with a version "v1alpha1" and given the kind "memcachedext";
  • The 2nd api then uses a type from the v1 api hence placing a parent-child dependency on these apis.

For this to compile correctly, the v1 package had to be imported into the v1alpha1 api. This happened to require the api be modularized. Maybe, this is unnecessary for solving the import problem but is required anyway for making available the api as a module in its own right.

Issues:

  • make manifests fails to generate any CRDs due to the controller-gen command;
  • If the go.mod is removed then things do get generated and this seems to be a possible workaround. However, a further problem emerges due to v1alpha1 depending on v1 with the v1 CRD containing a duplicated schema, ie. 2 versions of schema v1.
@phantomjinx
Copy link
Author

Update on duplicated schema
This appears to be intermittent and maybe dependent on there be a copy of the api directory, eg. in the camel-k project the api is located in pkg/apis so a workaround is to copy it to /api first. Consequently, every other execution of controller-gen seems to generate duplicate schema in the CRDs.
Cannot currently mirror this reliably in the example project other than to copy /api down to /pkg/apis and then execute controller-gen with paths=./.... In the camel-k project, duplication does occur even when setting paths=./api/....

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 9, 2021
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 11, 2021
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-contributor-experience at kubernetes/community.
/close

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.

@akutz
Copy link
Contributor

akutz commented Apr 22, 2022

I am currently bit by this as well. Has anyone encountered a solution in the wild?

@akutz
Copy link
Contributor

akutz commented Apr 22, 2022

I found a work-around, but it has its own issues.

@akutz
Copy link
Contributor

akutz commented Apr 23, 2022

I filed a PR to fix this issue -- #663.

@alvaroaleman
Copy link
Member

/assign akutz

@akutz
Copy link
Contributor

akutz commented May 3, 2022

This has been fixed with #663.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants