Skip to content

Commit 2c6daa4

Browse files
authored
Merge pull request kubernetes#125162 from sttts/sttts-code-generator-core-group
code-generator/client-gen: decouple core group from package name 'api'
2 parents 742b2f7 + ac3b764 commit 2c6daa4

File tree

101 files changed

+4842
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+4842
-76
lines changed

api/api-rules/codegen_violation_exceptions.list

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,StatusCause
77
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Time,Time
88
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentEncoding
99
API rule violation: names_match,k8s.io/apimachinery/pkg/runtime,Unknown,ContentType
10-
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/example/v1,TestTypeStatus,Blah
11-
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/example2/v1,TestTypeStatus,Blah
12-
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/example3.io/v1,TestTypeStatus,Blah

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/HyphenGroup/apis/example/v1/types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ type TestTypeList struct {
4343
}
4444

4545
type TestTypeStatus struct {
46-
Blah string
46+
Blah string `json:"blah"`
4747
}
4848

4949
// +genclient:nonNamespaced
5050
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
5151

5252
type ClusterTestTypeList struct {
53-
metav1.TypeMeta
54-
metav1.ListMeta
55-
Items []ClusterTestType
53+
metav1.TypeMeta `json:",inline"`
54+
metav1.ListMeta `json:"metadata,omitempty"`
55+
Items []ClusterTestType `json:"items"`
5656
}
5757

5858
// +genclient
@@ -70,5 +70,5 @@ type ClusterTestType struct {
7070
}
7171

7272
type ClusterTestTypeStatus struct {
73-
Blah string
73+
Blah string `json:"blah"`
7474
}

staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttype.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttypestatus.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtype.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)