From 7e52d34852125a05de618b0f61ec3d463b1160a5 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 28 May 2024 09:05:30 +0200 Subject: [PATCH 1/5] code-generator/client-gen: add example with core group Signed-off-by: Dr. Stefan Schimanski --- .../codegen_violation_exceptions.list | 1 + .../examples/apiserver/apis/core/doc.go | 19 ++ .../apiserver/apis/core/install/install.go | 33 +++ .../examples/apiserver/apis/core/register.go | 45 ++++ .../examples/apiserver/apis/core/types.go | 44 ++++ .../examples/apiserver/apis/core/v1/doc.go | 22 ++ .../apiserver/apis/core/v1/register.go | 59 ++++++ .../examples/apiserver/apis/core/v1/types.go | 47 +++++ .../apis/core/v1/zz_generated.conversion.go | 138 +++++++++++++ .../apis/core/v1/zz_generated.deepcopy.go | 102 +++++++++ .../apis/core/v1/zz_generated.defaults.go | 33 +++ .../apis/core/zz_generated.deepcopy.go | 102 +++++++++ .../clientset/versioned/clientset.go | 13 ++ .../versioned/fake/clientset_generated.go | 7 + .../clientset/versioned/fake/register.go | 2 + .../clientset/versioned/scheme/register.go | 2 + .../versioned/typed/core/v1/core_client.go | 107 ++++++++++ .../clientset/versioned/typed/core/v1/doc.go | 20 ++ .../versioned/typed/core/v1/fake/doc.go | 20 ++ .../typed/core/v1/fake/fake_core_client.go | 40 ++++ .../typed/core/v1/fake/fake_testtype.go | 141 +++++++++++++ .../typed/core/v1/generated_expansion.go | 21 ++ .../versioned/typed/core/v1/testtype.go | 195 ++++++++++++++++++ .../externalversions/core/interface.go | 46 +++++ .../externalversions/core/v1/interface.go | 45 ++++ .../externalversions/core/v1/testtype.go | 90 ++++++++ .../informers/externalversions/factory.go | 6 + .../informers/externalversions/generic.go | 9 +- .../listers/core/v1/expansion_generated.go | 27 +++ .../apiserver/listers/core/v1/testtype.go | 99 +++++++++ .../apiserver/openapi/zz_generated.openapi.go | 113 ++++++++++ 31 files changed, 1646 insertions(+), 2 deletions(-) create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/install/install.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/register.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/types.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/register.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/types.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.conversion.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.deepcopy.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.defaults.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/apis/core/zz_generated.deepcopy.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/core_client.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_core_client.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/generated_expansion.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/testtype.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/interface.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1/interface.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1/testtype.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/expansion_generated.go create mode 100644 staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/testtype.go diff --git a/api/api-rules/codegen_violation_exceptions.list b/api/api-rules/codegen_violation_exceptions.list index d16e61db5c9..257872812c7 100644 --- a/api/api-rules/codegen_violation_exceptions.list +++ b/api/api-rules/codegen_violation_exceptions.list @@ -7,6 +7,7 @@ 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/core/v1,TestTypeStatus,Blah 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 diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go new file mode 100644 index 00000000000..bc03c4655e0 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go @@ -0,0 +1,19 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +package core // import "k8s.io/code-generator/examples/apiserver/apis/core" diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/install/install.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/install/install.go new file mode 100644 index 00000000000..c1b6d2d5c41 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/install/install.go @@ -0,0 +1,33 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package install installs the experimental API group, making it available as +// an option to all of the API encoding/decoding machinery. +package install + +import ( + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/code-generator/examples/apiserver/apis/core" + "k8s.io/code-generator/examples/apiserver/apis/core/v1" +) + +// Install registers the API group and adds types to a scheme +func Install(scheme *runtime.Scheme) { + utilruntime.Must(core.AddToScheme(scheme)) + utilruntime.Must(v1.AddToScheme(scheme)) + utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion)) +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/register.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/register.go new file mode 100644 index 00000000000..9e2cd292a94 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/register.go @@ -0,0 +1,45 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package core + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var SchemeGroupVersion = schema.GroupVersion{Version: runtime.APIVersionInternal} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &TestType{}, + &TestTypeList{}, + ) + + scheme.AddKnownTypes(SchemeGroupVersion) + return nil +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/types.go new file mode 100644 index 00000000000..bd725cd6ca5 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/types.go @@ -0,0 +1,44 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package core + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// TestType is a top-level type. A client is created for it. +type TestType struct { + metav1.TypeMeta + metav1.ObjectMeta + Status TestTypeStatus +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// TestTypeList is a top-level list type. The client methods for lists are automatically created. +// You are not supposed to create a separated client for this one. +type TestTypeList struct { + metav1.TypeMeta + metav1.ListMeta + + Items []TestType +} + +type TestTypeStatus struct { + Blah string +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go new file mode 100644 index 00000000000..6af4ff739ce --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go @@ -0,0 +1,22 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package +// +k8s:defaulter-gen=TypeMeta +// +k8s:conversion-gen=k8s.io/code-generator/examples/apiserver/apis/core + +package v1 // import "k8s.io/code-generator/examples/apiserver/apis/core/v1" diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/register.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/register.go new file mode 100644 index 00000000000..0bfc241a424 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/register.go @@ -0,0 +1,59 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var SchemeGroupVersion = schema.GroupVersion{Group: "example.apiserver.code-generator.k8s.io", Version: "v1"} + +var ( + // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api. + // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. + SchemeBuilder runtime.SchemeBuilder + localSchemeBuilder = &SchemeBuilder + AddToScheme = localSchemeBuilder.AddToScheme +) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(addKnownTypes) +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &TestType{}, + &TestTypeList{}, + ) + + scheme.AddKnownTypes(SchemeGroupVersion, + &metav1.Status{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/types.go new file mode 100644 index 00000000000..819ad21a5f8 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/types.go @@ -0,0 +1,47 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// TestType is a top-level type. A client is created for it. +type TestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // +optional + Status TestTypeStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// TestTypeList is a top-level list type. The client methods for lists are automatically created. +// You are not supposed to create a separated client for this one. +type TestTypeList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []TestType `json:"items"` +} + +type TestTypeStatus struct { + Blah string +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.conversion.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.conversion.go new file mode 100644 index 00000000000..59219a1b3a2 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.conversion.go @@ -0,0 +1,138 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by conversion-gen. DO NOT EDIT. + +package v1 + +import ( + unsafe "unsafe" + + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" + core "k8s.io/code-generator/examples/apiserver/apis/core" +) + +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + +// RegisterConversions adds conversion functions to the given scheme. +// Public to allow building arbitrary schemes. +func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*TestType)(nil), (*core.TestType)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1_TestType_To_core_TestType(a.(*TestType), b.(*core.TestType), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*core.TestType)(nil), (*TestType)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_core_TestType_To_v1_TestType(a.(*core.TestType), b.(*TestType), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*TestTypeList)(nil), (*core.TestTypeList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1_TestTypeList_To_core_TestTypeList(a.(*TestTypeList), b.(*core.TestTypeList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*core.TestTypeList)(nil), (*TestTypeList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_core_TestTypeList_To_v1_TestTypeList(a.(*core.TestTypeList), b.(*TestTypeList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*TestTypeStatus)(nil), (*core.TestTypeStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1_TestTypeStatus_To_core_TestTypeStatus(a.(*TestTypeStatus), b.(*core.TestTypeStatus), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*core.TestTypeStatus)(nil), (*TestTypeStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_core_TestTypeStatus_To_v1_TestTypeStatus(a.(*core.TestTypeStatus), b.(*TestTypeStatus), scope) + }); err != nil { + return err + } + return nil +} + +func autoConvert_v1_TestType_To_core_TestType(in *TestType, out *core.TestType, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1_TestTypeStatus_To_core_TestTypeStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_v1_TestType_To_core_TestType is an autogenerated conversion function. +func Convert_v1_TestType_To_core_TestType(in *TestType, out *core.TestType, s conversion.Scope) error { + return autoConvert_v1_TestType_To_core_TestType(in, out, s) +} + +func autoConvert_core_TestType_To_v1_TestType(in *core.TestType, out *TestType, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_core_TestTypeStatus_To_v1_TestTypeStatus(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_core_TestType_To_v1_TestType is an autogenerated conversion function. +func Convert_core_TestType_To_v1_TestType(in *core.TestType, out *TestType, s conversion.Scope) error { + return autoConvert_core_TestType_To_v1_TestType(in, out, s) +} + +func autoConvert_v1_TestTypeList_To_core_TestTypeList(in *TestTypeList, out *core.TestTypeList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]core.TestType)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_v1_TestTypeList_To_core_TestTypeList is an autogenerated conversion function. +func Convert_v1_TestTypeList_To_core_TestTypeList(in *TestTypeList, out *core.TestTypeList, s conversion.Scope) error { + return autoConvert_v1_TestTypeList_To_core_TestTypeList(in, out, s) +} + +func autoConvert_core_TestTypeList_To_v1_TestTypeList(in *core.TestTypeList, out *TestTypeList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]TestType)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_core_TestTypeList_To_v1_TestTypeList is an autogenerated conversion function. +func Convert_core_TestTypeList_To_v1_TestTypeList(in *core.TestTypeList, out *TestTypeList, s conversion.Scope) error { + return autoConvert_core_TestTypeList_To_v1_TestTypeList(in, out, s) +} + +func autoConvert_v1_TestTypeStatus_To_core_TestTypeStatus(in *TestTypeStatus, out *core.TestTypeStatus, s conversion.Scope) error { + out.Blah = in.Blah + return nil +} + +// Convert_v1_TestTypeStatus_To_core_TestTypeStatus is an autogenerated conversion function. +func Convert_v1_TestTypeStatus_To_core_TestTypeStatus(in *TestTypeStatus, out *core.TestTypeStatus, s conversion.Scope) error { + return autoConvert_v1_TestTypeStatus_To_core_TestTypeStatus(in, out, s) +} + +func autoConvert_core_TestTypeStatus_To_v1_TestTypeStatus(in *core.TestTypeStatus, out *TestTypeStatus, s conversion.Scope) error { + out.Blah = in.Blah + return nil +} + +// Convert_core_TestTypeStatus_To_v1_TestTypeStatus is an autogenerated conversion function. +func Convert_core_TestTypeStatus_To_v1_TestTypeStatus(in *core.TestTypeStatus, out *TestTypeStatus, s conversion.Scope) error { + return autoConvert_core_TestTypeStatus_To_v1_TestTypeStatus(in, out, s) +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.deepcopy.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..d87f706f770 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.deepcopy.go @@ -0,0 +1,102 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestType) DeepCopyInto(out *TestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. +func (in *TestType) DeepCopy() *TestType { + if in == nil { + return nil + } + out := new(TestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestType) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]TestType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. +func (in *TestTypeList) DeepCopy() *TestTypeList { + if in == nil { + return nil + } + out := new(TestTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestTypeList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestTypeStatus) DeepCopyInto(out *TestTypeStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeStatus. +func (in *TestTypeStatus) DeepCopy() *TestTypeStatus { + if in == nil { + return nil + } + out := new(TestTypeStatus) + in.DeepCopyInto(out) + return out +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.defaults.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.defaults.go new file mode 100644 index 00000000000..dac177e93bd --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/zz_generated.defaults.go @@ -0,0 +1,33 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by defaulter-gen. DO NOT EDIT. + +package v1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + return nil +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/zz_generated.deepcopy.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/zz_generated.deepcopy.go new file mode 100644 index 00000000000..4e59542113e --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/zz_generated.deepcopy.go @@ -0,0 +1,102 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package core + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestType) DeepCopyInto(out *TestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. +func (in *TestType) DeepCopy() *TestType { + if in == nil { + return nil + } + out := new(TestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestType) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]TestType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. +func (in *TestTypeList) DeepCopy() *TestTypeList { + if in == nil { + return nil + } + out := new(TestTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestTypeList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestTypeStatus) DeepCopyInto(out *TestTypeStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeStatus. +func (in *TestTypeStatus) DeepCopy() *TestTypeStatus { + if in == nil { + return nil + } + out := new(TestTypeStatus) + in.DeepCopyInto(out) + return out +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/clientset.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/clientset.go index 76a6efd3574..82c7e2e3d9a 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/clientset.go @@ -25,6 +25,7 @@ import ( discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" + corev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1" examplev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example/v1" secondexamplev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example2/v1" thirdexamplev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example3.io/v1" @@ -32,6 +33,7 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface + CoreV1() corev1.CoreV1Interface ExampleV1() examplev1.ExampleV1Interface SecondExampleV1() secondexamplev1.SecondExampleV1Interface ThirdExampleV1() thirdexamplev1.ThirdExampleV1Interface @@ -40,11 +42,17 @@ type Interface interface { // Clientset contains the clients for groups. type Clientset struct { *discovery.DiscoveryClient + coreV1 *corev1.CoreV1Client exampleV1 *examplev1.ExampleV1Client secondExampleV1 *secondexamplev1.SecondExampleV1Client thirdExampleV1 *thirdexamplev1.ThirdExampleV1Client } +// CoreV1 retrieves the CoreV1Client +func (c *Clientset) CoreV1() corev1.CoreV1Interface { + return c.coreV1 +} + // ExampleV1 retrieves the ExampleV1Client func (c *Clientset) ExampleV1() examplev1.ExampleV1Interface { return c.exampleV1 @@ -104,6 +112,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, var cs Clientset var err error + cs.coreV1, err = corev1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -137,6 +149,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { // New creates a new Clientset for the given RESTClient. func New(c rest.Interface) *Clientset { var cs Clientset + cs.coreV1 = corev1.New(c) cs.exampleV1 = examplev1.New(c) cs.secondExampleV1 = secondexamplev1.New(c) cs.thirdExampleV1 = thirdexamplev1.New(c) diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/fake/clientset_generated.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/fake/clientset_generated.go index df6e75d986a..2e6319c46bf 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/fake/clientset_generated.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/fake/clientset_generated.go @@ -25,6 +25,8 @@ import ( fakediscovery "k8s.io/client-go/discovery/fake" "k8s.io/client-go/testing" clientset "k8s.io/code-generator/examples/apiserver/clientset/versioned" + corev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1" + fakecorev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake" examplev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example/v1" fakeexamplev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example/v1/fake" secondexamplev1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/example2/v1" @@ -87,6 +89,11 @@ var ( _ testing.FakeClient = &Clientset{} ) +// CoreV1 retrieves the CoreV1Client +func (c *Clientset) CoreV1() corev1.CoreV1Interface { + return &fakecorev1.FakeCoreV1{Fake: &c.Fake} +} + // ExampleV1 retrieves the ExampleV1Client func (c *Clientset) ExampleV1() examplev1.ExampleV1Interface { return &fakeexamplev1.FakeExampleV1{Fake: &c.Fake} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/fake/register.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/fake/register.go index ee077eb0cd8..c2a38a9fc86 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/fake/register.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/fake/register.go @@ -24,6 +24,7 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" serializer "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + corev1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" examplev1 "k8s.io/code-generator/examples/apiserver/apis/example/v1" secondexamplev1 "k8s.io/code-generator/examples/apiserver/apis/example2/v1" thirdexamplev1 "k8s.io/code-generator/examples/apiserver/apis/example3.io/v1" @@ -33,6 +34,7 @@ var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ + corev1.AddToScheme, examplev1.AddToScheme, secondexamplev1.AddToScheme, thirdexamplev1.AddToScheme, diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/scheme/register.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/scheme/register.go index 851b918b313..1ea712906ce 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/scheme/register.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/scheme/register.go @@ -24,6 +24,7 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" serializer "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + corev1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" examplev1 "k8s.io/code-generator/examples/apiserver/apis/example/v1" secondexamplev1 "k8s.io/code-generator/examples/apiserver/apis/example2/v1" thirdexamplev1 "k8s.io/code-generator/examples/apiserver/apis/example3.io/v1" @@ -33,6 +34,7 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ + corev1.AddToScheme, examplev1.AddToScheme, secondexamplev1.AddToScheme, thirdexamplev1.AddToScheme, diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/core_client.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/core_client.go new file mode 100644 index 00000000000..e81f6f066f3 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/core_client.go @@ -0,0 +1,107 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + "net/http" + + rest "k8s.io/client-go/rest" + v1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" + "k8s.io/code-generator/examples/apiserver/clientset/versioned/scheme" +) + +type CoreV1Interface interface { + RESTClient() rest.Interface + TestTypesGetter +} + +// CoreV1Client is used to interact with features provided by the group. +type CoreV1Client struct { + restClient rest.Interface +} + +func (c *CoreV1Client) TestTypes(namespace string) TestTypeInterface { + return newTestTypes(c, namespace) +} + +// NewForConfig creates a new CoreV1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*CoreV1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new CoreV1Client for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*CoreV1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &CoreV1Client{client}, nil +} + +// NewForConfigOrDie creates a new CoreV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *CoreV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new CoreV1Client for the given RESTClient. +func New(c rest.Interface) *CoreV1Client { + return &CoreV1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/api" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *CoreV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/doc.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/doc.go new file mode 100644 index 00000000000..3af5d054f10 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/doc.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/doc.go new file mode 100644 index 00000000000..16f44399065 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_core_client.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_core_client.go new file mode 100644 index 00000000000..2cdcda7879d --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_core_client.go @@ -0,0 +1,40 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + v1 "k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1" +) + +type FakeCoreV1 struct { + *testing.Fake +} + +func (c *FakeCoreV1) TestTypes(namespace string) v1.TestTypeInterface { + return &FakeTestTypes{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeCoreV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go new file mode 100644 index 00000000000..6beefaffa90 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go @@ -0,0 +1,141 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" +) + +// FakeTestTypes implements TestTypeInterface +type FakeTestTypes struct { + Fake *FakeCoreV1 + ns string +} + +var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") + +var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") + +// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. +func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &v1.TestTypeList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} + for _, item := range obj.(*v1.TestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested testTypes. +func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) + +} + +// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(testtypesResource, "status", c.ns, testType), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// Delete takes name of the testType and deletes it. Returns an error if one occurs. +func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) + return err +} + +// Patch applies the patch and returns the patched testType. +func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/generated_expansion.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/generated_expansion.go new file mode 100644 index 00000000000..d513810d0d7 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/generated_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +type TestTypeExpansion interface{} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/testtype.go new file mode 100644 index 00000000000..a04cd3dd2aa --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/testtype.go @@ -0,0 +1,195 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" + scheme "k8s.io/code-generator/examples/apiserver/clientset/versioned/scheme" +) + +// TestTypesGetter has a method to return a TestTypeInterface. +// A group's client should implement this interface. +type TestTypesGetter interface { + TestTypes(namespace string) TestTypeInterface +} + +// TestTypeInterface has methods to work with TestType resources. +type TestTypeInterface interface { + Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) + Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.TestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) + TestTypeExpansion +} + +// testTypes implements TestTypeInterface +type testTypes struct { + client rest.Interface + ns string +} + +// newTestTypes returns a TestTypes +func newTestTypes(c *CoreV1Client, namespace string) *testTypes { + return &testTypes{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. +func (c *testTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Get(). + Namespace(c.ns). + Resource("testtypes"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *testTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1.TestTypeList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("testtypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested testTypes. +func (c *testTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("testtypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *testTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Post(). + Namespace(c.ns). + Resource("testtypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testType). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *testTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Put(). + Namespace(c.ns). + Resource("testtypes"). + Name(testType.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testType). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *testTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Put(). + Namespace(c.ns). + Resource("testtypes"). + Name(testType.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testType). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the testType and deletes it. Returns an error if one occurs. +func (c *testTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("testtypes"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *testTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("testtypes"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched testType. +func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("testtypes"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/interface.go b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/interface.go new file mode 100644 index 00000000000..56a1bc41a6b --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/interface.go @@ -0,0 +1,46 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package core + +import ( + v1 "k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1" + internalinterfaces "k8s.io/code-generator/examples/apiserver/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1/interface.go b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1/interface.go new file mode 100644 index 00000000000..32180c91f8c --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1/interface.go @@ -0,0 +1,45 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "k8s.io/code-generator/examples/apiserver/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// TestTypes returns a TestTypeInformer. +func (v *version) TestTypes() TestTypeInformer { + return &testTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1/testtype.go new file mode 100644 index 00000000000..01ddbd8e849 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/core/v1/testtype.go @@ -0,0 +1,90 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + time "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + corev1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" + versioned "k8s.io/code-generator/examples/apiserver/clientset/versioned" + internalinterfaces "k8s.io/code-generator/examples/apiserver/informers/externalversions/internalinterfaces" + v1 "k8s.io/code-generator/examples/apiserver/listers/core/v1" +) + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.TestTypeLister +} + +type testTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CoreV1().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CoreV1().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &corev1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&corev1.TestType{}, f.defaultInformer) +} + +func (f *testTypeInformer) Lister() v1.TestTypeLister { + return v1.NewTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go index 47bdaeb6027..a07237c90e4 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/factory.go @@ -28,6 +28,7 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" versioned "k8s.io/code-generator/examples/apiserver/clientset/versioned" + core "k8s.io/code-generator/examples/apiserver/informers/externalversions/core" example "k8s.io/code-generator/examples/apiserver/informers/externalversions/example" example2 "k8s.io/code-generator/examples/apiserver/informers/externalversions/example2" example3io "k8s.io/code-generator/examples/apiserver/informers/externalversions/example3.io" @@ -255,11 +256,16 @@ type SharedInformerFactory interface { // client. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer + Core() core.Interface Example() example.Interface SecondExample() example2.Interface ThirdExample() example3io.Interface } +func (f *sharedInformerFactory) Core() core.Interface { + return core.New(f, f.namespace, f.tweakListOptions) +} + func (f *sharedInformerFactory) Example() example.Interface { return example.New(f, f.namespace, f.tweakListOptions) } diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/generic.go b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/generic.go index 987ae5f8d90..ae51fbbf2cd 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/generic.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/informers/externalversions/generic.go @@ -23,7 +23,8 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" - v1 "k8s.io/code-generator/examples/apiserver/apis/example/v1" + v1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" + examplev1 "k8s.io/code-generator/examples/apiserver/apis/example/v1" example2v1 "k8s.io/code-generator/examples/apiserver/apis/example2/v1" example3iov1 "k8s.io/code-generator/examples/apiserver/apis/example3.io/v1" ) @@ -54,8 +55,12 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=example.apiserver.code-generator.k8s.io, Version=v1 + // Group=core, Version=v1 case v1.SchemeGroupVersion.WithResource("testtypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Core().V1().TestTypes().Informer()}, nil + + // Group=example.apiserver.code-generator.k8s.io, Version=v1 + case examplev1.SchemeGroupVersion.WithResource("testtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil // Group=example.dots.apiserver.code-generator.k8s.io, Version=v1 diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/expansion_generated.go b/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/expansion_generated.go new file mode 100644 index 00000000000..0192e05f0d1 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/expansion_generated.go @@ -0,0 +1,27 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/testtype.go new file mode 100644 index 00000000000..b2b2dc47644 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/testtype.go @@ -0,0 +1,99 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" +) + +// TestTypeLister helps list TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.TestType, err error) + // TestTypes returns an object that can list and get TestTypes. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// testTypeLister implements the TestTypeLister interface. +type testTypeLister struct { + indexer cache.Indexer +} + +// NewTestTypeLister returns a new TestTypeLister. +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{indexer: indexer} +} + +// List lists all TestTypes in the indexer. +func (s *testTypeLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// TestTypeNamespaceLister helps list and get TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeNamespaceLister interface { + // List lists all TestTypes in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.TestType, err error) + // Get retrieves the TestType from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all TestTypes in the indexer for a given namespace. +func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given namespace and name. +func (s testTypeNamespaceLister) Get(name string) (*v1.TestType, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("testtype"), name) + } + return obj.(*v1.TestType), nil +} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/openapi/zz_generated.openapi.go b/staging/src/k8s.io/code-generator/examples/apiserver/openapi/zz_generated.openapi.go index e4d0148a6dd..a20dae445e0 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/openapi/zz_generated.openapi.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/openapi/zz_generated.openapi.go @@ -81,6 +81,9 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "k8s.io/apimachinery/pkg/runtime.TypeMeta": schema_k8sio_apimachinery_pkg_runtime_TypeMeta(ref), "k8s.io/apimachinery/pkg/runtime.Unknown": schema_k8sio_apimachinery_pkg_runtime_Unknown(ref), "k8s.io/apimachinery/pkg/version.Info": schema_k8sio_apimachinery_pkg_version_Info(ref), + "k8s.io/code-generator/examples/apiserver/apis/core/v1.TestType": schema_apiserver_apis_core_v1_TestType(ref), + "k8s.io/code-generator/examples/apiserver/apis/core/v1.TestTypeList": schema_apiserver_apis_core_v1_TestTypeList(ref), + "k8s.io/code-generator/examples/apiserver/apis/core/v1.TestTypeStatus": schema_apiserver_apis_core_v1_TestTypeStatus(ref), "k8s.io/code-generator/examples/apiserver/apis/example/v1.TestType": schema_apiserver_apis_example_v1_TestType(ref), "k8s.io/code-generator/examples/apiserver/apis/example/v1.TestTypeList": schema_apiserver_apis_example_v1_TestTypeList(ref), "k8s.io/code-generator/examples/apiserver/apis/example/v1.TestTypeStatus": schema_apiserver_apis_example_v1_TestTypeStatus(ref), @@ -2632,6 +2635,116 @@ func schema_k8sio_apimachinery_pkg_version_Info(ref common.ReferenceCallback) co } } +func schema_apiserver_apis_core_v1_TestType(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TestType is a top-level type. A client is created for it.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/code-generator/examples/apiserver/apis/core/v1.TestTypeStatus"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta", "k8s.io/code-generator/examples/apiserver/apis/core/v1.TestTypeStatus"}, + } +} + +func schema_apiserver_apis_core_v1_TestTypeList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TestTypeList is a top-level list type. The client methods for lists are automatically created. You are not supposed to create a separated client for this one.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/code-generator/examples/apiserver/apis/core/v1.TestType"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta", "k8s.io/code-generator/examples/apiserver/apis/core/v1.TestType"}, + } +} + +func schema_apiserver_apis_core_v1_TestTypeStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "Blah": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"Blah"}, + }, + }, + } +} + func schema_apiserver_apis_example_v1_TestType(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ From 6b2f779bd40bf78b8b54617f4e092334eb659654 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 28 May 2024 09:03:04 +0200 Subject: [PATCH 2/5] code-generator/client-gen: decouple core group from package name 'api' Signed-off-by: Dr. Stefan Schimanski --- pkg/apis/core/doc.go | 1 + staging/src/k8s.io/api/core/v1/doc.go | 1 + .../cmd/client-gen/args/gvpackages_test.go | 6 +++--- .../generators/generator_for_group.go | 20 +++++++------------ .../cmd/client-gen/types/types.go | 4 ++-- .../examples/apiserver/apis/core/doc.go | 1 + .../examples/apiserver/apis/core/v1/doc.go | 1 + 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/pkg/apis/core/doc.go b/pkg/apis/core/doc.go index 6475fdab1de..79ef0e05d56 100644 --- a/pkg/apis/core/doc.go +++ b/pkg/apis/core/doc.go @@ -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. diff --git a/staging/src/k8s.io/api/core/v1/doc.go b/staging/src/k8s.io/api/core/v1/doc.go index dc1f946fc28..bc0041b331a 100644 --- a/staging/src/k8s.io/api/core/v1/doc.go +++ b/staging/src/k8s.io/api/core/v1/doc.go @@ -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" diff --git a/staging/src/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go b/staging/src/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go index f8891bec87a..3f7eb8902ed 100644 --- a/staging/src/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go +++ b/staging/src/k8s.io/code-generator/cmd/client-gen/args/gvpackages_test.go @@ -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"}, }}, }, }, diff --git a/staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go b/staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go index 2a7ac1e9a49..83b13b11cdc 100644 --- a/staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go +++ b/staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go @@ -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"}), diff --git a/staging/src/k8s.io/code-generator/cmd/client-gen/types/types.go b/staging/src/k8s.io/code-generator/cmd/client-gen/types/types.go index 2c0a5347fcd..df030e8459c 100644 --- a/staging/src/k8s.io/code-generator/cmd/client-gen/types/types.go +++ b/staging/src/k8s.io/code-generator/cmd/client-gen/types/types.go @@ -42,7 +42,7 @@ func (g Group) String() string { } func (g Group) NonEmpty() string { - if g == "api" { + if g == "" { return "core" } return string(g) @@ -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() diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go index bc03c4655e0..da76737808c 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/doc.go @@ -15,5 +15,6 @@ limitations under the License. */ // +k8s:deepcopy-gen=package +// +groupName= package core // import "k8s.io/code-generator/examples/apiserver/apis/core" diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go index 6af4ff739ce..0de0bdda64e 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/doc.go @@ -18,5 +18,6 @@ limitations under the License. // +k8s:deepcopy-gen=package // +k8s:defaulter-gen=TypeMeta // +k8s:conversion-gen=k8s.io/code-generator/examples/apiserver/apis/core +// +groupName= package v1 // import "k8s.io/code-generator/examples/apiserver/apis/core/v1" From be2cf7e4d920136c3e93c991473806a9de0a3a54 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 28 May 2024 09:06:22 +0200 Subject: [PATCH 3/5] code-generator/client-gen: add example with single package api/v1 Signed-off-by: Dr. Stefan Schimanski --- .../examples/hack/update-codegen.sh | 9 + .../examples/hack/verify-codegen.sh | 1 + .../examples/single/api/v1/doc.go | 21 ++ .../examples/single/api/v1/register.go | 59 ++++ .../examples/single/api/v1/types.go | 74 +++++ .../single/api/v1/zz_generated.deepcopy.go | 178 ++++++++++++ .../single/api/v1/zz_generated.defaults.go | 33 +++ .../api/v1/clustertesttype.go | 210 ++++++++++++++ .../applyconfiguration/api/v1/testtype.go | 211 ++++++++++++++ .../applyconfiguration/internal/internal.go | 62 ++++ .../single/applyconfiguration/utils.go | 39 +++ .../single/clientset/versioned/clientset.go | 120 ++++++++ .../versioned/fake/clientset_generated.go | 85 ++++++ .../single/clientset/versioned/fake/doc.go | 20 ++ .../clientset/versioned/fake/register.go | 56 ++++ .../single/clientset/versioned/scheme/doc.go | 20 ++ .../clientset/versioned/scheme/register.go | 56 ++++ .../versioned/typed/api/v1/api_client.go | 112 +++++++ .../versioned/typed/api/v1/clustertesttype.go | 274 ++++++++++++++++++ .../clientset/versioned/typed/api/v1/doc.go | 20 ++ .../versioned/typed/api/v1/fake/doc.go | 20 ++ .../typed/api/v1/fake/fake_api_client.go | 44 +++ .../typed/api/v1/fake/fake_clustertesttype.go | 199 +++++++++++++ .../typed/api/v1/fake/fake_testtype.go | 189 ++++++++++++ .../typed/api/v1/generated_expansion.go | 23 ++ .../versioned/typed/api/v1/testtype.go | 256 ++++++++++++++++ .../externalversions/api/interface.go | 46 +++ .../api/v1/clustertesttype.go | 89 ++++++ .../externalversions/api/v1/interface.go | 52 ++++ .../externalversions/api/v1/testtype.go | 90 ++++++ .../informers/externalversions/factory.go | 261 +++++++++++++++++ .../informers/externalversions/generic.go | 64 ++++ .../internalinterfaces/factory_interfaces.go | 40 +++ .../single/listers/api/v1/clustertesttype.go | 68 +++++ .../listers/api/v1/expansion_generated.go | 31 ++ .../single/listers/api/v1/testtype.go | 99 +++++++ 36 files changed, 3231 insertions(+) create mode 100644 staging/src/k8s.io/code-generator/examples/single/api/v1/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/api/v1/register.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/api/v1/types.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/api/v1/zz_generated.deepcopy.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/api/v1/zz_generated.defaults.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/applyconfiguration/internal/internal.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/applyconfiguration/utils.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/clientset.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/clientset_generated.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/register.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/scheme/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/scheme/register.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/api_client.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/clustertesttype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/doc.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_api_client.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/generated_expansion.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/testtype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/interface.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/clustertesttype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/interface.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/testtype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/informers/externalversions/factory.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/informers/externalversions/generic.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces/factory_interfaces.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/listers/api/v1/clustertesttype.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/listers/api/v1/expansion_generated.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/listers/api/v1/testtype.go diff --git a/staging/src/k8s.io/code-generator/examples/hack/update-codegen.sh b/staging/src/k8s.io/code-generator/examples/hack/update-codegen.sh index dea221cafdc..2f9a734cd68 100755 --- a/staging/src/k8s.io/code-generator/examples/hack/update-codegen.sh +++ b/staging/src/k8s.io/code-generator/examples/hack/update-codegen.sh @@ -60,6 +60,15 @@ kube::codegen::gen_client \ --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ "${SCRIPT_ROOT}/crd/apis" +kube::codegen::gen_client \ + --with-watch \ + --with-applyconfig \ + --output-dir "${SCRIPT_ROOT}/single" \ + --output-pkg "${THIS_PKG}/single" \ + --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ + --one-input-api "api" \ + "${SCRIPT_ROOT}/single" + kube::codegen::gen_client \ --with-watch \ --with-applyconfig \ diff --git a/staging/src/k8s.io/code-generator/examples/hack/verify-codegen.sh b/staging/src/k8s.io/code-generator/examples/hack/verify-codegen.sh index c27fdda69e0..789f2847244 100755 --- a/staging/src/k8s.io/code-generator/examples/hack/verify-codegen.sh +++ b/staging/src/k8s.io/code-generator/examples/hack/verify-codegen.sh @@ -47,6 +47,7 @@ fi echo "Smoke testing examples by compiling..." pushd "${SCRIPT_ROOT}" go build "k8s.io/code-generator/examples/crd/..." + go build "k8s.io/code-generator/examples/single/..." go build "k8s.io/code-generator/examples/apiserver/..." go build "k8s.io/code-generator/examples/MixedCase/..." go build "k8s.io/code-generator/examples/HyphenGroup/..." diff --git a/staging/src/k8s.io/code-generator/examples/single/api/v1/doc.go b/staging/src/k8s.io/code-generator/examples/single/api/v1/doc.go new file mode 100644 index 00000000000..89647413b0c --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/api/v1/doc.go @@ -0,0 +1,21 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package +// +k8s:defaulter-gen=TypeMeta +// +groupName=example.crd.code-generator.k8s.io + +package v1 // import "k8s.io/code-generator/examples/crd/apis/example/v1" diff --git a/staging/src/k8s.io/code-generator/examples/single/api/v1/register.go b/staging/src/k8s.io/code-generator/examples/single/api/v1/register.go new file mode 100644 index 00000000000..58371e0e943 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/api/v1/register.go @@ -0,0 +1,59 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var SchemeGroupVersion = schema.GroupVersion{Group: "example.crd.code-generator.k8s.io", Version: "v1"} + +var ( + // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api. + // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. + SchemeBuilder runtime.SchemeBuilder + localSchemeBuilder = &SchemeBuilder + AddToScheme = localSchemeBuilder.AddToScheme +) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(addKnownTypes) +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &TestType{}, + &TestTypeList{}, + ) + + scheme.AddKnownTypes(SchemeGroupVersion, + &metav1.Status{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/staging/src/k8s.io/code-generator/examples/single/api/v1/types.go b/staging/src/k8s.io/code-generator/examples/single/api/v1/types.go new file mode 100644 index 00000000000..8543ad26c26 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/api/v1/types.go @@ -0,0 +1,74 @@ +/* +Copyright 2015 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// TestType is a top-level type. A client is created for it. +type TestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // +optional + Status TestTypeStatus `json:"status,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// TestTypeList is a top-level list type. The client methods for lists are automatically created. +// You are not supposed to create a separated client for this one. +type TestTypeList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []TestType `json:"items"` +} + +type TestTypeStatus struct { + Blah string +} + +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type ClusterTestTypeList struct { + metav1.TypeMeta + metav1.ListMeta + Items []ClusterTestType +} + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +genclient:method=GetScale,verb=get,subresource=scale,result=k8s.io/api/autoscaling/v1.Scale +// +genclient:method=UpdateScale,verb=update,subresource=scale,input=k8s.io/api/autoscaling/v1.Scale,result=k8s.io/api/autoscaling/v1.Scale + +type ClusterTestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // +optional + Status ClusterTestTypeStatus `json:"status,omitempty"` +} + +type ClusterTestTypeStatus struct { + Blah string +} diff --git a/staging/src/k8s.io/code-generator/examples/single/api/v1/zz_generated.deepcopy.go b/staging/src/k8s.io/code-generator/examples/single/api/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..5eee47016bf --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/api/v1/zz_generated.deepcopy.go @@ -0,0 +1,178 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. +func (in *ClusterTestType) DeepCopy() *ClusterTestType { + if in == nil { + return nil + } + out := new(ClusterTestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterTestType) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ClusterTestType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. +func (in *ClusterTestTypeList) DeepCopy() *ClusterTestTypeList { + if in == nil { + return nil + } + out := new(ClusterTestTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterTestTypeList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. +func (in *ClusterTestTypeStatus) DeepCopy() *ClusterTestTypeStatus { + if in == nil { + return nil + } + out := new(ClusterTestTypeStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestType) DeepCopyInto(out *TestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. +func (in *TestType) DeepCopy() *TestType { + if in == nil { + return nil + } + out := new(TestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestType) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestTypeList) DeepCopyInto(out *TestTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]TestType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. +func (in *TestTypeList) DeepCopy() *TestTypeList { + if in == nil { + return nil + } + out := new(TestTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestTypeList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestTypeStatus) DeepCopyInto(out *TestTypeStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeStatus. +func (in *TestTypeStatus) DeepCopy() *TestTypeStatus { + if in == nil { + return nil + } + out := new(TestTypeStatus) + in.DeepCopyInto(out) + return out +} diff --git a/staging/src/k8s.io/code-generator/examples/single/api/v1/zz_generated.defaults.go b/staging/src/k8s.io/code-generator/examples/single/api/v1/zz_generated.defaults.go new file mode 100644 index 00000000000..dac177e93bd --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/api/v1/zz_generated.defaults.go @@ -0,0 +1,33 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by defaulter-gen. DO NOT EDIT. + +package v1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + return nil +} diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttype.go new file mode 100644 index 00000000000..14e646e3a56 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttype.go @@ -0,0 +1,210 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" + apiv1 "k8s.io/code-generator/examples/single/api/v1" +) + +// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// with apply. +type ClusterTestTypeApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + Status *apiv1.ClusterTestTypeStatus `json:"status,omitempty"` +} + +// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// apply. +func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { + b := &ClusterTestTypeApplyConfiguration{} + b.WithName(name) + b.WithKind("ClusterTestType") + b.WithAPIVersion("example.crd.code-generator.k8s.io/v1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithStatus sets the Status field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Status field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithStatus(value apiv1.ClusterTestTypeStatus) *ClusterTestTypeApplyConfiguration { + b.Status = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtype.go new file mode 100644 index 00000000000..855e3262f72 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtype.go @@ -0,0 +1,211 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" + apiv1 "k8s.io/code-generator/examples/single/api/v1" +) + +// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// with apply. +type TestTypeApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + Status *apiv1.TestTypeStatus `json:"status,omitempty"` +} + +// TestType constructs an declarative configuration of the TestType type for use with +// apply. +func TestType(name, namespace string) *TestTypeApplyConfiguration { + b := &TestTypeApplyConfiguration{} + b.WithName(name) + b.WithNamespace(namespace) + b.WithKind("TestType") + b.WithAPIVersion("example.crd.code-generator.k8s.io/v1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithStatus sets the Status field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Status field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithStatus(value apiv1.TestTypeStatus) *TestTypeApplyConfiguration { + b.Status = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/internal/internal.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/internal/internal.go new file mode 100644 index 00000000000..4d7ef1313fb --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/internal/internal.go @@ -0,0 +1,62 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package internal + +import ( + "fmt" + "sync" + + typed "sigs.k8s.io/structured-merge-diff/v4/typed" +) + +func Parser() *typed.Parser { + parserOnce.Do(func() { + var err error + parser, err = typed.NewParser(schemaYAML) + if err != nil { + panic(fmt.Sprintf("Failed to parse schema: %v", err)) + } + }) + return parser +} + +var parserOnce sync.Once +var parser *typed.Parser +var schemaYAML = typed.YAMLObject(`types: +- name: __untyped_atomic_ + scalar: untyped + list: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic + map: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic +- name: __untyped_deduced_ + scalar: untyped + list: + elementType: + namedType: __untyped_atomic_ + elementRelationship: atomic + map: + elementType: + namedType: __untyped_deduced_ + elementRelationship: separable +`) diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/utils.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/utils.go new file mode 100644 index 00000000000..ce9634fb7ee --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/utils.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package applyconfiguration + +import ( + schema "k8s.io/apimachinery/pkg/runtime/schema" + v1 "k8s.io/code-generator/examples/single/api/v1" + apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" +) + +// ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no +// apply configuration type exists for the given GroupVersionKind. +func ForKind(kind schema.GroupVersionKind) interface{} { + switch kind { + // Group=example.crd.code-generator.k8s.io, Version=v1 + case v1.SchemeGroupVersion.WithKind("ClusterTestType"): + return &apiv1.ClusterTestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("TestType"): + return &apiv1.TestTypeApplyConfiguration{} + + } + return nil +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/clientset.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/clientset.go new file mode 100644 index 00000000000..55936d3a61e --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/clientset.go @@ -0,0 +1,120 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package versioned + +import ( + "fmt" + "net/http" + + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" + examplev1 "k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + ExampleV1() examplev1.ExampleV1Interface +} + +// Clientset contains the clients for groups. +type Clientset struct { + *discovery.DiscoveryClient + exampleV1 *examplev1.ExampleV1Client +} + +// ExampleV1 retrieves the ExampleV1Client +func (c *Clientset) ExampleV1() examplev1.ExampleV1Interface { + return c.exampleV1 +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*Clientset, error) { + configShallowCopy := *c + + if configShallowCopy.UserAgent == "" { + configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() + } + + // share the transport between all clients + httpClient, err := rest.HTTPClientFor(&configShallowCopy) + if err != nil { + return nil, err + } + + return NewForConfigAndClient(&configShallowCopy, httpClient) +} + +// NewForConfigAndClient creates a new Clientset for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfigAndClient will generate a rate-limiter in configShallowCopy. +func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } + configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) + } + + var cs Clientset + var err error + cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + return &cs, nil +} + +// NewForConfigOrDie creates a new Clientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Clientset { + cs, err := NewForConfig(c) + if err != nil { + panic(err) + } + return cs +} + +// New creates a new Clientset for the given RESTClient. +func New(c rest.Interface) *Clientset { + var cs Clientset + cs.exampleV1 = examplev1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/clientset_generated.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 00000000000..8913148cfa6 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,85 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" + clientset "k8s.io/code-generator/examples/single/clientset/versioned" + examplev1 "k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1" + fakeexamplev1 "k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery + tracker testing.ObjectTracker +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() testing.ObjectTracker { + return c.tracker +} + +var ( + _ clientset.Interface = &Clientset{} + _ testing.FakeClient = &Clientset{} +) + +// ExampleV1 retrieves the ExampleV1Client +func (c *Clientset) ExampleV1() examplev1.ExampleV1Interface { + return &fakeexamplev1.FakeExampleV1{Fake: &c.Fake} +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/doc.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/doc.go new file mode 100644 index 00000000000..9b99e716709 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/register.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/register.go new file mode 100644 index 00000000000..084c6bc8fc3 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/register.go @@ -0,0 +1,56 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + examplev1 "k8s.io/code-generator/examples/single/api/v1" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + examplev1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/scheme/doc.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/scheme/doc.go new file mode 100644 index 00000000000..7dc3756168f --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/scheme/register.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/scheme/register.go new file mode 100644 index 00000000000..d54e5a32b0e --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/scheme/register.go @@ -0,0 +1,56 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + examplev1 "k8s.io/code-generator/examples/single/api/v1" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + examplev1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(Scheme)) +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/api_client.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/api_client.go new file mode 100644 index 00000000000..3d39be087c8 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/api_client.go @@ -0,0 +1,112 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + "net/http" + + rest "k8s.io/client-go/rest" + v1 "k8s.io/code-generator/examples/single/api/v1" + "k8s.io/code-generator/examples/single/clientset/versioned/scheme" +) + +type ExampleV1Interface interface { + RESTClient() rest.Interface + ClusterTestTypesGetter + TestTypesGetter +} + +// ExampleV1Client is used to interact with features provided by the example.crd.code-generator.k8s.io group. +type ExampleV1Client struct { + restClient rest.Interface +} + +func (c *ExampleV1Client) ClusterTestTypes() ClusterTestTypeInterface { + return newClusterTestTypes(c) +} + +func (c *ExampleV1Client) TestTypes(namespace string) TestTypeInterface { + return newTestTypes(c, namespace) +} + +// NewForConfig creates a new ExampleV1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleV1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new ExampleV1Client for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*ExampleV1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &ExampleV1Client{client}, nil +} + +// NewForConfigOrDie creates a new ExampleV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new ExampleV1Client for the given RESTClient. +func New(c rest.Interface) *ExampleV1Client { + return &ExampleV1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *ExampleV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/clustertesttype.go new file mode 100644 index 00000000000..0fd4b88a68b --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/clustertesttype.go @@ -0,0 +1,274 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + json "encoding/json" + "fmt" + "time" + + autoscalingv1 "k8s.io/api/autoscaling/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1 "k8s.io/code-generator/examples/single/api/v1" + apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" + scheme "k8s.io/code-generator/examples/single/clientset/versioned/scheme" +) + +// ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. +// A group's client should implement this interface. +type ClusterTestTypesGetter interface { + ClusterTestTypes() ClusterTestTypeInterface +} + +// ClusterTestTypeInterface has methods to work with ClusterTestType resources. +type ClusterTestTypeInterface interface { + Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (*v1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.ClusterTestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) + Apply(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) + ApplyStatus(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) + GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (*autoscalingv1.Scale, error) + UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (*autoscalingv1.Scale, error) + + ClusterTestTypeExpansion +} + +// clusterTestTypes implements ClusterTestTypeInterface +type clusterTestTypes struct { + client rest.Interface +} + +// newClusterTestTypes returns a ClusterTestTypes +func newClusterTestTypes(c *ExampleV1Client) *clusterTestTypes { + return &clusterTestTypes{ + client: c.RESTClient(), + } +} + +// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. +func (c *clusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { + result = &v1.ClusterTestType{} + err = c.client.Get(). + Resource("clustertesttypes"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. +func (c *clusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1.ClusterTestTypeList{} + err = c.client.Get(). + Resource("clustertesttypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested clusterTestTypes. +func (c *clusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("clustertesttypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. +func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { + result = &v1.ClusterTestType{} + err = c.client.Post(). + Resource("clustertesttypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(clusterTestType). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. +func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { + result = &v1.ClusterTestType{} + err = c.client.Put(). + Resource("clustertesttypes"). + Name(clusterTestType.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(clusterTestType). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { + result = &v1.ClusterTestType{} + err = c.client.Put(). + Resource("clustertesttypes"). + Name(clusterTestType.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(clusterTestType). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. +func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + return c.client.Delete(). + Resource("clustertesttypes"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Resource("clustertesttypes"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched clusterTestType. +func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { + result = &v1.ClusterTestType{} + err = c.client.Patch(pt). + Resource("clustertesttypes"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied clusterTestType. +func (c *clusterTestTypes) Apply(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { + if clusterTestType == nil { + return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") + } + patchOpts := opts.ToPatchOptions() + data, err := json.Marshal(clusterTestType) + if err != nil { + return nil, err + } + name := clusterTestType.Name + if name == nil { + return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") + } + result = &v1.ClusterTestType{} + err = c.client.Patch(types.ApplyPatchType). + Resource("clustertesttypes"). + Name(*name). + VersionedParams(&patchOpts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} + +// ApplyStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). +func (c *clusterTestTypes) ApplyStatus(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { + if clusterTestType == nil { + return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") + } + patchOpts := opts.ToPatchOptions() + data, err := json.Marshal(clusterTestType) + if err != nil { + return nil, err + } + + name := clusterTestType.Name + if name == nil { + return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") + } + + result = &v1.ClusterTestType{} + err = c.client.Patch(types.ApplyPatchType). + Resource("clustertesttypes"). + Name(*name). + SubResource("status"). + VersionedParams(&patchOpts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} + +// GetScale takes name of the clusterTestType, and returns the corresponding autoscalingv1.Scale object, and an error if there is any. +func (c *clusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { + result = &autoscalingv1.Scale{} + err = c.client.Get(). + Resource("clustertesttypes"). + Name(clusterTestTypeName). + SubResource("scale"). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// UpdateScale takes the top resource name and the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. +func (c *clusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { + result = &autoscalingv1.Scale{} + err = c.client.Put(). + Resource("clustertesttypes"). + Name(clusterTestTypeName). + SubResource("scale"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(scale). + Do(ctx). + Into(result) + return +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/doc.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/doc.go new file mode 100644 index 00000000000..3af5d054f10 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/doc.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/doc.go new file mode 100644 index 00000000000..16f44399065 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_api_client.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_api_client.go new file mode 100644 index 00000000000..905fbe02726 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_api_client.go @@ -0,0 +1,44 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + v1 "k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1" +) + +type FakeExampleV1 struct { + *testing.Fake +} + +func (c *FakeExampleV1) ClusterTestTypes() v1.ClusterTestTypeInterface { + return &FakeClusterTestTypes{c} +} + +func (c *FakeExampleV1) TestTypes(namespace string) v1.TestTypeInterface { + return &FakeTestTypes{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeExampleV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go new file mode 100644 index 00000000000..ec0ef6a95a1 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go @@ -0,0 +1,199 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + json "encoding/json" + "fmt" + + autoscalingv1 "k8s.io/api/autoscaling/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1 "k8s.io/code-generator/examples/single/api/v1" + apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" +) + +// FakeClusterTestTypes implements ClusterTestTypeInterface +type FakeClusterTestTypes struct { + Fake *FakeExampleV1 +} + +var clustertesttypesResource = v1.SchemeGroupVersion.WithResource("clustertesttypes") + +var clustertesttypesKind = v1.SchemeGroupVersion.WithKind("ClusterTestType") + +// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. +func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*v1.ClusterTestType), err +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. +func (c *FakeClusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &v1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1.ClusterTestTypeList{ListMeta: obj.(*v1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*v1.ClusterTestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested clusterTestTypes. +func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) +} + +// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. +func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*v1.ClusterTestType), err +} + +// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. +func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*v1.ClusterTestType), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*v1.ClusterTestType), err +} + +// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. +func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v1.ClusterTestType{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) + + _, err := c.Fake.Invokes(action, &v1.ClusterTestTypeList{}) + return err +} + +// Patch applies the patch and returns the patched clusterTestType. +func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*v1.ClusterTestType), err +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied clusterTestType. +func (c *FakeClusterTestTypes) Apply(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { + if clusterTestType == nil { + return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") + } + data, err := json.Marshal(clusterTestType) + if err != nil { + return nil, err + } + name := clusterTestType.Name + if name == nil { + return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") + } + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, *name, types.ApplyPatchType, data), &v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*v1.ClusterTestType), err +} + +// ApplyStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). +func (c *FakeClusterTestTypes) ApplyStatus(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { + if clusterTestType == nil { + return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") + } + data, err := json.Marshal(clusterTestType) + if err != nil { + return nil, err + } + name := clusterTestType.Name + if name == nil { + return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") + } + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, *name, types.ApplyPatchType, data, "status"), &v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*v1.ClusterTestType), err +} + +// GetScale takes name of the clusterTestType, and returns the corresponding scale object, and an error if there is any. +func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetSubresourceAction(clustertesttypesResource, "scale", clusterTestTypeName), &autoscalingv1.Scale{}) + if obj == nil { + return nil, err + } + return obj.(*autoscalingv1.Scale), err +} + +// UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. +func (c *FakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "scale", scale), &autoscalingv1.Scale{}) + if obj == nil { + return nil, err + } + return obj.(*autoscalingv1.Scale), err +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go new file mode 100644 index 00000000000..801f9257167 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go @@ -0,0 +1,189 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + json "encoding/json" + "fmt" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1 "k8s.io/code-generator/examples/single/api/v1" + apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" +) + +// FakeTestTypes implements TestTypeInterface +type FakeTestTypes struct { + Fake *FakeExampleV1 + ns string +} + +var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") + +var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") + +// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. +func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &v1.TestTypeList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} + for _, item := range obj.(*v1.TestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested testTypes. +func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) + +} + +// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(testtypesResource, "status", c.ns, testType), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// Delete takes name of the testType and deletes it. Returns an error if one occurs. +func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) + return err +} + +// Patch applies the patch and returns the patched testType. +func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied testType. +func (c *FakeTestTypes) Apply(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { + if testType == nil { + return nil, fmt.Errorf("testType provided to Apply must not be nil") + } + data, err := json.Marshal(testType) + if err != nil { + return nil, err + } + name := testType.Name + if name == nil { + return nil, fmt.Errorf("testType.Name must be provided to Apply") + } + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, *name, types.ApplyPatchType, data), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} + +// ApplyStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). +func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { + if testType == nil { + return nil, fmt.Errorf("testType provided to Apply must not be nil") + } + data, err := json.Marshal(testType) + if err != nil { + return nil, err + } + name := testType.Name + if name == nil { + return nil, fmt.Errorf("testType.Name must be provided to Apply") + } + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, *name, types.ApplyPatchType, data, "status"), &v1.TestType{}) + + if obj == nil { + return nil, err + } + return obj.(*v1.TestType), err +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/generated_expansion.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/generated_expansion.go new file mode 100644 index 00000000000..3059734a9ea --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +type ClusterTestTypeExpansion interface{} + +type TestTypeExpansion interface{} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/testtype.go new file mode 100644 index 00000000000..eb7c2ae7949 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/testtype.go @@ -0,0 +1,256 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + json "encoding/json" + "fmt" + "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1 "k8s.io/code-generator/examples/single/api/v1" + apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" + scheme "k8s.io/code-generator/examples/single/clientset/versioned/scheme" +) + +// TestTypesGetter has a method to return a TestTypeInterface. +// A group's client should implement this interface. +type TestTypesGetter interface { + TestTypes(namespace string) TestTypeInterface +} + +// TestTypeInterface has methods to work with TestType resources. +type TestTypeInterface interface { + Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) + Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.TestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) + Apply(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) + ApplyStatus(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) + TestTypeExpansion +} + +// testTypes implements TestTypeInterface +type testTypes struct { + client rest.Interface + ns string +} + +// newTestTypes returns a TestTypes +func newTestTypes(c *ExampleV1Client, namespace string) *testTypes { + return &testTypes{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. +func (c *testTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Get(). + Namespace(c.ns). + Resource("testtypes"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *testTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1.TestTypeList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("testtypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested testTypes. +func (c *testTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("testtypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *testTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Post(). + Namespace(c.ns). + Resource("testtypes"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testType). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *testTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Put(). + Namespace(c.ns). + Resource("testtypes"). + Name(testType.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testType). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *testTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Put(). + Namespace(c.ns). + Resource("testtypes"). + Name(testType.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(testType). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the testType and deletes it. Returns an error if one occurs. +func (c *testTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("testtypes"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *testTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("testtypes"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched testType. +func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { + result = &v1.TestType{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("testtypes"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied testType. +func (c *testTypes) Apply(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { + if testType == nil { + return nil, fmt.Errorf("testType provided to Apply must not be nil") + } + patchOpts := opts.ToPatchOptions() + data, err := json.Marshal(testType) + if err != nil { + return nil, err + } + name := testType.Name + if name == nil { + return nil, fmt.Errorf("testType.Name must be provided to Apply") + } + result = &v1.TestType{} + err = c.client.Patch(types.ApplyPatchType). + Namespace(c.ns). + Resource("testtypes"). + Name(*name). + VersionedParams(&patchOpts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} + +// ApplyStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). +func (c *testTypes) ApplyStatus(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { + if testType == nil { + return nil, fmt.Errorf("testType provided to Apply must not be nil") + } + patchOpts := opts.ToPatchOptions() + data, err := json.Marshal(testType) + if err != nil { + return nil, err + } + + name := testType.Name + if name == nil { + return nil, fmt.Errorf("testType.Name must be provided to Apply") + } + + result = &v1.TestType{} + err = c.client.Patch(types.ApplyPatchType). + Namespace(c.ns). + Resource("testtypes"). + Name(*name). + SubResource("status"). + VersionedParams(&patchOpts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/interface.go b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/interface.go new file mode 100644 index 00000000000..633ba3d0dee --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/interface.go @@ -0,0 +1,46 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package api + +import ( + v1 "k8s.io/code-generator/examples/single/informers/externalversions/api/v1" + internalinterfaces "k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/clustertesttype.go new file mode 100644 index 00000000000..d6b3e0bb4e6 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/clustertesttype.go @@ -0,0 +1,89 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + time "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + apiv1 "k8s.io/code-generator/examples/single/api/v1" + versioned "k8s.io/code-generator/examples/single/clientset/versioned" + internalinterfaces "k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces" + v1 "k8s.io/code-generator/examples/single/listers/api/v1" +) + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.ClusterTestTypeLister +} + +type clusterTestTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewClusterTestTypeInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &apiv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apiv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { + return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/interface.go b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/interface.go new file mode 100644 index 00000000000..442f04b9590 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/interface.go @@ -0,0 +1,52 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // ClusterTestTypes returns a ClusterTestTypeInformer. + ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeInformer. +func (v *version) ClusterTestTypes() ClusterTestTypeInformer { + return &clusterTestTypeInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// TestTypes returns a TestTypeInformer. +func (v *version) TestTypes() TestTypeInformer { + return &testTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/testtype.go new file mode 100644 index 00000000000..e6ea6b10d5f --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/api/v1/testtype.go @@ -0,0 +1,90 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + time "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + apiv1 "k8s.io/code-generator/examples/single/api/v1" + versioned "k8s.io/code-generator/examples/single/clientset/versioned" + internalinterfaces "k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces" + v1 "k8s.io/code-generator/examples/single/listers/api/v1" +) + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.TestTypeLister +} + +type testTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleV1().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &apiv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apiv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeInformer) Lister() v1.TestTypeLister { + return v1.NewTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/factory.go b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/factory.go new file mode 100644 index 00000000000..f886fdf5e24 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/factory.go @@ -0,0 +1,261 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + versioned "k8s.io/code-generator/examples/single/clientset/versioned" + api "k8s.io/code-generator/examples/single/informers/externalversions/api" + internalinterfaces "k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + transform cache.TransformFunc + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool + // wg tracks how many goroutines were started. + wg sync.WaitGroup + // shuttingDown is true when Shutdown has been called. It may still be running + // because it needs to wait for goroutines. + shuttingDown bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + for k, v := range resyncConfig { + factory.customResync[reflect.TypeOf(k)] = v + } + return factory + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.tweakListOptions = tweakListOptions + return factory + } +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.namespace = namespace + return factory + } +} + +// WithTransform sets a transform on all informers. +func WithTransform(transform cache.TransformFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.transform = transform + return factory + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + namespace: v1.NamespaceAll, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + factory = opt(factory) + } + + return factory +} + +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + if f.shuttingDown { + return + } + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + f.wg.Add(1) + // We need a new variable in each loop iteration, + // otherwise the goroutine would use the loop variable + // and that keeps changing. + informer := informer + go func() { + defer f.wg.Done() + informer.Run(stopCh) + }() + f.startedInformers[informerType] = true + } + } +} + +func (f *sharedInformerFactory) Shutdown() { + f.lock.Lock() + f.shuttingDown = true + f.lock.Unlock() + + // Will return immediately if there is nothing to wait for. + f.wg.Wait() +} + +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + informer.SetTransform(f.transform) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +// +// It is typically used like this: +// +// ctx, cancel := context.Background() +// defer cancel() +// factory := NewSharedInformerFactory(client, resyncPeriod) +// defer factory.WaitForStop() // Returns immediately if nothing was started. +// genericInformer := factory.ForResource(resource) +// typedInformer := factory.SomeAPIGroup().V1().SomeType() +// factory.Start(ctx.Done()) // Start processing these informers. +// synced := factory.WaitForCacheSync(ctx.Done()) +// for v, ok := range synced { +// if !ok { +// fmt.Fprintf(os.Stderr, "caches failed to sync: %v", v) +// return +// } +// } +// +// // Creating informers can also be created after Start, but then +// // Start must be called again: +// anotherGenericInformer := factory.ForResource(resource) +// factory.Start(ctx.Done()) +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + + // Start initializes all requested informers. They are handled in goroutines + // which run until the stop channel gets closed. + Start(stopCh <-chan struct{}) + + // Shutdown marks a factory as shutting down. At that point no new + // informers can be started anymore and Start will return without + // doing anything. + // + // In addition, Shutdown blocks until all goroutines have terminated. For that + // to happen, the close channel(s) that they were started with must be closed, + // either before Shutdown gets called or while it is waiting. + // + // Shutdown may be called multiple times, even concurrently. All such calls will + // block until all goroutines have terminated. + Shutdown() + + // WaitForCacheSync blocks until all started informers' caches were synced + // or the stop channel gets closed. + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + + // InformerFor returns the SharedIndexInformer for obj using an internal + // client. + InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer + + Example() api.Interface +} + +func (f *sharedInformerFactory) Example() api.Interface { + return api.New(f, f.namespace, f.tweakListOptions) +} diff --git a/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/generic.go b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/generic.go new file mode 100644 index 00000000000..4f0c5791ef5 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/generic.go @@ -0,0 +1,64 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + v1 "k8s.io/code-generator/examples/single/api/v1" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=example.crd.code-generator.k8s.io, Version=v1 + case v1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1().ClusterTestTypes().Informer()}, nil + case v1.SchemeGroupVersion.WithResource("testtypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces/factory_interfaces.go b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 00000000000..20cb59b4b2b --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,40 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" + versioned "k8s.io/code-generator/examples/single/clientset/versioned" +) + +// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/clustertesttype.go new file mode 100644 index 00000000000..de1d9e3708e --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/clustertesttype.go @@ -0,0 +1,68 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1 "k8s.io/code-generator/examples/single/api/v1" +) + +// ClusterTestTypeLister helps list ClusterTestTypes. +// All objects returned here must be treated as read-only. +type ClusterTestTypeLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) + // Get retrieves the ClusterTestType from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.ClusterTestType, error) + ClusterTestTypeListerExpansion +} + +// clusterTestTypeLister implements the ClusterTestTypeLister interface. +type clusterTestTypeLister struct { + indexer cache.Indexer +} + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{indexer: indexer} +} + +// List lists all ClusterTestTypes in the indexer. +func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the index for a given name. +func (s *clusterTestTypeLister) Get(name string) (*v1.ClusterTestType, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("clustertesttype"), name) + } + return obj.(*v1.ClusterTestType), nil +} diff --git a/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/expansion_generated.go b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/expansion_generated.go new file mode 100644 index 00000000000..2681a29f472 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/expansion_generated.go @@ -0,0 +1,31 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/testtype.go new file mode 100644 index 00000000000..028a44a4bf7 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/testtype.go @@ -0,0 +1,99 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1 "k8s.io/code-generator/examples/single/api/v1" +) + +// TestTypeLister helps list TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.TestType, err error) + // TestTypes returns an object that can list and get TestTypes. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// testTypeLister implements the TestTypeLister interface. +type testTypeLister struct { + indexer cache.Indexer +} + +// NewTestTypeLister returns a new TestTypeLister. +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{indexer: indexer} +} + +// List lists all TestTypes in the indexer. +func (s *testTypeLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// TestTypeNamespaceLister helps list and get TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeNamespaceLister interface { + // List lists all TestTypes in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.TestType, err error) + // Get retrieves the TestType from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all TestTypes in the indexer for a given namespace. +func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given namespace and name. +func (s testTypeNamespaceLister) Get(name string) (*v1.TestType, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("testtype"), name) + } + return obj.(*v1.TestType), nil +} From 676d989713060aca0fc8f4fb0e82249fa69a7f39 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 4 Jun 2024 11:50:23 -0400 Subject: [PATCH 4/5] code-generator/examples: fix json tags Signed-off-by: Dr. Stefan Schimanski --- .../examples/HyphenGroup/apis/example/v1/types.go | 10 +++++----- .../examples/MixedCase/apis/example/v1/types.go | 11 ++++++----- .../examples/apiserver/apis/core/types.go | 3 +++ .../examples/apiserver/apis/core/v1/types.go | 2 +- .../examples/apiserver/apis/example/types.go | 3 +++ .../examples/apiserver/apis/example/v1/types.go | 2 +- .../examples/apiserver/apis/example2/types.go | 1 + .../examples/apiserver/apis/example2/v1/types.go | 2 +- .../examples/apiserver/apis/example3.io/types.go | 3 +++ .../examples/apiserver/apis/example3.io/v1/types.go | 2 +- .../examples/crd/apis/example/v1/types.go | 12 +++++++----- .../examples/crd/apis/example2/v1/types.go | 2 +- .../code-generator/examples/single/api/v1/types.go | 11 ++++++----- 13 files changed, 39 insertions(+), 25 deletions(-) diff --git a/staging/src/k8s.io/code-generator/examples/HyphenGroup/apis/example/v1/types.go b/staging/src/k8s.io/code-generator/examples/HyphenGroup/apis/example/v1/types.go index 3c97c319ca1..b8c7f823301 100644 --- a/staging/src/k8s.io/code-generator/examples/HyphenGroup/apis/example/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/HyphenGroup/apis/example/v1/types.go @@ -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 @@ -70,5 +70,5 @@ type ClusterTestType struct { } type ClusterTestTypeStatus struct { - Blah string + Blah string `json:"blah"` } diff --git a/staging/src/k8s.io/code-generator/examples/MixedCase/apis/example/v1/types.go b/staging/src/k8s.io/code-generator/examples/MixedCase/apis/example/v1/types.go index 3eb7669d3fc..f74e27cee0d 100644 --- a/staging/src/k8s.io/code-generator/examples/MixedCase/apis/example/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/MixedCase/apis/example/v1/types.go @@ -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 @@ -71,5 +72,5 @@ type ClusterTestType struct { } type ClusterTestTypeStatus struct { - Blah string + Blah string `json:"blah"` } diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/types.go index bd725cd6ca5..9ad4579cd31 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/types.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/types.go @@ -24,7 +24,9 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // TestType is a top-level type. A client is created for it. type TestType struct { metav1.TypeMeta + // +optional metav1.ObjectMeta + // +optional Status TestTypeStatus } @@ -34,6 +36,7 @@ type TestType struct { // You are not supposed to create a separated client for this one. type TestTypeList struct { metav1.TypeMeta + // +optional metav1.ListMeta Items []TestType diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/types.go index 819ad21a5f8..5a9c0b9a7bd 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/core/v1/types.go @@ -43,5 +43,5 @@ type TestTypeList struct { } type TestTypeStatus struct { - Blah string + Blah string `json:"blah"` } diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example/types.go index b4fc976684f..8f3dbb55375 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example/types.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example/types.go @@ -24,7 +24,9 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // TestType is a top-level type. A client is created for it. type TestType struct { metav1.TypeMeta + // +optional metav1.ObjectMeta + // +optional Status TestTypeStatus } @@ -34,6 +36,7 @@ type TestType struct { // You are not supposed to create a separated client for this one. type TestTypeList struct { metav1.TypeMeta + // +optional metav1.ListMeta Items []TestType diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example/v1/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example/v1/types.go index 5c2ebc4d6f4..24a1a348c35 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example/v1/types.go @@ -43,5 +43,5 @@ type TestTypeList struct { } type TestTypeStatus struct { - Blah string + Blah string `json:"blah"` } diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example2/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example2/types.go index a23ee09185c..3bdcf2a9a4b 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example2/types.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example2/types.go @@ -21,6 +21,7 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +genclient:nonNamespaced +// // TestType is a top-level type. A client is created for it. type TestType struct { metav1.TypeMeta diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example2/v1/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example2/v1/types.go index 5c2ebc4d6f4..24a1a348c35 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example2/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example2/v1/types.go @@ -43,5 +43,5 @@ type TestTypeList struct { } type TestTypeStatus struct { - Blah string + Blah string `json:"blah"` } diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example3.io/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example3.io/types.go index 0c49b45f367..a020b0af534 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example3.io/types.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example3.io/types.go @@ -24,7 +24,9 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // TestType is a top-level type. A client is created for it. type TestType struct { metav1.TypeMeta + // +optional metav1.ObjectMeta + // +optional Status TestTypeStatus } @@ -34,6 +36,7 @@ type TestType struct { // You are not supposed to create a separated client for this one. type TestTypeList struct { metav1.TypeMeta + // +optional metav1.ListMeta Items []TestType diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example3.io/v1/types.go b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example3.io/v1/types.go index 5c2ebc4d6f4..24a1a348c35 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/apis/example3.io/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/apis/example3.io/v1/types.go @@ -43,5 +43,5 @@ type TestTypeList struct { } type TestTypeStatus struct { - Blah string + Blah string `json:"blah"` } diff --git a/staging/src/k8s.io/code-generator/examples/crd/apis/example/v1/types.go b/staging/src/k8s.io/code-generator/examples/crd/apis/example/v1/types.go index d92582569c7..0fc1edb41c9 100644 --- a/staging/src/k8s.io/code-generator/examples/crd/apis/example/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/crd/apis/example/v1/types.go @@ -44,16 +44,18 @@ 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 @@ -71,5 +73,5 @@ type ClusterTestType struct { } type ClusterTestTypeStatus struct { - Blah string + Blah string `json:"blah"` } diff --git a/staging/src/k8s.io/code-generator/examples/crd/apis/example2/v1/types.go b/staging/src/k8s.io/code-generator/examples/crd/apis/example2/v1/types.go index 5c2ebc4d6f4..24a1a348c35 100644 --- a/staging/src/k8s.io/code-generator/examples/crd/apis/example2/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/crd/apis/example2/v1/types.go @@ -43,5 +43,5 @@ type TestTypeList struct { } type TestTypeStatus struct { - Blah string + Blah string `json:"blah"` } diff --git a/staging/src/k8s.io/code-generator/examples/single/api/v1/types.go b/staging/src/k8s.io/code-generator/examples/single/api/v1/types.go index 8543ad26c26..f1bd68f4981 100644 --- a/staging/src/k8s.io/code-generator/examples/single/api/v1/types.go +++ b/staging/src/k8s.io/code-generator/examples/single/api/v1/types.go @@ -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 @@ -70,5 +71,5 @@ type ClusterTestType struct { } type ClusterTestTypeStatus struct { - Blah string + Blah string `json:"blah"` } From ac3b7643ad2e0211438f097b1ecdf2482469860c Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Tue, 4 Jun 2024 12:00:59 -0400 Subject: [PATCH 5/5] make codegen Signed-off-by: Dr. Stefan Schimanski --- .../codegen_violation_exceptions.list | 4 - .../example/v1/clustertesttype.go | 7 +- .../example/v1/clustertesttypestatus.go | 39 ++++ .../applyconfiguration/example/v1/testtype.go | 7 +- .../example/v1/testtypestatus.go | 39 ++++ .../HyphenGroup/applyconfiguration/utils.go | 4 + .../example/v1/clustertesttype.go | 7 +- .../example/v1/clustertesttypestatus.go | 39 ++++ .../applyconfiguration/example/v1/testtype.go | 7 +- .../example/v1/testtypestatus.go | 39 ++++ .../MixedCase/applyconfiguration/utils.go | 4 + .../typed/core/v1/fake/fake_testtype.go | 36 +-- .../versioned/typed/core/v1/testtype.go | 146 +------------ .../apiserver/listers/core/v1/testtype.go | 39 +--- .../apiserver/openapi/zz_generated.openapi.go | 16 +- .../example/v1/clustertesttype.go | 7 +- .../example/v1/clustertesttypestatus.go | 39 ++++ .../applyconfiguration/example/v1/testtype.go | 7 +- .../example/v1/testtypestatus.go | 39 ++++ .../example2/v1/testtype.go | 7 +- .../example2/v1/testtypestatus.go | 39 ++++ .../examples/crd/applyconfiguration/utils.go | 6 + .../api/v1/clustertesttype.go | 17 +- .../api/v1/clustertesttypestatus.go | 39 ++++ .../applyconfiguration/api/v1/testtype.go | 17 +- .../api/v1/testtypestatus.go | 39 ++++ .../single/applyconfiguration/utils.go | 11 + .../versioned/fake/clientset_generated.go | 39 +++- .../versioned/typed/api/v1/clustertesttype.go | 196 ++--------------- .../typed/api/v1/fake/fake_clustertesttype.go | 56 +++-- .../typed/api/v1/fake/fake_testtype.go | 46 ++-- .../versioned/typed/api/v1/testtype.go | 205 +----------------- .../single/listers/api/v1/clustertesttype.go | 26 +-- .../single/listers/api/v1/testtype.go | 39 +--- 34 files changed, 593 insertions(+), 714 deletions(-) create mode 100644 staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttypestatus.go create mode 100644 staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtypestatus.go create mode 100644 staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/clustertesttypestatus.go create mode 100644 staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/testtypestatus.go create mode 100644 staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/clustertesttypestatus.go create mode 100644 staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/testtypestatus.go create mode 100644 staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1/testtypestatus.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttypestatus.go create mode 100644 staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtypestatus.go diff --git a/api/api-rules/codegen_violation_exceptions.list b/api/api-rules/codegen_violation_exceptions.list index 257872812c7..8f1c9408a63 100644 --- a/api/api-rules/codegen_violation_exceptions.list +++ b/api/api-rules/codegen_violation_exceptions.list @@ -7,7 +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/core/v1,TestTypeStatus,Blah -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 diff --git a/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttype.go index a5436ba3868..e80b9fa5f57 100644 --- a/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttype.go +++ b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttype.go @@ -22,7 +22,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - examplev1 "k8s.io/code-generator/examples/HyphenGroup/apis/example/v1" ) // ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use @@ -30,7 +29,7 @@ import ( type ClusterTestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *examplev1.ClusterTestTypeStatus `json:"status,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } // ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with @@ -204,8 +203,8 @@ func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationEx // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithStatus(value examplev1.ClusterTestTypeStatus) *ClusterTestTypeApplyConfiguration { - b.Status = &value +func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeStatusApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.Status = value return b } diff --git a/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttypestatus.go b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttypestatus.go new file mode 100644 index 00000000000..c2ccfa58117 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/clustertesttypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use +// with apply. +type ClusterTestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with +// apply. +func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { + return &ClusterTestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *ClusterTestTypeStatusApplyConfiguration) WithBlah(value string) *ClusterTestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtype.go index 5c9b0c3a8fa..c47810eba6b 100644 --- a/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtype.go @@ -22,7 +22,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - examplev1 "k8s.io/code-generator/examples/HyphenGroup/apis/example/v1" ) // TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use @@ -30,7 +29,7 @@ import ( type TestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *examplev1.TestTypeStatus `json:"status,omitempty"` + Status *TestTypeStatusApplyConfiguration `json:"status,omitempty"` } // TestType constructs a declarative configuration of the TestType type for use with @@ -205,8 +204,8 @@ func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithStatus(value examplev1.TestTypeStatus) *TestTypeApplyConfiguration { - b.Status = &value +func (b *TestTypeApplyConfiguration) WithStatus(value *TestTypeStatusApplyConfiguration) *TestTypeApplyConfiguration { + b.Status = value return b } diff --git a/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtypestatus.go b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtypestatus.go new file mode 100644 index 00000000000..246b2ee1889 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/example/v1/testtypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// TestTypeStatusApplyConfiguration represents a declarative configuration of the TestTypeStatus type for use +// with apply. +type TestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// TestTypeStatusApplyConfiguration constructs a declarative configuration of the TestTypeStatus type for use with +// apply. +func TestTypeStatus() *TestTypeStatusApplyConfiguration { + return &TestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *TestTypeStatusApplyConfiguration) WithBlah(value string) *TestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/utils.go b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/utils.go index 5856e20dc5f..ed90602696c 100644 --- a/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/utils.go +++ b/staging/src/k8s.io/code-generator/examples/HyphenGroup/applyconfiguration/utils.go @@ -34,8 +34,12 @@ func ForKind(kind schema.GroupVersionKind) interface{} { // Group=example-group.hyphens.code-generator.k8s.io, Version=v1 case v1.SchemeGroupVersion.WithKind("ClusterTestType"): return &examplev1.ClusterTestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): + return &examplev1.ClusterTestTypeStatusApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("TestType"): return &examplev1.TestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("TestTypeStatus"): + return &examplev1.TestTypeStatusApplyConfiguration{} } return nil diff --git a/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/clustertesttype.go index e15851f5cb0..30f68b3b7bb 100644 --- a/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/clustertesttype.go +++ b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/clustertesttype.go @@ -22,7 +22,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - examplev1 "k8s.io/code-generator/examples/MixedCase/apis/example/v1" ) // ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use @@ -30,7 +29,7 @@ import ( type ClusterTestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *examplev1.ClusterTestTypeStatus `json:"status,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } // ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with @@ -204,8 +203,8 @@ func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationEx // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithStatus(value examplev1.ClusterTestTypeStatus) *ClusterTestTypeApplyConfiguration { - b.Status = &value +func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeStatusApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.Status = value return b } diff --git a/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/clustertesttypestatus.go b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/clustertesttypestatus.go new file mode 100644 index 00000000000..c2ccfa58117 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/clustertesttypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use +// with apply. +type ClusterTestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with +// apply. +func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { + return &ClusterTestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *ClusterTestTypeStatusApplyConfiguration) WithBlah(value string) *ClusterTestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/testtype.go index d3bfd38c202..1e15689c2e1 100644 --- a/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/testtype.go @@ -22,7 +22,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - examplev1 "k8s.io/code-generator/examples/MixedCase/apis/example/v1" ) // TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use @@ -30,7 +29,7 @@ import ( type TestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *examplev1.TestTypeStatus `json:"status,omitempty"` + Status *TestTypeStatusApplyConfiguration `json:"status,omitempty"` } // TestType constructs a declarative configuration of the TestType type for use with @@ -205,8 +204,8 @@ func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithStatus(value examplev1.TestTypeStatus) *TestTypeApplyConfiguration { - b.Status = &value +func (b *TestTypeApplyConfiguration) WithStatus(value *TestTypeStatusApplyConfiguration) *TestTypeApplyConfiguration { + b.Status = value return b } diff --git a/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/testtypestatus.go b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/testtypestatus.go new file mode 100644 index 00000000000..246b2ee1889 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/example/v1/testtypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// TestTypeStatusApplyConfiguration represents a declarative configuration of the TestTypeStatus type for use +// with apply. +type TestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// TestTypeStatusApplyConfiguration constructs a declarative configuration of the TestTypeStatus type for use with +// apply. +func TestTypeStatus() *TestTypeStatusApplyConfiguration { + return &TestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *TestTypeStatusApplyConfiguration) WithBlah(value string) *TestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/utils.go b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/utils.go index c1103ea956e..c28368a4494 100644 --- a/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/utils.go +++ b/staging/src/k8s.io/code-generator/examples/MixedCase/applyconfiguration/utils.go @@ -34,8 +34,12 @@ func ForKind(kind schema.GroupVersionKind) interface{} { // Group=example.crd.code-generator.k8s.io, Version=v1 case v1.SchemeGroupVersion.WithKind("ClusterTestType"): return &examplev1.ClusterTestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): + return &examplev1.ClusterTestTypeStatusApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("TestType"): return &examplev1.TestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("TestTypeStatus"): + return &examplev1.TestTypeStatusApplyConfiguration{} } return nil diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go index 6beefaffa90..bcb4d416211 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/fake/fake_testtype.go @@ -41,22 +41,24 @@ var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") // Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &v1.TestType{}) + Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } // List takes label and field selectors, and returns the list of TestTypes that match those selectors. func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { + emptyResult := &v1.TestTypeList{} obj, err := c.Fake. - Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &v1.TestTypeList{}) + Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -75,40 +77,43 @@ func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (resu // Watch returns a watch.Interface that watches the requested testTypes. func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) } // Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &v1.TestType{}) + Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } // Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &v1.TestType{}) + Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } // UpdateStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) { +func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(testtypesResource, "status", c.ns, testType), &v1.TestType{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } @@ -123,7 +128,7 @@ func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.Del // DeleteCollection deletes a collection of objects. func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) return err @@ -131,11 +136,12 @@ func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.Delete // Patch applies the patch and returns the patched testType. func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &v1.TestType{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/testtype.go index a04cd3dd2aa..8c5d4be5bce 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/clientset/versioned/typed/core/v1/testtype.go @@ -20,12 +20,11 @@ package v1 import ( "context" - "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" scheme "k8s.io/code-generator/examples/apiserver/clientset/versioned/scheme" ) @@ -40,6 +39,7 @@ type TestTypesGetter interface { type TestTypeInterface interface { Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error @@ -52,144 +52,18 @@ type TestTypeInterface interface { // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithList[*v1.TestType, *v1.TestTypeList] } // newTestTypes returns a TestTypes func newTestTypes(c *CoreV1Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithList[*v1.TestType, *v1.TestTypeList]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }), } } - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.TestTypeList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *testTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *testTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/testtype.go index b2b2dc47644..ee143da73c5 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/listers/core/v1/testtype.go @@ -19,8 +19,8 @@ limitations under the License. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" v1 "k8s.io/code-generator/examples/apiserver/apis/core/v1" ) @@ -38,25 +38,17 @@ type TestTypeLister interface { // testTypeLister implements the TestTypeLister interface. type testTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1.TestType] } // NewTestTypeLister returns a new TestTypeLister. func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer. -func (s *testTypeLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err + return &testTypeLister{listers.New[*v1.TestType](indexer, v1.Resource("testtype"))} } // TestTypes returns an object that can list and get TestTypes. func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return testTypeNamespaceLister{listers.NewNamespaced[*v1.TestType](s.ResourceIndexer, namespace)} } // TestTypeNamespaceLister helps list and get TestTypes. @@ -74,26 +66,5 @@ type TestTypeNamespaceLister interface { // testTypeNamespaceLister implements the TestTypeNamespaceLister // interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given namespace. -func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given namespace and name. -func (s testTypeNamespaceLister) Get(name string) (*v1.TestType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("testtype"), name) - } - return obj.(*v1.TestType), nil + listers.ResourceIndexer[*v1.TestType] } diff --git a/staging/src/k8s.io/code-generator/examples/apiserver/openapi/zz_generated.openapi.go b/staging/src/k8s.io/code-generator/examples/apiserver/openapi/zz_generated.openapi.go index a20dae445e0..7ac39c8d99a 100644 --- a/staging/src/k8s.io/code-generator/examples/apiserver/openapi/zz_generated.openapi.go +++ b/staging/src/k8s.io/code-generator/examples/apiserver/openapi/zz_generated.openapi.go @@ -2731,7 +2731,7 @@ func schema_apiserver_apis_core_v1_TestTypeStatus(ref common.ReferenceCallback) SchemaProps: spec.SchemaProps{ Type: []string{"object"}, Properties: map[string]spec.Schema{ - "Blah": { + "blah": { SchemaProps: spec.SchemaProps{ Default: "", Type: []string{"string"}, @@ -2739,7 +2739,7 @@ func schema_apiserver_apis_core_v1_TestTypeStatus(ref common.ReferenceCallback) }, }, }, - Required: []string{"Blah"}, + Required: []string{"blah"}, }, }, } @@ -2841,7 +2841,7 @@ func schema_apiserver_apis_example_v1_TestTypeStatus(ref common.ReferenceCallbac SchemaProps: spec.SchemaProps{ Type: []string{"object"}, Properties: map[string]spec.Schema{ - "Blah": { + "blah": { SchemaProps: spec.SchemaProps{ Default: "", Type: []string{"string"}, @@ -2849,7 +2849,7 @@ func schema_apiserver_apis_example_v1_TestTypeStatus(ref common.ReferenceCallbac }, }, }, - Required: []string{"Blah"}, + Required: []string{"blah"}, }, }, } @@ -2951,7 +2951,7 @@ func schema_apiserver_apis_example2_v1_TestTypeStatus(ref common.ReferenceCallba SchemaProps: spec.SchemaProps{ Type: []string{"object"}, Properties: map[string]spec.Schema{ - "Blah": { + "blah": { SchemaProps: spec.SchemaProps{ Default: "", Type: []string{"string"}, @@ -2959,7 +2959,7 @@ func schema_apiserver_apis_example2_v1_TestTypeStatus(ref common.ReferenceCallba }, }, }, - Required: []string{"Blah"}, + Required: []string{"blah"}, }, }, } @@ -3061,7 +3061,7 @@ func schema_apiserver_apis_example3io_v1_TestTypeStatus(ref common.ReferenceCall SchemaProps: spec.SchemaProps{ Type: []string{"object"}, Properties: map[string]spec.Schema{ - "Blah": { + "blah": { SchemaProps: spec.SchemaProps{ Default: "", Type: []string{"string"}, @@ -3069,7 +3069,7 @@ func schema_apiserver_apis_example3io_v1_TestTypeStatus(ref common.ReferenceCall }, }, }, - Required: []string{"Blah"}, + Required: []string{"blah"}, }, }, } diff --git a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/clustertesttype.go index c89cd2ea9ef..30f68b3b7bb 100644 --- a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/clustertesttype.go +++ b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/clustertesttype.go @@ -22,7 +22,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - examplev1 "k8s.io/code-generator/examples/crd/apis/example/v1" ) // ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use @@ -30,7 +29,7 @@ import ( type ClusterTestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *examplev1.ClusterTestTypeStatus `json:"status,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } // ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with @@ -204,8 +203,8 @@ func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationEx // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithStatus(value examplev1.ClusterTestTypeStatus) *ClusterTestTypeApplyConfiguration { - b.Status = &value +func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeStatusApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.Status = value return b } diff --git a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/clustertesttypestatus.go b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/clustertesttypestatus.go new file mode 100644 index 00000000000..c2ccfa58117 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/clustertesttypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use +// with apply. +type ClusterTestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with +// apply. +func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { + return &ClusterTestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *ClusterTestTypeStatusApplyConfiguration) WithBlah(value string) *ClusterTestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/testtype.go index a09dc6da76e..1e15689c2e1 100644 --- a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/testtype.go @@ -22,7 +22,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - examplev1 "k8s.io/code-generator/examples/crd/apis/example/v1" ) // TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use @@ -30,7 +29,7 @@ import ( type TestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *examplev1.TestTypeStatus `json:"status,omitempty"` + Status *TestTypeStatusApplyConfiguration `json:"status,omitempty"` } // TestType constructs a declarative configuration of the TestType type for use with @@ -205,8 +204,8 @@ func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithStatus(value examplev1.TestTypeStatus) *TestTypeApplyConfiguration { - b.Status = &value +func (b *TestTypeApplyConfiguration) WithStatus(value *TestTypeStatusApplyConfiguration) *TestTypeApplyConfiguration { + b.Status = value return b } diff --git a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/testtypestatus.go b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/testtypestatus.go new file mode 100644 index 00000000000..246b2ee1889 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example/v1/testtypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// TestTypeStatusApplyConfiguration represents a declarative configuration of the TestTypeStatus type for use +// with apply. +type TestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// TestTypeStatusApplyConfiguration constructs a declarative configuration of the TestTypeStatus type for use with +// apply. +func TestTypeStatus() *TestTypeStatusApplyConfiguration { + return &TestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *TestTypeStatusApplyConfiguration) WithBlah(value string) *TestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1/testtype.go index 140caa19f81..37940976ac5 100644 --- a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1/testtype.go @@ -22,7 +22,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - example2v1 "k8s.io/code-generator/examples/crd/apis/example2/v1" ) // TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use @@ -30,7 +29,7 @@ import ( type TestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *example2v1.TestTypeStatus `json:"status,omitempty"` + Status *TestTypeStatusApplyConfiguration `json:"status,omitempty"` } // TestType constructs a declarative configuration of the TestType type for use with @@ -205,8 +204,8 @@ func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithStatus(value example2v1.TestTypeStatus) *TestTypeApplyConfiguration { - b.Status = &value +func (b *TestTypeApplyConfiguration) WithStatus(value *TestTypeStatusApplyConfiguration) *TestTypeApplyConfiguration { + b.Status = value return b } diff --git a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1/testtypestatus.go b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1/testtypestatus.go new file mode 100644 index 00000000000..246b2ee1889 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/example2/v1/testtypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// TestTypeStatusApplyConfiguration represents a declarative configuration of the TestTypeStatus type for use +// with apply. +type TestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// TestTypeStatusApplyConfiguration constructs a declarative configuration of the TestTypeStatus type for use with +// apply. +func TestTypeStatus() *TestTypeStatusApplyConfiguration { + return &TestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *TestTypeStatusApplyConfiguration) WithBlah(value string) *TestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/utils.go b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/utils.go index 6496ad39922..2fd91bfa374 100644 --- a/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/utils.go +++ b/staging/src/k8s.io/code-generator/examples/crd/applyconfiguration/utils.go @@ -36,12 +36,18 @@ func ForKind(kind schema.GroupVersionKind) interface{} { // Group=example.crd.code-generator.k8s.io, Version=v1 case v1.SchemeGroupVersion.WithKind("ClusterTestType"): return &examplev1.ClusterTestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): + return &examplev1.ClusterTestTypeStatusApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("TestType"): return &examplev1.TestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("TestTypeStatus"): + return &examplev1.TestTypeStatusApplyConfiguration{} // Group=example.test.crd.code-generator.k8s.io, Version=v1 case example2v1.SchemeGroupVersion.WithKind("TestType"): return &applyconfigurationexample2v1.TestTypeApplyConfiguration{} + case example2v1.SchemeGroupVersion.WithKind("TestTypeStatus"): + return &applyconfigurationexample2v1.TestTypeStatusApplyConfiguration{} } return nil diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttype.go index 14e646e3a56..30f68b3b7bb 100644 --- a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttype.go +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttype.go @@ -22,18 +22,17 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - apiv1 "k8s.io/code-generator/examples/single/api/v1" ) -// ClusterTestTypeApplyConfiguration represents an declarative configuration of the ClusterTestType type for use +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use // with apply. type ClusterTestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *apiv1.ClusterTestTypeStatus `json:"status,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// ClusterTestType constructs an declarative configuration of the ClusterTestType type for use with +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with // apply. func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { b := &ClusterTestTypeApplyConfiguration{} @@ -204,7 +203,13 @@ func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationEx // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *ClusterTestTypeApplyConfiguration) WithStatus(value apiv1.ClusterTestTypeStatus) *ClusterTestTypeApplyConfiguration { - b.Status = &value +func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeStatusApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.Name +} diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttypestatus.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttypestatus.go new file mode 100644 index 00000000000..c2ccfa58117 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/clustertesttypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use +// with apply. +type ClusterTestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with +// apply. +func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { + return &ClusterTestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *ClusterTestTypeStatusApplyConfiguration) WithBlah(value string) *ClusterTestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtype.go index 855e3262f72..1e15689c2e1 100644 --- a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtype.go @@ -22,18 +22,17 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" v1 "k8s.io/client-go/applyconfigurations/meta/v1" - apiv1 "k8s.io/code-generator/examples/single/api/v1" ) -// TestTypeApplyConfiguration represents an declarative configuration of the TestType type for use +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use // with apply. type TestTypeApplyConfiguration struct { v1.TypeMetaApplyConfiguration `json:",inline"` *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` - Status *apiv1.TestTypeStatus `json:"status,omitempty"` + Status *TestTypeStatusApplyConfiguration `json:"status,omitempty"` } -// TestType constructs an declarative configuration of the TestType type for use with +// TestType constructs a declarative configuration of the TestType type for use with // apply. func TestType(name, namespace string) *TestTypeApplyConfiguration { b := &TestTypeApplyConfiguration{} @@ -205,7 +204,13 @@ func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() // WithStatus sets the Status field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Status field is set to the value of the last call. -func (b *TestTypeApplyConfiguration) WithStatus(value apiv1.TestTypeStatus) *TestTypeApplyConfiguration { - b.Status = &value +func (b *TestTypeApplyConfiguration) WithStatus(value *TestTypeStatusApplyConfiguration) *TestTypeApplyConfiguration { + b.Status = value return b } + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.Name +} diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtypestatus.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtypestatus.go new file mode 100644 index 00000000000..246b2ee1889 --- /dev/null +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/api/v1/testtypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// TestTypeStatusApplyConfiguration represents a declarative configuration of the TestTypeStatus type for use +// with apply. +type TestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// TestTypeStatusApplyConfiguration constructs a declarative configuration of the TestTypeStatus type for use with +// apply. +func TestTypeStatus() *TestTypeStatusApplyConfiguration { + return &TestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *TestTypeStatusApplyConfiguration) WithBlah(value string) *TestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/utils.go b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/utils.go index ce9634fb7ee..07079ed2b68 100644 --- a/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/utils.go +++ b/staging/src/k8s.io/code-generator/examples/single/applyconfiguration/utils.go @@ -19,9 +19,12 @@ limitations under the License. package applyconfiguration import ( + runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" + testing "k8s.io/client-go/testing" v1 "k8s.io/code-generator/examples/single/api/v1" apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" + internal "k8s.io/code-generator/examples/single/applyconfiguration/internal" ) // ForKind returns an apply configuration type for the given GroupVersionKind, or nil if no @@ -31,9 +34,17 @@ func ForKind(kind schema.GroupVersionKind) interface{} { // Group=example.crd.code-generator.k8s.io, Version=v1 case v1.SchemeGroupVersion.WithKind("ClusterTestType"): return &apiv1.ClusterTestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): + return &apiv1.ClusterTestTypeStatusApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("TestType"): return &apiv1.TestTypeApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("TestTypeStatus"): + return &apiv1.TestTypeStatusApplyConfiguration{} } return nil } + +func NewTypeConverter(scheme *runtime.Scheme) *testing.TypeConverter { + return &testing.TypeConverter{Scheme: scheme, TypeResolver: internal.Parser()} +} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/clientset_generated.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/clientset_generated.go index 8913148cfa6..d16257bc4a3 100644 --- a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/clientset_generated.go +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/fake/clientset_generated.go @@ -24,6 +24,7 @@ import ( "k8s.io/client-go/discovery" fakediscovery "k8s.io/client-go/discovery/fake" "k8s.io/client-go/testing" + applyconfiguration "k8s.io/code-generator/examples/single/applyconfiguration" clientset "k8s.io/code-generator/examples/single/clientset/versioned" examplev1 "k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1" fakeexamplev1 "k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake" @@ -31,8 +32,12 @@ import ( // NewSimpleClientset returns a clientset that will respond with the provided objects. // It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement +// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement // for a real clientset and is mostly useful in simple unit tests. +// +// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). func NewSimpleClientset(objects ...runtime.Object) *Clientset { o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range objects { @@ -74,6 +79,38 @@ func (c *Clientset) Tracker() testing.ObjectTracker { return c.tracker } +// NewClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewClientset(objects ...runtime.Object) *Clientset { + o := testing.NewFieldManagedObjectTracker( + scheme, + codecs.UniversalDecoder(), + applyconfiguration.NewTypeConverter(scheme), + ) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + var ( _ clientset.Interface = &Clientset{} _ testing.FakeClient = &Clientset{} diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/clustertesttype.go index 0fd4b88a68b..2981be5ce0f 100644 --- a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/clustertesttype.go +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/clustertesttype.go @@ -20,15 +20,12 @@ package v1 import ( "context" - json "encoding/json" - "fmt" - "time" autoscalingv1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/single/api/v1" apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" scheme "k8s.io/code-generator/examples/single/clientset/versioned/scheme" @@ -44,6 +41,7 @@ type ClusterTestTypesGetter interface { type ClusterTestTypeInterface interface { Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (*v1.ClusterTestType, error) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error @@ -52,6 +50,7 @@ type ClusterTestTypeInterface interface { Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) Apply(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). ApplyStatus(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (*autoscalingv1.Scale, error) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (*autoscalingv1.Scale, error) @@ -61,195 +60,26 @@ type ClusterTestTypeInterface interface { // clusterTestTypes implements ClusterTestTypeInterface type clusterTestTypes struct { - client rest.Interface + *gentype.ClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *apiv1.ClusterTestTypeApplyConfiguration] } // newClusterTestTypes returns a ClusterTestTypes func newClusterTestTypes(c *ExampleV1Client) *clusterTestTypes { return &clusterTestTypes{ - client: c.RESTClient(), + gentype.NewClientWithListAndApply[*v1.ClusterTestType, *v1.ClusterTestTypeList, *apiv1.ClusterTestTypeApplyConfiguration]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }), } } -// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. -func (c *clusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Get(). - Resource("clustertesttypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. -func (c *clusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.ClusterTestTypeList{} - err = c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested clusterTestTypes. -func (c *clusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Post(). - Resource("clustertesttypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. -func (c *clusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *clusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Put(). - Resource("clustertesttypes"). - Name(clusterTestType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(clusterTestType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. -func (c *clusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Resource("clustertesttypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *clusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Resource("clustertesttypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched clusterTestType. -func (c *clusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { - result = &v1.ClusterTestType{} - err = c.client.Patch(pt). - Resource("clustertesttypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied clusterTestType. -func (c *clusterTestTypes) Apply(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - patchOpts := opts.ToPatchOptions() - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - result = &v1.ClusterTestType{} - err = c.client.Patch(types.ApplyPatchType). - Resource("clustertesttypes"). - Name(*name). - VersionedParams(&patchOpts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *clusterTestTypes) ApplyStatus(ctx context.Context, clusterTestType *apiv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.ClusterTestType, err error) { - if clusterTestType == nil { - return nil, fmt.Errorf("clusterTestType provided to Apply must not be nil") - } - patchOpts := opts.ToPatchOptions() - data, err := json.Marshal(clusterTestType) - if err != nil { - return nil, err - } - - name := clusterTestType.Name - if name == nil { - return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") - } - - result = &v1.ClusterTestType{} - err = c.client.Patch(types.ApplyPatchType). - Resource("clustertesttypes"). - Name(*name). - SubResource("status"). - VersionedParams(&patchOpts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} - // GetScale takes name of the clusterTestType, and returns the corresponding autoscalingv1.Scale object, and an error if there is any. func (c *clusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { result = &autoscalingv1.Scale{} - err = c.client.Get(). + err = c.GetClient().Get(). Resource("clustertesttypes"). Name(clusterTestTypeName). SubResource("scale"). @@ -262,7 +92,7 @@ func (c *clusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName str // UpdateScale takes the top resource name and the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. func (c *clusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { result = &autoscalingv1.Scale{} - err = c.client.Put(). + err = c.GetClient().Put(). Resource("clustertesttypes"). Name(clusterTestTypeName). SubResource("scale"). diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go index ec0ef6a95a1..ba705cfbd2a 100644 --- a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_clustertesttype.go @@ -44,20 +44,22 @@ var clustertesttypesKind = v1.SchemeGroupVersion.WithKind("ClusterTestType") // Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} obj, err := c.Fake. - Invokes(testing.NewRootGetAction(clustertesttypesResource, name), &v1.ClusterTestType{}) + Invokes(testing.NewRootGetActionWithOptions(clustertesttypesResource, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.ClusterTestType), err } // List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. func (c *FakeClusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { + emptyResult := &v1.ClusterTestTypeList{} obj, err := c.Fake. - Invokes(testing.NewRootListAction(clustertesttypesResource, clustertesttypesKind, opts), &v1.ClusterTestTypeList{}) + Invokes(testing.NewRootListActionWithOptions(clustertesttypesResource, clustertesttypesKind, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -76,36 +78,39 @@ func (c *FakeClusterTestTypes) List(ctx context.Context, opts metav1.ListOptions // Watch returns a watch.Interface that watches the requested clusterTestTypes. func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewRootWatchAction(clustertesttypesResource, opts)) + InvokesWatch(testing.NewRootWatchActionWithOptions(clustertesttypesResource, opts)) } // Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(clustertesttypesResource, clusterTestType), &v1.ClusterTestType{}) + Invokes(testing.NewRootCreateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.ClusterTestType), err } // Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(clustertesttypesResource, clusterTestType), &v1.ClusterTestType{}) + Invokes(testing.NewRootUpdateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.ClusterTestType), err } // UpdateStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) { +func (c *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "status", clusterTestType), &v1.ClusterTestType{}) + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "status", clusterTestType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.ClusterTestType), err } @@ -119,7 +124,7 @@ func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts met // DeleteCollection deletes a collection of objects. func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(clustertesttypesResource, listOpts) + action := testing.NewRootDeleteCollectionActionWithOptions(clustertesttypesResource, opts, listOpts) _, err := c.Fake.Invokes(action, &v1.ClusterTestTypeList{}) return err @@ -127,10 +132,11 @@ func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts metav1 // Patch applies the patch and returns the patched clusterTestType. func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, name, pt, data, subresources...), &v1.ClusterTestType{}) + Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.ClusterTestType), err } @@ -148,10 +154,11 @@ func (c *FakeClusterTestTypes) Apply(ctx context.Context, clusterTestType *apiv1 if name == nil { return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") } + emptyResult := &v1.ClusterTestType{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, *name, types.ApplyPatchType, data), &v1.ClusterTestType{}) + Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.ClusterTestType), err } @@ -170,30 +177,33 @@ func (c *FakeClusterTestTypes) ApplyStatus(ctx context.Context, clusterTestType if name == nil { return nil, fmt.Errorf("clusterTestType.Name must be provided to Apply") } + emptyResult := &v1.ClusterTestType{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(clustertesttypesResource, *name, types.ApplyPatchType, data, "status"), &v1.ClusterTestType{}) + Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.ClusterTestType), err } // GetScale takes name of the clusterTestType, and returns the corresponding scale object, and an error if there is any. func (c *FakeClusterTestTypes) GetScale(ctx context.Context, clusterTestTypeName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { + emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootGetSubresourceAction(clustertesttypesResource, "scale", clusterTestTypeName), &autoscalingv1.Scale{}) + Invokes(testing.NewRootGetSubresourceActionWithOptions(clustertesttypesResource, "scale", clusterTestTypeName, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*autoscalingv1.Scale), err } // UpdateScale takes the representation of a scale and updates it. Returns the server's representation of the scale, and an error, if there is any. func (c *FakeClusterTestTypes) UpdateScale(ctx context.Context, clusterTestTypeName string, scale *autoscalingv1.Scale, opts metav1.UpdateOptions) (result *autoscalingv1.Scale, err error) { + emptyResult := &autoscalingv1.Scale{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(clustertesttypesResource, "scale", scale), &autoscalingv1.Scale{}) + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "scale", scale, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*autoscalingv1.Scale), err } diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go index 801f9257167..c39075be447 100644 --- a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/fake/fake_testtype.go @@ -44,22 +44,24 @@ var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") // Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewGetAction(testtypesResource, c.ns, name), &v1.TestType{}) + Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } // List takes label and field selectors, and returns the list of TestTypes that match those selectors. func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { + emptyResult := &v1.TestTypeList{} obj, err := c.Fake. - Invokes(testing.NewListAction(testtypesResource, testtypesKind, c.ns, opts), &v1.TestTypeList{}) + Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } label, _, _ := testing.ExtractFromListOptions(opts) @@ -78,40 +80,43 @@ func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (resu // Watch returns a watch.Interface that watches the requested testTypes. func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchAction(testtypesResource, c.ns, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) } // Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewCreateAction(testtypesResource, c.ns, testType), &v1.TestType{}) + Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } // Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewUpdateAction(testtypesResource, c.ns, testType), &v1.TestType{}) + Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } // UpdateStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) { +func (c *FakeTestTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(testtypesResource, "status", c.ns, testType), &v1.TestType{}) + Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "status", c.ns, testType, opts), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } @@ -126,7 +131,7 @@ func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.Del // DeleteCollection deletes a collection of objects. func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := testing.NewDeleteCollectionAction(testtypesResource, c.ns, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) return err @@ -134,11 +139,12 @@ func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.Delete // Patch applies the patch and returns the patched testType. func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, name, pt, data, subresources...), &v1.TestType{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } @@ -156,11 +162,12 @@ func (c *FakeTestTypes) Apply(ctx context.Context, testType *apiv1.TestTypeApply if name == nil { return nil, fmt.Errorf("testType.Name must be provided to Apply") } + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, *name, types.ApplyPatchType, data), &v1.TestType{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } @@ -179,11 +186,12 @@ func (c *FakeTestTypes) ApplyStatus(ctx context.Context, testType *apiv1.TestTyp if name == nil { return nil, fmt.Errorf("testType.Name must be provided to Apply") } + emptyResult := &v1.TestType{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(testtypesResource, c.ns, *name, types.ApplyPatchType, data, "status"), &v1.TestType{}) + Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) if obj == nil { - return nil, err + return emptyResult, err } return obj.(*v1.TestType), err } diff --git a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/testtype.go index eb7c2ae7949..75a2bc54021 100644 --- a/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/single/clientset/versioned/typed/api/v1/testtype.go @@ -20,14 +20,11 @@ package v1 import ( "context" - json "encoding/json" - "fmt" - "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" + gentype "k8s.io/client-go/gentype" v1 "k8s.io/code-generator/examples/single/api/v1" apiv1 "k8s.io/code-generator/examples/single/applyconfiguration/api/v1" scheme "k8s.io/code-generator/examples/single/clientset/versioned/scheme" @@ -43,6 +40,7 @@ type TestTypesGetter interface { type TestTypeInterface interface { Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error @@ -51,206 +49,25 @@ type TestTypeInterface interface { Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) Apply(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). ApplyStatus(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) TestTypeExpansion } // testTypes implements TestTypeInterface type testTypes struct { - client rest.Interface - ns string + *gentype.ClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *apiv1.TestTypeApplyConfiguration] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV1Client, namespace string) *testTypes { return &testTypes{ - client: c.RESTClient(), - ns: namespace, + gentype.NewClientWithListAndApply[*v1.TestType, *v1.TestTypeList, *apiv1.TestTypeApplyConfiguration]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }), } } - -// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. -func (c *testTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of TestTypes that match those selectors. -func (c *testTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.TestTypeList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested testTypes. -func (c *testTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Post(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. -func (c *testTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *testTypes) UpdateStatus(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Put(). - Namespace(c.ns). - Resource("testtypes"). - Name(testType.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(testType). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the testType and deletes it. Returns an error if one occurs. -func (c *testTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *testTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("testtypes"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched testType. -func (c *testTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { - result = &v1.TestType{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("testtypes"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} - -// Apply takes the given apply declarative configuration, applies it and returns the applied testType. -func (c *testTypes) Apply(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - patchOpts := opts.ToPatchOptions() - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - result = &v1.TestType{} - err = c.client.Patch(types.ApplyPatchType). - Namespace(c.ns). - Resource("testtypes"). - Name(*name). - VersionedParams(&patchOpts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} - -// ApplyStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). -func (c *testTypes) ApplyStatus(ctx context.Context, testType *apiv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (result *v1.TestType, err error) { - if testType == nil { - return nil, fmt.Errorf("testType provided to Apply must not be nil") - } - patchOpts := opts.ToPatchOptions() - data, err := json.Marshal(testType) - if err != nil { - return nil, err - } - - name := testType.Name - if name == nil { - return nil, fmt.Errorf("testType.Name must be provided to Apply") - } - - result = &v1.TestType{} - err = c.client.Patch(types.ApplyPatchType). - Namespace(c.ns). - Resource("testtypes"). - Name(*name). - SubResource("status"). - VersionedParams(&patchOpts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/clustertesttype.go b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/clustertesttype.go index de1d9e3708e..d0ca06c3ed7 100644 --- a/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/clustertesttype.go +++ b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/clustertesttype.go @@ -19,8 +19,8 @@ limitations under the License. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" v1 "k8s.io/code-generator/examples/single/api/v1" ) @@ -39,30 +39,10 @@ type ClusterTestTypeLister interface { // clusterTestTypeLister implements the ClusterTestTypeLister interface. type clusterTestTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1.ClusterTestType] } // NewClusterTestTypeLister returns a new ClusterTestTypeLister. func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { - return &clusterTestTypeLister{indexer: indexer} -} - -// List lists all ClusterTestTypes in the indexer. -func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ClusterTestType)) - }) - return ret, err -} - -// Get retrieves the ClusterTestType from the index for a given name. -func (s *clusterTestTypeLister) Get(name string) (*v1.ClusterTestType, error) { - obj, exists, err := s.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("clustertesttype"), name) - } - return obj.(*v1.ClusterTestType), nil + return &clusterTestTypeLister{listers.New[*v1.ClusterTestType](indexer, v1.Resource("clustertesttype"))} } diff --git a/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/testtype.go b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/testtype.go index 028a44a4bf7..72ca181a23f 100644 --- a/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/testtype.go +++ b/staging/src/k8s.io/code-generator/examples/single/listers/api/v1/testtype.go @@ -19,8 +19,8 @@ limitations under the License. package v1 import ( - "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" "k8s.io/client-go/tools/cache" v1 "k8s.io/code-generator/examples/single/api/v1" ) @@ -38,25 +38,17 @@ type TestTypeLister interface { // testTypeLister implements the TestTypeLister interface. type testTypeLister struct { - indexer cache.Indexer + listers.ResourceIndexer[*v1.TestType] } // NewTestTypeLister returns a new TestTypeLister. func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { - return &testTypeLister{indexer: indexer} -} - -// List lists all TestTypes in the indexer. -func (s *testTypeLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err + return &testTypeLister{listers.New[*v1.TestType](indexer, v1.Resource("testtype"))} } // TestTypes returns an object that can list and get TestTypes. func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { - return testTypeNamespaceLister{indexer: s.indexer, namespace: namespace} + return testTypeNamespaceLister{listers.NewNamespaced[*v1.TestType](s.ResourceIndexer, namespace)} } // TestTypeNamespaceLister helps list and get TestTypes. @@ -74,26 +66,5 @@ type TestTypeNamespaceLister interface { // testTypeNamespaceLister implements the TestTypeNamespaceLister // interface. type testTypeNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all TestTypes in the indexer for a given namespace. -func (s testTypeNamespaceLister) List(selector labels.Selector) (ret []*v1.TestType, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.TestType)) - }) - return ret, err -} - -// Get retrieves the TestType from the indexer for a given namespace and name. -func (s testTypeNamespaceLister) Get(name string) (*v1.TestType, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("testtype"), name) - } - return obj.(*v1.TestType), nil + listers.ResourceIndexer[*v1.TestType] }