Skip to content

Commit

Permalink
Merge pull request kubernetes#125162 from sttts/sttts-code-generator-…
Browse files Browse the repository at this point in the history
…core-group

code-generator/client-gen: decouple core group from package name 'api'
  • Loading branch information
k8s-ci-robot committed Jun 27, 2024
2 parents 742b2f7 + ac3b764 commit 2c6daa4
Show file tree
Hide file tree
Showing 101 changed files with 4,842 additions and 76 deletions.
3 changes: 0 additions & 3 deletions api/api-rules/codegen_violation_exceptions.list
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ 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/example/v1,TestTypeStatus,Blah
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/example2/v1,TestTypeStatus,Blah
API rule violation: names_match,k8s.io/code-generator/examples/apiserver/apis/example3.io/v1,TestTypeStatus,Blah
1 change: 1 addition & 0 deletions pkg/apis/core/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

// +k8s:deepcopy-gen=package
// +groupName=

// Package core contains the latest (or "internal") version of the
// Kubernetes API objects. This is the API objects as represented in memory.
Expand Down
1 change: 1 addition & 0 deletions staging/src/k8s.io/api/core/v1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
// +k8s:deepcopy-gen=package
// +k8s:protobuf-gen=package
// +k8s:prerelease-lifecycle-gen=true
// +groupName=

// Package v1 is the v1 version of the core API.
package v1 // import "k8s.io/api/core/v1"
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func TestGVPackageFlag(t *testing.T) {
{
args: []string{"api/v1", "api"},
expectedGroups: []types.GroupVersions{
{PackageName: "core", Group: types.Group("api"), Versions: []types.PackageVersion{
{Version: "v1", Package: "core/v1"},
{Version: "", Package: "core"},
{PackageName: "api", Group: types.Group("api"), Versions: []types.PackageVersion{
{Version: "v1", Package: "api/v1"},
{Version: "", Package: "api"},
}},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
if group == "core" {
return `"/api"`
}
return `"` + g.apiPath + `"`
}

groupName := g.group
if g.group == "core" {
groupName = ""
}
// allow user to define a group name that's different from the one parsed from the directory.
p := c.Universe.Package(g.inputPackage)
groupName := g.group
if override := gengo.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil {
groupName = override[0]
}

apiPath := `"` + g.apiPath + `"`
if groupName == "" {
apiPath = `"/api"`
}

m := map[string]interface{}{
"group": g.group,
"version": g.version,
"groupName": groupName,
"GroupGoName": g.groupGoName,
"Version": namer.IC(g.version),
"types": g.types,
"apiPath": apiPath(g.group),
"apiPath": apiPath,
"schemaGroupVersion": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersion"}),
"runtimeAPIVersionInternal": c.Universe.Variable(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "APIVersionInternal"}),
"restConfig": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Config"}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (g Group) String() string {
}

func (g Group) NonEmpty() string {
if g == "api" {
if g == "" {
return "core"
}
return string(g)
Expand Down Expand Up @@ -76,7 +76,7 @@ type GroupVersionKind struct {
}

func (gv GroupVersion) ToAPIVersion() string {
if len(gv.Group) > 0 && gv.Group.NonEmpty() != "core" {
if len(gv.Group) > 0 && gv.Group != "" {
return gv.Group.String() + "/" + gv.Version.String()
} else {
return gv.Version.String()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ type TestTypeList struct {
}

type TestTypeStatus struct {
Blah string
Blah string `json:"blah"`
}

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

type ClusterTestTypeList struct {
metav1.TypeMeta
metav1.ListMeta
Items []ClusterTestType
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterTestType `json:"items"`
}

// +genclient
Expand All @@ -70,5 +70,5 @@ type ClusterTestType struct {
}

type ClusterTestTypeStatus struct {
Blah string
Blah string `json:"blah"`
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ type TestTypeList struct {
}

type TestTypeStatus struct {
Blah string
Blah string `json:"blah"`
}

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

type ClusterTestTypeList struct {
metav1.TypeMeta
metav1.ListMeta
Items []ClusterTestType
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterTestType `json:"items"`
}

// +genclient
Expand All @@ -71,5 +72,5 @@ type ClusterTestType struct {
}

type ClusterTestTypeStatus struct {
Blah string
Blah string `json:"blah"`
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2c6daa4

Please sign in to comment.