Skip to content

Commit dc4fce6

Browse files
committed
Add missing imports in register-gen
Due to a recent change in k8s.io/gengo/v2, the register-gen is missing 2 imports.The imports were previously auto inserted during the code generation by k8s.io/gengo/v2. Now, instead, they are directly imported by the register-gen. An output_tests has been added to register-gen. This generates an example, which would have been invalid with these changes. Signed-off-by: Lionel Jouin <[email protected]>
1 parent ef54ac8 commit dc4fce6

File tree

8 files changed

+194
-9
lines changed

8 files changed

+194
-9
lines changed

staging/src/k8s.io/code-generator/cmd/register-gen/generators/register_external.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ func (g *registerExternalGenerator) Finalize(context *generator.Context, w io.Wr
6161

6262
sw := generator.NewSnippetWriter(w, context, "$", "$")
6363
m := map[string]interface{}{
64-
"groupName": g.gv.Group,
65-
"version": g.gv.Version,
66-
"types": typesToGenerateOnlyNames,
67-
"addToGroupVersion": context.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "AddToGroupVersion"}),
68-
"groupVersion": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GroupVersion"}),
64+
"groupName": g.gv.Group,
65+
"version": g.gv.Version,
66+
"types": typesToGenerateOnlyNames,
67+
"addToGroupVersion": context.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "AddToGroupVersion"}),
68+
"groupVersion": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GroupVersion"}),
69+
"schemaGroupVersion": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersion"}),
70+
"schemaGroupResource": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupResource"}),
71+
"scheme": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "Scheme"}),
72+
"schemeBuilder": context.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "SchemeBuilder"}),
6973
}
7074
sw.Do(registerExternalTypesTemplate, m)
7175
return sw.Error()
@@ -80,16 +84,16 @@ var GroupVersion = $.groupVersion|raw${Group: GroupName, Version: "$.version$"}
8084
8185
// SchemeGroupVersion is group version used to register these objects
8286
// Deprecated: use GroupVersion instead.
83-
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "$.version$"}
87+
var SchemeGroupVersion = $.schemaGroupVersion|raw${Group: GroupName, Version: "$.version$"}
8488
8589
// Resource takes an unqualified resource and returns a Group qualified GroupResource
86-
func Resource(resource string) schema.GroupResource {
90+
func Resource(resource string) $.schemaGroupResource|raw$ {
8791
return SchemeGroupVersion.WithResource(resource).GroupResource()
8892
}
8993
9094
var (
9195
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
92-
SchemeBuilder runtime.SchemeBuilder
96+
SchemeBuilder $.schemeBuilder|raw$
9397
localSchemeBuilder = &SchemeBuilder
9498
// Deprecated: use Install instead
9599
AddToScheme = localSchemeBuilder.AddToScheme
@@ -104,7 +108,7 @@ func init() {
104108
}
105109
106110
// Adds the list of known types to Scheme.
107-
func addKnownTypes(scheme *runtime.Scheme) error {
111+
func addKnownTypes(scheme *$.scheme|raw$) error {
108112
scheme.AddKnownTypes(SchemeGroupVersion,
109113
$range .types -$
110114
&$.${},
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//go:build !ignore_autogenerated
2+
3+
/*
4+
Copyright 2024 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
//go:generate go run k8s.io/code-generator/cmd/register-gen --output-file zz_generated.register.go --go-header-file=../../../examples/hack/boilerplate.go.txt k8s.io/code-generator/cmd/register-gen/output_tests/...
20+
package outputtests
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +groupName=simpletype.foo.bar
18+
package simpletype
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package simpletype
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime"
21+
)
22+
23+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
24+
func (in *SimpleType) DeepCopyInto(out *SimpleType) {
25+
*out = *in
26+
}
27+
28+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Inner.
29+
func (in *SimpleType) DeepCopy() *SimpleType {
30+
if in == nil {
31+
return nil
32+
}
33+
out := new(SimpleType)
34+
in.DeepCopyInto(out)
35+
return out
36+
}
37+
38+
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
39+
func (in *SimpleType) DeepCopyObject() runtime.Object {
40+
if c := in.DeepCopy(); c != nil {
41+
return c
42+
}
43+
return nil
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package simpletype
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
type SimpleType struct {
24+
metav1.TypeMeta `json:",inline"`
25+
}

staging/src/k8s.io/code-generator/cmd/register-gen/output_tests/simpletype/zz_generated.register.go

Lines changed: 69 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/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ require (
3636
github.com/modern-go/reflect2 v1.0.2 // indirect
3737
github.com/x448/float16 v0.8.4 // indirect
3838
golang.org/x/mod v0.21.0 // indirect
39+
golang.org/x/net v0.30.0 // indirect
3940
golang.org/x/sync v0.10.0 // indirect
4041
golang.org/x/sys v0.28.0 // indirect
4142
golang.org/x/tools v0.26.0 // indirect
4243
google.golang.org/protobuf v1.35.1 // indirect
44+
gopkg.in/inf.v0 v0.9.1 // indirect
4345
gopkg.in/yaml.v3 v3.0.1 // indirect
46+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
4447
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
4548
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
4649
)

staging/src/k8s.io/code-generator/go.sum

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

0 commit comments

Comments
 (0)