-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
cmd/operator-sdk/generate/crds.go: check for existence of pkg/apis
#3091
Conversation
4f0293f
to
140b81c
Compare
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
@joelanford this is technically a bugfix right? Would be worth adding a fragment. |
cmd/operator-sdk/generate/crds.go
Outdated
// improper CLI usage. | ||
if err := genutil.CRDGen(crdVersion); err != nil { | ||
log.Fatal(err) | ||
switch t := projutil.GetOperatorType(); t { |
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.
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
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.
Would they have pkg/apis
if cmd/manager/main.go
wasn't also present?
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.
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
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'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.
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.
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.
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 ( |
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.
missing fragment
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.
- 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
140b81c
to
66bca03
Compare
New changes are detected. LGTM label has been removed. |
66bca03
to
0e08657
Compare
pkg/apis
HI @joelanford, Shows that it is missing just a rebase with the master to get merged. |
0e08657
to
652ca2c
Compare
@fabianvf @estroz @camilamacedo86 Updated per @fabianvf's suggestion and rebased to latest |
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.
Tested locally successfully:
$ operator-sdk generate crds
FATA[0000] Failed to generate CRDs; directory "pkg/apis" not found.
Description of the change:
Emit error message when using
operator-sdk generate crds
andpkg/apis
directory does not exist.Motivation for the change:
operator-sdk generate crds
is generally only supported for Go projects, which have apkg/apis
directory by default. Non-Go projects could use this command, but only if they manually createpkg/apis
and define Go types for their APIs.