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

Proposal for meta-generator #17

Closed
wants to merge 3 commits into from
Closed

Conversation

pwittrock
Copy link
Member

@pwittrock pwittrock commented Oct 30, 2017

This is a proposal in the form of what would be the user facing documentation for a meta code generation tool.

kubernetes/kubernetes#53524

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 30, 2017
@tamalsaha
Copy link
Member

Can we relax the assumption that everything will be inside the pkg package? We like to define things without pkg. For example: https://github.com/appscode/voyager

@pwittrock
Copy link
Member Author

@tamalsaha updated

@pwittrock
Copy link
Member Author

cc @erictune

@tamalsaha
Copy link
Member

Thanks @pwittrock ! LGTM!

patterns.

- **group pattern**: ^[a-z]+$
- **version pattern**: ^v\\d+(alpha\\d+|beta\\d+)*$

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?

Copy link
Member Author

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+)?$

Copy link
Contributor

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?

Copy link
Contributor

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.

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@jennybuckley +1

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.

Copy link
Contributor

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.

@pwittrock
Copy link
Member Author

@stts what is the typical process to get lazy consensus in this repo?

- **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.
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Member Author

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?

- informer-gen
- lister-gen
- openapi-gen
- set-gen
Copy link
Contributor

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.

Copy link
Member Author

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"
Copy link
Contributor

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.

Copy link
Member Author

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"
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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 ...

Copy link
Member Author

@pwittrock pwittrock Nov 2, 2017

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

Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor

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.")

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

@sttts
Copy link
Contributor

sttts commented Nov 1, 2017

what is the typical process to get lazy consensus in this repo?

I don't think there is a policy for that. I guess in kubernetes/community the proposal process is written down somewhere.

@pwittrock
Copy link
Member Author

Moved to kubernetes/community#1315

@pwittrock pwittrock closed this Nov 1, 2017
@pwittrock
Copy link
Member Author

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.

@sttts
Copy link
Contributor

sttts commented Nov 2, 2017

Left a couple of more comments. WIll switch to the new community PR now.

@pwittrock
Copy link
Member Author

@sttts Addressed comments in the community repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants