-
Notifications
You must be signed in to change notification settings - Fork 218
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
refactor: kind aware codegen tools #2839
base: master
Are you sure you want to change the base?
Conversation
CMDs like: ``` $ go run main.go generate-types \ --service google.cloud.bigquery.analyticshub.v1 \ --proto-source-path ../proto-to-mapper/build/googleapis.pb \ --output-api $REPO_ROOT/apis \ --kind BigQueryAnalyticsHubDataExchange \ --proto-resource DataExchange \ --api-version "bigqueryanalyticshub.cnrm.cloud.google.com/v1alpha1" ``` and ``` $ go run main.go generate-types \ --service google.cloud.bigquery.analyticshub.v1 \ --proto-source-path ../proto-to-mapper/build/googleapis.pb \ --output-api $REPO_ROOT/apis \ --kind BigQueryAnalyticsHubListing \ --proto-resource Listing \ --api-version "bigqueryanalyticshub.cnrm.cloud.google.com/v1alpha1" ``` are not going to step onto each other. In the future, we can parse the files and create a shared.go file. Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Note I modified the ast code to keep track of which file a go struct comes from. TODO: - a lot of the "right" mappings are in mapper.generated.go it seems because of a naming issue. I will address that as a follow on. For now, the strucutre is more important. Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
fyi/ cc y'all |
@@ -116,7 +118,7 @@ func (g *TypeGenerator) writeVisitedMessages() { | |||
|
|||
k := generatedFileKey{ | |||
GoPackage: g.goPackage, | |||
FileName: "types.generated.go", | |||
FileName: strings.ToLower(g.goKind) +".types.generated.go", |
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 was under the impression we'd have a single 'types.generated.go' shared across multiple resources. Did I get that wrong?
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.
types.generated.go will get clobbered by the most recent type IIUC. The intent here is to keep these separate and the cmd user can select how they deal with this 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.
types.generated.go will get clobbered by the most recent type IIUC
To fix this issue, can we modify the flags to pass in a list of protos? That way, we can generate all the types for a set of protos in the same API group, instead of just one at a time.
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.
That way, we can generate all the types for a set of protos in the same API group
Or maybe we can pass in just the API group. The issue w a list of protos is what happens, say, 6 months after we added resources A and B. Someone wants to add resource C, they then have to recall to add both resources that came before to their generation cmd which is a bit of a paper cut imo.
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 thought that was the purpose of https://github.com/GoogleCloudPlatform/k8s-config-connector/blob/master/dev/tools/controllerbuilder/generate.sh ? To record what had been run before. And, eventually, we would run it regularly to catch field updates / changes.
I would prefer that we avoid prepending the resource kind to the auto-generated types and mappings. In my view, it isn't necessary, and it could also prevent the command from being rerun on existing SciFi resources. I think ideally the tool should generate the following:
|
I've reworked the 3 cmds (generate-types, generate-mapper and add) to be kind aware. The new structure for
apis
:and for the
controller
:NOTES:
mapper.generated.go
is a catch all but ideally all relevant mappings should be in each file; I will follow on about this but for now the structure is more importantshared_types.go
is more to share the direction that we are going in; the tooling doesn't support this yet but I/ we can explore that out of band.Reviewers: