-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
code-generator/client-gen: decouple core group from package name 'api' #125162
code-generator/client-gen: decouple core group from package name 'api' #125162
Conversation
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
/triage accepted |
c27b22b
to
4186e8c
Compare
@@ -7,6 +7,7 @@ API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,StatusCause | |||
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Time,Time | |||
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentEncoding | |||
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentType | |||
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/core/v1,TestTypeStatus,Blah |
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 can't tell if this is intentional (ie. the lack of a JSON name matters to the test) or just because we are too lazy to fix these?
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.
probably lazy and good cargo culting of the broken example. Let me check.
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.
staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go
Show resolved
Hide resolved
e3f6314
to
2edb86b
Compare
I can confirm that this PR allows me to generate applyconfiguration and clientset in https://github.com/kubernetes-sigs/cluster-api-provider-openstack. The gen_client invocation I tested is:
That's slightly different to the example in the description as the input argument is the project root rather than the output directory. |
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.
Thanks!
/lgtm
/approve
@@ -71,31 +71,25 @@ func (g *genGroup) Imports(c *generator.Context) (imports []string) { | |||
func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error { | |||
sw := generator.NewSnippetWriter(w, c, "$", "$") | |||
|
|||
apiPath := func(group string) string { |
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 had to backtrack to find where group is being set to "core" - Group.NonEmpty()
says:
func (g Group) NonEmpty() string {
if g == "api" {
return "core"
}
return string(g)
}
So where does "api" come from? I guess that comes from the filesystem layout of the legacy group.
Do you think it would make sense to move legacy code or somehow "normalize" it so these weird special cases go away?
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 "api"
is now gone, replaced with ""
. Core is still hardcoded. But that's just a symbol for the go types.
LGTM label has been added. Git tree hash: d4fb258aa250e1447a6fe1ffcbbec486894bfb94
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sttts, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
/hold |
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
2edb86b
to
ac3b764
Compare
I've retested this locally. I am still able to use this to generate a clientset in cluster-api-provider-openstack. /lgtm |
LGTM label has been added. Git tree hash: b25e6e60cf126c99c8677963d1e740dc1543ad65
|
Just wanted to throw a thank you to everyone who worked on this, it is appreciated! 🫡 |
@sttts was this last push just a rebase? I can't discern what relevant changes are in the diff? /lgtm |
Yes, rebase and codegen, some go docs changed. |
/hold cancel |
What type of PR is this?
/kind bug
What this PR does / why we need it:
client-gen didn't work with
api/v1
-like directory structures. This PR removes special casing of theapi
package name, and move that logic into the// +groupName=
marker.This PR also adds an example for a single API group to ensure the generated code is correct. Compare how client-gen is launched to support this single group:
Which issue(s) this PR fixes:
Fixes kubernetes/code-generator#167
Special notes for your reviewer:
Note that there are no changes to generated client-go code for the legacy core group.
Also note that the generated client for the "single" example uses
config.APIPath = "/apis"
, not/api
as the legacy core group client (this would have been the case before this PR).Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: