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

cmd/operator-sdk/generate/crds.go: check for existence of pkg/apis #3091

Merged

Conversation

joelanford
Copy link
Member

@joelanford joelanford commented May 22, 2020

Description of the change:
Emit error message when using operator-sdk generate crds and pkg/apis directory does not exist.

Motivation for the change:
operator-sdk generate crds is generally only supported for Go projects, which have a pkg/apis directory by default. Non-Go projects could use this command, but only if they manually create pkg/apis and define Go types for their APIs.

Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 22, 2020
@estroz
Copy link
Member

estroz commented May 22, 2020

@joelanford this is technically a bugfix right? Would be worth adding a fragment.

// improper CLI usage.
if err := genutil.CRDGen(crdVersion); err != nil {
log.Fatal(err)
switch t := projutil.GetOperatorType(); t {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than switching on this, can we define a new switch that checks for the presence of pkg/apis and go.mod, as it seems that those are the only required files for generation to succeed. This will make it so that users that provide those files can still use these functions in non-Go-based operators

Copy link
Member

Choose a reason for hiding this comment

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

Would they have pkg/apis if cmd/manager/main.go wasn't also present?

Copy link
Member

Choose a reason for hiding this comment

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

currently they would have to create pkg/apis themselves (or do something hacky like touch main.go before running it so that it's detected as a go-type project), but if there is a pkg/apis present then it works whether or not the rest of the scaffolded go code is there

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if there are any users out there who have figured out that this works, but if there are it doesn't seem to be technically necessary for us to block it off. We don't need to explicitly support it (and if we want to should probably add options to the Ansible scaffolding to generate these files), but if a user wants to generate types in this way I see no reason to add additional barriers.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO since we do not support the gen k8s and cRD this shows fine.

However, if we would like to follow up @fabianvf suggestion we can just call the genutil.CRDGen for Ansible and Helm and print an alert informing that is not supported instead of the block as well.

@jmrodri
Copy link
Member

jmrodri commented May 26, 2020

There's a bug associated with this https://bugzilla.redhat.com/show_bug.cgi?id=1838881. Once this PR merges we need to move the bug to MODIFIED.

@@ -17,11 +17,12 @@ package generate
import (
Copy link
Contributor

Choose a reason for hiding this comment

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

missing fragment

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

  • missing fragment before the merge (blocker to merge)
  • Consider the approach to alert that is not supported instead of the block as suggested by @fabianvf

otherwise

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 9, 2020
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@joelanford joelanford changed the title cmd/operator-sdk/generate/crds.go: error with non-go projects cmd/operator-sdk/generate/crds.go: check for existence of pkg/apis Jun 9, 2020
@camilamacedo86
Copy link
Contributor

HI @joelanford,

Shows that it is missing just a rebase with the master to get merged.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 15, 2020
@joelanford
Copy link
Member Author

@fabianvf @estroz @camilamacedo86

Updated per @fabianvf's suggestion and rebased to latest master. PTAL

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Tested locally successfully:

 $ operator-sdk generate crds 
FATA[0000] Failed to generate CRDs; directory "pkg/apis" not found. 

@camilamacedo86 camilamacedo86 added approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. labels Jun 19, 2020
@joelanford joelanford merged commit de24954 into operator-framework:master Jul 7, 2020
@joelanford joelanford deleted the generate-crds-non-go branch July 7, 2020 14:59
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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants