-
Notifications
You must be signed in to change notification settings - Fork 407
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
Proposal for meta-generator #17
Conversation
Can we relax the assumption that everything will be inside the |
@tamalsaha updated |
cc @erictune |
Thanks @pwittrock ! LGTM! |
docs/proposals/kubegen.md
Outdated
patterns. | ||
|
||
- **group pattern**: ^[a-z]+$ | ||
- **version pattern**: ^v\\d+(alpha\\d+|beta\\d+)*$ |
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.
just wondering, since i haven't seen it in use, would something like "v1alpha1alpha1alpha1alpha1" be accepted as a 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.
hm, good point, I don't think that is ok. Should probably be ^v\\d+(alpha\\d+|beta\\d+)?$
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 do we restrict the version pattern here?
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 for the group pattern.
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 think it could be useful to restrict, since some generators assume things about how the version will be formatted, like this one
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 have found the code generators and apimachinery makes assumptions about the pattern and break unexpectedly and with obscure errors when they are not followed.
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.
It must be a valid Go identifier. But other than that? Restricting it to alpha/beta is definitely not necessary. If we require that anywhere, we should fix it.
@stts what is the typical process to get lazy consensus in this repo? |
docs/proposals/kubegen.md
Outdated
- **version pattern**: ^v\\d+(alpha\\d+|beta\\d+)*$ | ||
|
||
By default, kubegen will run code generators for both external types defined under `pkg/apis/<group>/<version>` and | ||
internal types defined under `pkg/apis/<group>`. The location kubegen searches can be overridden. |
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 have to support the pattern established by k8s.io/api, i.e. that the external APIs are in a different repo. I understand both location can be overridden? locations
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 section about this in the FAQ at the end
|
||
kubegen will prepend all generated files with copyright and license comments. | ||
|
||
By default, the kubegen binary runs all* of the Kubernetes code |
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.
what is all? The list varies depending on external-type-only projects (usually CRDs of k8s.io/api like repos) and user-provider APIServers.
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.
the list is directly below this statement. crd use cases can manually specify the generators they need
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.
Don't like to specify the generators manually. We have these two pretty well defined use-cases: external types only, internal+external. They should just work out of the box. If things are not needed (e.g. protobuf), this should be auto-detected by the lack of tags.
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 think you are right. We may need some break glass in the future, but best not to start with it.
Are there existing tags we should us?
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.
Does this allow us to disable things like deepcopy and conversiongen?
docs/proposals/kubegen.md
Outdated
- informer-gen | ||
- lister-gen | ||
- openapi-gen | ||
- set-gen |
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.
set-gen is independent. It's not run by API groups.
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
The license can be overridden from the LICENSE file using the `--license` flag | ||
|
||
```sh | ||
kubegen --license "Apache 2.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.
How much do we want to deviate from the gengo flag go-header-file
. I don't see much additional value of these fine-grained flags.
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 provides a simpler bootstrapping experience for new projects by removing an extra step.
The license file can be overridden from the LICENSE file using the `--license-file` flag | ||
|
||
```sh | ||
kubegen --license-file "boilerplate.go.txt" |
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.
can we re-use the gengo flag name --go-header-file
?
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 find this to be more descriptive and that it models the intent better. the go-header-file is in practice just the copyright and license. I would expect most new repos / projects to use the LICENSE file in the project root if it exists. this flag name more closely matches the default.
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.
Took a moment to understand that you want something else. The "boilerplate.go.txt" example flag is wrong.
There is no reason not support both. But I like the idea to use the LICENSE file by default.
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.
How about we start with just --license-file
with the description saying it specifies boilerplate.go.txt. Having 2 flags for the same thing is a bit confusing.
|
||
Generating code using only a specific set of generators can be performed using the | ||
`--generator` flag. This flag may be provided multiple times to run multiple | ||
generators. |
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.
it's a bit odd that the first --generator
arg replaces the "all generators" list with a single generator. Then the second appearance appends the generator. IMO a comma separated --generators
is more natural.
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 is a common pattern for cobra commands and I believe is preferred. Comma separated lists are hard when there can be commas in the lists.
directories. | ||
|
||
```sh | ||
kubegen --apis-dir notpkg/apis --apis-dir pkg/notapis |
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.
are these internal api types or external?
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.
either. It is the directory containing the groups.
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.
For some generator it makes a difference. I don't think we should use the same arg. It's a fundamental concept of our apis and our generators that the user easily understands. IMO we should have:
kubegen --apis-dir ... --internal-apis-dir ...
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 like this. We will just need to be careful that the default values correctly detect whether internal or external types should be generated. e.g. --internal-apis-dir
defaults to pkg/apis
, and if there are no internal types defined, it should just skip generating internal types.
|
||
- run all code generators against discovered APIs | ||
- search for API group versions under notpkg/apis and pkg/notapis instead of pkg/apis | ||
|
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.
What about the output-package?
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.
Do we pass through any gengo args?
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.
For reference, these are the gengo flags:
fs.StringSliceVarP(&g.InputDirs, "input-dirs", "i", g.InputDirs, "Comma-separated list of import paths to get input types from.")
fs.StringVarP(&g.OutputBase, "output-base", "o", g.OutputBase, "Output base; defaults to $GOPATH/src/ or ./ if $GOPATH is not set.")
fs.StringVarP(&g.OutputPackagePath, "output-package", "p", g.OutputPackagePath, "Base package path.")
fs.StringVarP(&g.OutputFileBaseName, "output-file-base", "O", g.OutputFileBaseName, "Base name (without .go suffix) for output files.")
fs.StringVarP(&g.GoHeaderFilePath, "go-header-file", "h", g.GoHeaderFilePath, "File containing boilerplate header text. The string YEAR will be replaced with the current 4-digit year.")
fs.BoolVar(&g.VerifyOnly, "verify-only", g.VerifyOnly, "If true, only verify existing output, do not write anything.")
fs.StringVar(&g.GeneratedBuildTag, "build-tag", g.GeneratedBuildTag, "A Go build tag to use to identify files generated by this command. Should be unique.")
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.
There might be generator-specific flags we have to pass through as well. We should have a way to do this and/or look through the existing gen-specific flags.
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.
Agreed, though I would prefer to initially provide the simplest interface that works, and then add this additional complexity as we discover it is needed.
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.
Lets start with defaulting the output package and add it when we discover it is necessary.
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.
Actually, it's only --verify-only
I care about right now from the generic flags. But there are more converter specific flags. Just saying that we should be prepared to offer converter specific ones, e.g. --conversion-gen-exceptions-file
, --client-gen-clientset-name
.
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.
SGTM. I am proposing exposing --verify-only
as --dry-run
since it is a much more common flag name and has the same meaning. Thoughts?
I don't think there is a policy for that. I guess in kubernetes/community the proposal process is written down somewhere. |
Moved to kubernetes/community#1315 |
Thanks for all your comments @sttts I tried to respond or address all of them. The flag name changes I am suggesting are trying to make it as simple and understandable for folks that don't already have the background and history of the code generators. e.g. the history of boilerplate.go.txt. |
Left a couple of more comments. WIll switch to the new community PR now. |
@sttts Addressed comments in the community repo. |
This is a proposal in the form of what would be the user facing documentation for a meta code generation tool.
kubernetes/kubernetes#53524