Skip to content

Commit 9c99a2d

Browse files
Merge pull request #67 from stevekuznetsov/skuznets/ignore-internal-types
✨ ignore internal types
2 parents 6de96fa + d45db3a commit 9c99a2d

6 files changed

Lines changed: 410 additions & 12 deletions

File tree

examples/pkg/apis/example/doc.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2022 The KCP 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+
// +k8s:deepcopy-gen=package,register
18+
package example

examples/pkg/apis/example/register.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,40 @@ limitations under the License.
1616

1717
package example
1818

19-
const (
20-
GroupName = "example.dev"
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/apimachinery/pkg/runtime/schema"
2123
)
24+
25+
const GroupName = "example.dev"
26+
27+
// SchemeGroupVersion is group version used to register these objects
28+
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}
29+
30+
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
31+
func Kind(kind string) schema.GroupKind {
32+
return SchemeGroupVersion.WithKind(kind).GroupKind()
33+
}
34+
35+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
36+
func Resource(resource string) schema.GroupResource {
37+
return SchemeGroupVersion.WithResource(resource).GroupResource()
38+
}
39+
40+
var (
41+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
42+
AddToScheme = SchemeBuilder.AddToScheme
43+
)
44+
45+
// Adds the list of known types to Scheme.
46+
func addKnownTypes(scheme *runtime.Scheme) error {
47+
scheme.AddKnownTypes(SchemeGroupVersion,
48+
&TestType{},
49+
&TestTypeList{},
50+
&ClusterTestType{},
51+
&ClusterTestTypeList{},
52+
)
53+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
54+
return nil
55+
}

examples/pkg/apis/example/types.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright 2022 The KCP 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 example
18+
19+
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
21+
// +genclient
22+
// +genclient:noStatus
23+
// +genclient:method=CreateField,verb=create,subresource=field,input=Field,result=Field
24+
// +genclient:method=UpdateField,verb=update,subresource=field,input=Field,result=Field
25+
// +genclient:method=GetField,verb=get,subresource=field,result=Field
26+
// TestType is a top-level type. A client is created for it.
27+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
28+
type TestType struct {
29+
metav1.TypeMeta `json:",inline"`
30+
// +optional
31+
metav1.ObjectMeta `json:"metadata,omitempty"`
32+
// +optional
33+
APIGroups []string `json:"apiGroups,omitempty"`
34+
}
35+
36+
// TestTypeList is a top-level list type. The client methods for lists are automatically created.
37+
// You are not supposed to create a separated client for this one.
38+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
39+
type TestTypeList struct {
40+
metav1.TypeMeta `json:",inline"`
41+
metav1.ListMeta `json:"metadata"`
42+
Items []TestType `json:"items"`
43+
}
44+
45+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
46+
type Field struct {
47+
metav1.TypeMeta `json:",inline"`
48+
// Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
49+
// +optional
50+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
51+
Field string `json:"field"`
52+
}
53+
54+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
55+
type FieldList struct {
56+
metav1.TypeMeta `json:",inline"`
57+
metav1.ListMeta `json:"metadata"`
58+
Items []Field `json:"items"`
59+
}
60+
61+
// +genclient
62+
// +genclient:nonNamespaced
63+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
64+
type ClusterTestType struct {
65+
metav1.TypeMeta `json:",inline"`
66+
// +optional
67+
metav1.ObjectMeta `json:"metadata,omitempty"`
68+
// ObjectKind is the type of resource being referenced
69+
ObjectKind string `json:"kind"`
70+
// ObjectName is the name of resource being referenced
71+
ObjectName string `json:"name"`
72+
// +optional
73+
Status ClusterTestTypeStatus `json:"status,omitempty"`
74+
}
75+
76+
type ClusterTestTypeStatus struct {
77+
Blah string `json:"blah,omitempty"`
78+
}
79+
80+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
81+
type ClusterTestTypeList struct {
82+
metav1.TypeMeta `json:",inline"`
83+
metav1.ListMeta `json:"metadata"`
84+
85+
Items []ClusterTestType `json:"items"`
86+
}
87+
88+
// +genclient
89+
// +genclient:noVerbs
90+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
91+
type WithoutVerbType struct {
92+
metav1.TypeMeta `json:",inline"`
93+
// +optional
94+
metav1.ObjectMeta `json:"metadata,omitempty"`
95+
}

examples/pkg/apis/example/zz_generated.deepcopy.go

Lines changed: 227 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)