Skip to content

Commit 6b2f779

Browse files
committed
code-generator/client-gen: decouple core group from package name 'api'
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
1 parent 7e52d34 commit 6b2f779

File tree

7 files changed

+16
-18
lines changed

7 files changed

+16
-18
lines changed

pkg/apis/core/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
// +k8s:deepcopy-gen=package
18+
// +groupName=
1819

1920
// Package core contains the latest (or "internal") version of the
2021
// Kubernetes API objects. This is the API objects as represented in memory.

staging/src/k8s.io/api/core/v1/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
// +k8s:deepcopy-gen=package
1919
// +k8s:protobuf-gen=package
2020
// +k8s:prerelease-lifecycle-gen=true
21+
// +groupName=
2122

2223
// Package v1 is the v1 version of the core API.
2324
package v1 // import "k8s.io/api/core/v1"

staging/src/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ func TestGVPackageFlag(t *testing.T) {
7171
{
7272
args: []string{"api/v1", "api"},
7373
expectedGroups: []types.GroupVersions{
74-
{PackageName: "core", Group: types.Group("api"), Versions: []types.PackageVersion{
75-
{Version: "v1", Package: "core/v1"},
76-
{Version: "", Package: "core"},
74+
{PackageName: "api", Group: types.Group("api"), Versions: []types.PackageVersion{
75+
{Version: "v1", Package: "api/v1"},
76+
{Version: "", Package: "api"},
7777
}},
7878
},
7979
},

staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,25 @@ func (g *genGroup) Imports(c *generator.Context) (imports []string) {
7171
func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
7272
sw := generator.NewSnippetWriter(w, c, "$", "$")
7373

74-
apiPath := func(group string) string {
75-
if group == "core" {
76-
return `"/api"`
77-
}
78-
return `"` + g.apiPath + `"`
79-
}
80-
81-
groupName := g.group
82-
if g.group == "core" {
83-
groupName = ""
84-
}
8574
// allow user to define a group name that's different from the one parsed from the directory.
8675
p := c.Universe.Package(g.inputPackage)
76+
groupName := g.group
8777
if override := gengo.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil {
8878
groupName = override[0]
8979
}
9080

81+
apiPath := `"` + g.apiPath + `"`
82+
if groupName == "" {
83+
apiPath = `"/api"`
84+
}
85+
9186
m := map[string]interface{}{
92-
"group": g.group,
9387
"version": g.version,
9488
"groupName": groupName,
9589
"GroupGoName": g.groupGoName,
9690
"Version": namer.IC(g.version),
9791
"types": g.types,
98-
"apiPath": apiPath(g.group),
92+
"apiPath": apiPath,
9993
"schemaGroupVersion": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersion"}),
10094
"runtimeAPIVersionInternal": c.Universe.Variable(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "APIVersionInternal"}),
10195
"restConfig": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Config"}),

staging/src/k8s.io/code-generator/cmd/client-gen/types/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (g Group) String() string {
4242
}
4343

4444
func (g Group) NonEmpty() string {
45-
if g == "api" {
45+
if g == "" {
4646
return "core"
4747
}
4848
return string(g)
@@ -76,7 +76,7 @@ type GroupVersionKind struct {
7676
}
7777

7878
func (gv GroupVersion) ToAPIVersion() string {
79-
if len(gv.Group) > 0 && gv.Group.NonEmpty() != "core" {
79+
if len(gv.Group) > 0 && gv.Group != "" {
8080
return gv.Group.String() + "/" + gv.Version.String()
8181
} else {
8282
return gv.Version.String()

staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ limitations under the License.
1515
*/
1616

1717
// +k8s:deepcopy-gen=package
18+
// +groupName=
1819

1920
package core // import "k8s.io/code-generator/examples/apiserver/apis/core"

staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ limitations under the License.
1818
// +k8s:deepcopy-gen=package
1919
// +k8s:defaulter-gen=TypeMeta
2020
// +k8s:conversion-gen=k8s.io/code-generator/examples/apiserver/apis/core
21+
// +groupName=
2122

2223
package v1 // import "k8s.io/code-generator/examples/apiserver/apis/core/v1"

0 commit comments

Comments
 (0)