diff --git a/examples/pkg/apisv2/exampledashed/doc.go b/examples/pkg/apisv2/exampledashed/doc.go new file mode 100644 index 000000000..404117122 --- /dev/null +++ b/examples/pkg/apisv2/exampledashed/doc.go @@ -0,0 +1,21 @@ +/* +Copyright 2022 The KCP 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. +*/ + +// +groupName=example-dashed.dev +// +groupGoName=ExampleDashed +// +k8s:deepcopy-gen=package +// +kubebuilder:validation:Optional +package exampledashed diff --git a/examples/pkg/apisv2/exampledashed/v2/doc.go b/examples/pkg/apisv2/exampledashed/v2/doc.go new file mode 100644 index 000000000..8cc848843 --- /dev/null +++ b/examples/pkg/apisv2/exampledashed/v2/doc.go @@ -0,0 +1,21 @@ +/* +Copyright 2022 The KCP 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. +*/ + +// +groupName=example-dashed.dev +// +groupGoName=ExampleDashed +// +k8s:deepcopy-gen=package +// +kubebuilder:validation:Optional +package v2 diff --git a/examples/pkg/apisv2/exampledashed/v2/register.go b/examples/pkg/apisv2/exampledashed/v2/register.go new file mode 100644 index 000000000..16fe48fa3 --- /dev/null +++ b/examples/pkg/apisv2/exampledashed/v2/register.go @@ -0,0 +1,57 @@ +/* +Copyright 2021 The KCP 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 v2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +const ( + GroupName = "example-dashed.dev" +) + +// SchemeGroupVersion is group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v2"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &TestType{}, + &TestTypeList{}, + &ClusterTestType{}, + &ClusterTestTypeList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/examples/pkg/apisv2/exampledashed/v2/types.go b/examples/pkg/apisv2/exampledashed/v2/types.go new file mode 100644 index 000000000..848c112e7 --- /dev/null +++ b/examples/pkg/apisv2/exampledashed/v2/types.go @@ -0,0 +1,70 @@ +/* +Copyright 2022 The KCP 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 v2 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// +genclient +// +genclient:noStatus +// +genclient:method=CreateField,verb=create,subresource=field,input=acme.corp/pkg/apis/example/v1.Field,result=acme.corp/pkg/apis/example/v1.Field +// +genclient:method=UpdateField,verb=update,subresource=field,input=acme.corp/pkg/apis/example/v1.Field,result=acme.corp/pkg/apis/example/v1.Field +// +genclient:method=GetField,verb=get,subresource=field,result=acme.corp/pkg/apis/example/v1.Field +// TestType is a top-level type. A client is created for it. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type TestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // +optional + APIGroups []string `json:"apiGroups,omitempty"` +} + +// 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. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type TestTypeList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []TestType `json:"items"` +} + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type ClusterTestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // ObjectKind is the type of resource being referenced + ObjectKind string `json:"kind"` + // ObjectName is the name of resource being referenced + ObjectName string `json:"name"` + // +optional + Status ClusterTestTypeStatus `json:"status,omitempty"` +} + +type ClusterTestTypeStatus struct { + Blah string `json:"blah,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type ClusterTestTypeList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []ClusterTestType `json:"items"` +} diff --git a/examples/pkg/apisv2/exampledashed/v2/zz_generated.deepcopy.go b/examples/pkg/apisv2/exampledashed/v2/zz_generated.deepcopy.go new file mode 100644 index 000000000..8ed8afd35 --- /dev/null +++ b/examples/pkg/apisv2/exampledashed/v2/zz_generated.deepcopy.go @@ -0,0 +1,144 @@ +//go:build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package v2 + +import ( + "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 +} + +// 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]) + } + } +} + +// 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 +} + +// 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) + if in.APIGroups != nil { + in, out := &in.APIGroups, &out.APIGroups + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// 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]) + } + } +} + +// 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 +} diff --git a/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/clustertesttype.go b/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..abe76f267 --- /dev/null +++ b/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/clustertesttype.go @@ -0,0 +1,233 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// 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"` + ObjectKind *string `json:"kind,omitempty"` + ObjectName *string `json:"name,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` +} + +// ClusterTestType constructs a 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-dashed.dev/v2") + 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{} + } +} + +// WithObjectKind sets the ObjectKind 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 ObjectKind field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithObjectKind(value string) *ClusterTestTypeApplyConfiguration { + b.ObjectKind = &value + return b +} + +// WithObjectName sets the ObjectName 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 ObjectName field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithObjectName(value string) *ClusterTestTypeApplyConfiguration { + b.ObjectName = &value + return b +} + +// 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 *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/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/clustertesttypestatus.go new file mode 100644 index 000000000..dfab3fe1b --- /dev/null +++ b/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/clustertesttypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +// 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/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/testtype.go b/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/testtype.go new file mode 100644 index 000000000..08dc5e3ea --- /dev/null +++ b/examples/pkg/generated/applyconfigurationsv2/exampledashed/v2/testtype.go @@ -0,0 +1,218 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// 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"` + APIGroups []string `json:"apiGroups,omitempty"` +} + +// TestType constructs a 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-dashed.dev/v2") + 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{} + } +} + +// WithAPIGroups adds the given value to the APIGroups 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 APIGroups field. +func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeApplyConfiguration { + for i := range values { + b.APIGroups = append(b.APIGroups, values[i]) + } + 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/examples/pkg/generated/applyconfigurationsv2/internal/internal.go b/examples/pkg/generated/applyconfigurationsv2/internal/internal.go new file mode 100644 index 000000000..82f62ba54 --- /dev/null +++ b/examples/pkg/generated/applyconfigurationsv2/internal/internal.go @@ -0,0 +1,62 @@ +/* +Copyright The KCP 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-v0.31. 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/examples/pkg/generated/applyconfigurationsv2/utils.go b/examples/pkg/generated/applyconfigurationsv2/utils.go new file mode 100644 index 000000000..f120a0146 --- /dev/null +++ b/examples/pkg/generated/applyconfigurationsv2/utils.go @@ -0,0 +1,49 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package applyconfigurationsv2 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + testing "k8s.io/client-go/testing" + + v2 "acme.corp/pkg/apisv2/exampledashed/v2" + exampledashedv2 "acme.corp/pkg/generated/applyconfigurationsv2/exampledashed/v2" + internal "acme.corp/pkg/generated/applyconfigurationsv2/internal" +) + +// 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-dashed.dev, Version=v2 + case v2.SchemeGroupVersion.WithKind("ClusterTestType"): + return &exampledashedv2.ClusterTestTypeApplyConfiguration{} + case v2.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): + return &exampledashedv2.ClusterTestTypeStatusApplyConfiguration{} + case v2.SchemeGroupVersion.WithKind("TestType"): + return &exampledashedv2.TestTypeApplyConfiguration{} + + } + return nil +} + +func NewTypeConverter(scheme *runtime.Scheme) *testing.TypeConverter { + return &testing.TypeConverter{Scheme: scheme, TypeResolver: internal.Parser()} +} diff --git a/examples/pkg/generated/clientsetv2/versioned/clientset.go b/examples/pkg/generated/clientsetv2/versioned/clientset.go new file mode 100644 index 000000000..193631961 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/clientset.go @@ -0,0 +1,121 @@ +/* +Copyright The KCP 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-v0.31. 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" + + exampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + ExampleDashedV2() exampledashedv2.ExampleDashedV2Interface +} + +// Clientset contains the clients for groups. +type Clientset struct { + *discovery.DiscoveryClient + exampleDashedV2 *exampledashedv2.ExampleDashedV2Client +} + +// ExampleDashedV2 retrieves the ExampleDashedV2Client +func (c *Clientset) ExampleDashedV2() exampledashedv2.ExampleDashedV2Interface { + return c.exampleDashedV2 +} + +// 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.exampleDashedV2, err = exampledashedv2.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.exampleDashedV2 = exampledashedv2.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/examples/pkg/generated/clientsetv2/versioned/fake/clientset_generated.go b/examples/pkg/generated/clientsetv2/versioned/fake/clientset_generated.go new file mode 100644 index 000000000..e3dc9547b --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/fake/clientset_generated.go @@ -0,0 +1,90 @@ +/* +Copyright The KCP 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-v0.31. 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 "acme.corp/pkg/generated/clientsetv2/versioned" + exampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" + fakeexampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/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 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 { + 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{} +) + +// ExampleDashedV2 retrieves the ExampleDashedV2Client +func (c *Clientset) ExampleDashedV2() exampledashedv2.ExampleDashedV2Interface { + return &fakeexampledashedv2.FakeExampleDashedV2{Fake: &c.Fake} +} diff --git a/examples/pkg/generated/clientsetv2/versioned/fake/doc.go b/examples/pkg/generated/clientsetv2/versioned/fake/doc.go new file mode 100644 index 000000000..4293c8ce8 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/examples/pkg/generated/clientsetv2/versioned/fake/register.go b/examples/pkg/generated/clientsetv2/versioned/fake/register.go new file mode 100644 index 000000000..5123950e8 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/fake/register.go @@ -0,0 +1,57 @@ +/* +Copyright The KCP 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-v0.31. 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" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + exampledashedv2.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/examples/pkg/generated/clientsetv2/versioned/scheme/doc.go b/examples/pkg/generated/clientsetv2/versioned/scheme/doc.go new file mode 100644 index 000000000..0ba73696d --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/examples/pkg/generated/clientsetv2/versioned/scheme/register.go b/examples/pkg/generated/clientsetv2/versioned/scheme/register.go new file mode 100644 index 000000000..cd523ad85 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/scheme/register.go @@ -0,0 +1,57 @@ +/* +Copyright The KCP 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-v0.31. 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" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + exampledashedv2.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/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/clustertesttype.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..764a22f11 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/clustertesttype.go @@ -0,0 +1,70 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" + + v2 "acme.corp/pkg/apisv2/exampledashed/v2" + scheme "acme.corp/pkg/generated/clientsetv2/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 *v2.ClusterTestType, opts v1.CreateOptions) (*v2.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.UpdateOptions) (*v2.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *v2.ClusterTestType, opts v1.UpdateOptions) (*v2.ClusterTestType, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v2.ClusterTestType, error) + List(ctx context.Context, opts v1.ListOptions) (*v2.ClusterTestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.ClusterTestType, err error) + ClusterTestTypeExpansion +} + +// clusterTestTypes implements ClusterTestTypeInterface +type clusterTestTypes struct { + *gentype.ClientWithList[*v2.ClusterTestType, *v2.ClusterTestTypeList] +} + +// newClusterTestTypes returns a ClusterTestTypes +func newClusterTestTypes(c *ExampleDashedV2Client) *clusterTestTypes { + return &clusterTestTypes{ + gentype.NewClientWithList[*v2.ClusterTestType, *v2.ClusterTestTypeList]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *v2.ClusterTestType { return &v2.ClusterTestType{} }, + func() *v2.ClusterTestTypeList { return &v2.ClusterTestTypeList{} }), + } +} diff --git a/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/doc.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/doc.go new file mode 100644 index 000000000..c2e5631c8 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v2 diff --git a/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/exampledashed_client.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/exampledashed_client.go new file mode 100644 index 000000000..0ffe334b2 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/exampledashed_client.go @@ -0,0 +1,113 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + "net/http" + + rest "k8s.io/client-go/rest" + + v2 "acme.corp/pkg/apisv2/exampledashed/v2" + "acme.corp/pkg/generated/clientsetv2/versioned/scheme" +) + +type ExampleDashedV2Interface interface { + RESTClient() rest.Interface + ClusterTestTypesGetter + TestTypesGetter +} + +// ExampleDashedV2Client is used to interact with features provided by the example-dashed.dev group. +type ExampleDashedV2Client struct { + restClient rest.Interface +} + +func (c *ExampleDashedV2Client) ClusterTestTypes() ClusterTestTypeInterface { + return newClusterTestTypes(c) +} + +func (c *ExampleDashedV2Client) TestTypes(namespace string) TestTypeInterface { + return newTestTypes(c, namespace) +} + +// NewForConfig creates a new ExampleDashedV2Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV2Client, 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 ExampleDashedV2Client 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) (*ExampleDashedV2Client, 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 &ExampleDashedV2Client{client}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV2Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV2Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new ExampleDashedV2Client for the given RESTClient. +func New(c rest.Interface) *ExampleDashedV2Client { + return &ExampleDashedV2Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v2.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 *ExampleDashedV2Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/doc.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/doc.go new file mode 100644 index 000000000..43d633d75 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_clustertesttype.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_clustertesttype.go new file mode 100644 index 000000000..a614ffcf3 --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_clustertesttype.go @@ -0,0 +1,139 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package fake + +import ( + "context" + + v1 "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" + + v2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +// FakeClusterTestTypes implements ClusterTestTypeInterface +type FakeClusterTestTypes struct { + Fake *FakeExampleDashedV2 +} + +var clustertesttypesResource = v2.SchemeGroupVersion.WithResource("clustertesttypes") + +var clustertesttypesKind = v2.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 v1.GetOptions) (result *v2.ClusterTestType, err error) { + emptyResult := &v2.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootGetActionWithOptions(clustertesttypesResource, name, options), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v2.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 v1.ListOptions) (result *v2.ClusterTestTypeList, err error) { + emptyResult := &v2.ClusterTestTypeList{} + obj, err := c.Fake. + Invokes(testing.NewRootListActionWithOptions(clustertesttypesResource, clustertesttypesKind, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v2.ClusterTestTypeList{ListMeta: obj.(*v2.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*v2.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 v1.ListOptions) (watch.Interface, error) { + return c.Fake. + 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 *v2.ClusterTestType, opts v1.CreateOptions) (result *v2.ClusterTestType, err error) { + emptyResult := &v2.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootCreateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v2.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 *v2.ClusterTestType, opts v1.UpdateOptions) (result *v2.ClusterTestType, err error) { + emptyResult := &v2.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootUpdateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v2.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 *v2.ClusterTestType, opts v1.UpdateOptions) (result *v2.ClusterTestType, err error) { + emptyResult := &v2.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "status", clusterTestType, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v2.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 v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v2.ClusterTestType{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionActionWithOptions(clustertesttypesResource, opts, listOpts) + + _, err := c.Fake.Invokes(action, &v2.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 v1.PatchOptions, subresources ...string) (result *v2.ClusterTestType, err error) { + emptyResult := &v2.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, name, pt, data, opts, subresources...), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v2.ClusterTestType), err +} diff --git a/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_exampledashed_client.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_exampledashed_client.go new file mode 100644 index 000000000..86ffcf11a --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_exampledashed_client.go @@ -0,0 +1,45 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package fake + +import ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + + v2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +type FakeExampleDashedV2 struct { + *testing.Fake +} + +func (c *FakeExampleDashedV2) ClusterTestTypes() v2.ClusterTestTypeInterface { + return &FakeClusterTestTypes{c} +} + +func (c *FakeExampleDashedV2) TestTypes(namespace string) v2.TestTypeInterface { + return &FakeTestTypes{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeExampleDashedV2) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_testtype.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_testtype.go new file mode 100644 index 000000000..0bce256ca --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/fake/fake_testtype.go @@ -0,0 +1,172 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package fake + +import ( + "context" + + v1 "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" + + examplev1 "acme.corp/pkg/apis/example/v1" + v2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +// FakeTestTypes implements TestTypeInterface +type FakeTestTypes struct { + Fake *FakeExampleDashedV2 + ns string +} + +var testtypesResource = v2.SchemeGroupVersion.WithResource("testtypes") + +var testtypesKind = v2.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 v1.GetOptions) (result *v2.TestType, err error) { + emptyResult := &v2.TestType{} + obj, err := c.Fake. + Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v2.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 v1.ListOptions) (result *v2.TestTypeList, err error) { + emptyResult := &v2.TestTypeList{} + obj, err := c.Fake. + Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v2.TestTypeList{ListMeta: obj.(*v2.TestTypeList).ListMeta} + for _, item := range obj.(*v2.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 v1.ListOptions) (watch.Interface, error) { + return c.Fake. + 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 *v2.TestType, opts v1.CreateOptions) (result *v2.TestType, err error) { + emptyResult := &v2.TestType{} + obj, err := c.Fake. + Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v2.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 *v2.TestType, opts v1.UpdateOptions) (result *v2.TestType, err error) { + emptyResult := &v2.TestType{} + obj, err := c.Fake. + Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v2.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 v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v2.TestType{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) + + _, err := c.Fake.Invokes(action, &v2.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 v1.PatchOptions, subresources ...string) (result *v2.TestType, err error) { + emptyResult := &v2.TestType{} + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v2.TestType), err +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *FakeTestTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewCreateSubresourceActionWithOptions(testtypesResource, testTypeName, "field", c.ns, field, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *FakeTestTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "field", c.ns, field, opts), &examplev1.Field{}) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *FakeTestTypes) GetField(ctx context.Context, testTypeName string, options v1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewGetSubresourceActionWithOptions(testtypesResource, c.ns, "field", testTypeName, options), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/generated_expansion.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/generated_expansion.go new file mode 100644 index 000000000..233b68adf --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +type ClusterTestTypeExpansion interface{} + +type TestTypeExpansion interface{} diff --git a/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/testtype.go b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/testtype.go new file mode 100644 index 000000000..776b4d8de --- /dev/null +++ b/examples/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2/testtype.go @@ -0,0 +1,117 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" + + examplev1 "acme.corp/pkg/apis/example/v1" + v2 "acme.corp/pkg/apisv2/exampledashed/v2" + scheme "acme.corp/pkg/generated/clientsetv2/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 *v2.TestType, opts v1.CreateOptions) (*v2.TestType, error) + Update(ctx context.Context, testType *v2.TestType, opts v1.UpdateOptions) (*v2.TestType, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v2.TestType, error) + List(ctx context.Context, opts v1.ListOptions) (*v2.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v2.TestType, err error) + CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.CreateOptions) (*examplev1.Field, error) + UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.UpdateOptions) (*examplev1.Field, error) + GetField(ctx context.Context, testTypeName string, options v1.GetOptions) (*examplev1.Field, error) + + TestTypeExpansion +} + +// testTypes implements TestTypeInterface +type testTypes struct { + *gentype.ClientWithList[*v2.TestType, *v2.TestTypeList] +} + +// newTestTypes returns a TestTypes +func newTestTypes(c *ExampleDashedV2Client, namespace string) *testTypes { + return &testTypes{ + gentype.NewClientWithList[*v2.TestType, *v2.TestTypeList]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v2.TestType { return &v2.TestType{} }, + func() *v2.TestTypeList { return &v2.TestTypeList{} }), + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.CreateOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Post(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(field). + Do(ctx). + Into(result) + return +} + +// UpdateField takes the top resource name and the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts v1.UpdateOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Put(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(field). + Do(ctx). + Into(result) + return +} + +// GetField takes name of the testType, and returns the corresponding examplev1.Field object, and an error if there is any. +func (c *testTypes) GetField(ctx context.Context, testTypeName string, options v1.GetOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Get(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} diff --git a/examples/pkg/generated/informersv2/externalversions/exampledashed/interface.go b/examples/pkg/generated/informersv2/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..fd3587d7c --- /dev/null +++ b/examples/pkg/generated/informersv2/externalversions/exampledashed/interface.go @@ -0,0 +1,46 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package exampledashed + +import ( + v2 "acme.corp/pkg/generated/informersv2/externalversions/exampledashed/v2" + internalinterfaces "acme.corp/pkg/generated/informersv2/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V2 provides access to shared informers for resources in V2. + V2() v2.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} +} + +// V2 returns a new v2.Interface. +func (g *group) V2() v2.Interface { + return v2.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/clustertesttype.go b/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..957e5dc8f --- /dev/null +++ b/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/clustertesttype.go @@ -0,0 +1,90 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + "context" + time "time" + + v1 "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" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informersv2/externalversions/internalinterfaces" + v2 "acme.corp/pkg/generated/listersv2/exampledashed/v2" +) + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() v2.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 v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv2.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(&exampledashedv2.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeInformer) Lister() v2.ClusterTestTypeLister { + return v2.NewClusterTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/interface.go b/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/interface.go new file mode 100644 index 000000000..b5f0d8a5e --- /dev/null +++ b/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/interface.go @@ -0,0 +1,52 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + internalinterfaces "acme.corp/pkg/generated/informersv2/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/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/testtype.go b/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/testtype.go new file mode 100644 index 000000000..d737b7a24 --- /dev/null +++ b/examples/pkg/generated/informersv2/externalversions/exampledashed/v2/testtype.go @@ -0,0 +1,91 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + "context" + time "time" + + v1 "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" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informersv2/externalversions/internalinterfaces" + v2 "acme.corp/pkg/generated/listersv2/exampledashed/v2" +) + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() v2.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 v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &exampledashedv2.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(&exampledashedv2.TestType{}, f.defaultInformer) +} + +func (f *testTypeInformer) Lister() v2.TestTypeLister { + return v2.NewTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informersv2/externalversions/factory.go b/examples/pkg/generated/informersv2/externalversions/factory.go new file mode 100644 index 000000000..05b5bb54f --- /dev/null +++ b/examples/pkg/generated/informersv2/externalversions/factory.go @@ -0,0 +1,263 @@ +/* +Copyright The KCP 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-v0.31. 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 "acme.corp/pkg/generated/clientset/versioned" + exampledashed "acme.corp/pkg/generated/informersv2/externalversions/exampledashed" + internalinterfaces "acme.corp/pkg/generated/informersv2/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. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. + 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 + + ExampleDashed() exampledashed.Interface +} + +func (f *sharedInformerFactory) ExampleDashed() exampledashed.Interface { + return exampledashed.New(f, f.namespace, f.tweakListOptions) +} diff --git a/examples/pkg/generated/informersv2/externalversions/generic.go b/examples/pkg/generated/informersv2/externalversions/generic.go new file mode 100644 index 000000000..26b88c8b8 --- /dev/null +++ b/examples/pkg/generated/informersv2/externalversions/generic.go @@ -0,0 +1,65 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + + v2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +// 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-dashed.dev, Version=v2 + case v2.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V2().ClusterTestTypes().Informer()}, nil + case v2.SchemeGroupVersion.WithResource("testtypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V2().TestTypes().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/examples/pkg/generated/informersv2/externalversions/internalinterfaces/factory_interfaces.go b/examples/pkg/generated/informersv2/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 000000000..392f91887 --- /dev/null +++ b/examples/pkg/generated/informersv2/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,41 @@ +/* +Copyright The KCP 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-v0.31. 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 "acme.corp/pkg/generated/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/examples/pkg/generated/listersv2/exampledashed/v2/clustertesttype.go b/examples/pkg/generated/listersv2/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..5c8b0a3a6 --- /dev/null +++ b/examples/pkg/generated/listersv2/exampledashed/v2/clustertesttype.go @@ -0,0 +1,49 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" + "k8s.io/client-go/tools/cache" + + v2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +// 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 []*v2.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) (*v2.ClusterTestType, error) + ClusterTestTypeListerExpansion +} + +// clusterTestTypeLister implements the ClusterTestTypeLister interface. +type clusterTestTypeLister struct { + listers.ResourceIndexer[*v2.ClusterTestType] +} + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{listers.New[*v2.ClusterTestType](indexer, v2.Resource("clustertesttype"))} +} diff --git a/examples/pkg/generated/listersv2/exampledashed/v2/expansion_generated.go b/examples/pkg/generated/listersv2/exampledashed/v2/expansion_generated.go new file mode 100644 index 000000000..f839dcae1 --- /dev/null +++ b/examples/pkg/generated/listersv2/exampledashed/v2/expansion_generated.go @@ -0,0 +1,31 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +// 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/examples/pkg/generated/listersv2/exampledashed/v2/testtype.go b/examples/pkg/generated/listersv2/exampledashed/v2/testtype.go new file mode 100644 index 000000000..688f77db4 --- /dev/null +++ b/examples/pkg/generated/listersv2/exampledashed/v2/testtype.go @@ -0,0 +1,71 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v2 + +import ( + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" + "k8s.io/client-go/tools/cache" + + v2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +// 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 []*v2.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 { + listers.ResourceIndexer[*v2.TestType] +} + +// NewTestTypeLister returns a new TestTypeLister. +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{listers.New[*v2.TestType](indexer, v2.Resource("testtype"))} +} + +// TestTypes returns an object that can list and get TestTypes. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return testTypeNamespaceLister{listers.NewNamespaced[*v2.TestType](s.ResourceIndexer, 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 []*v2.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) (*v2.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + listers.ResourceIndexer[*v2.TestType] +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go index 5905b6d77..b2df4fb09 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go @@ -41,8 +41,8 @@ import ( example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "ClusterTestType"} +var clusterTestTypesResource = schema.GroupVersionResource{Group: "example3", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "example3", Version: "v1", Kind: "ClusterTestType"} type clusterTestTypesClusterClient struct { *kcptesting.Fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/testtype.go index a48cedad0..2ba9d3e93 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake/testtype.go @@ -43,8 +43,8 @@ import ( kcpexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" ) -var testTypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "TestType"} +var testTypesResource = schema.GroupVersionResource{Group: "example3", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "example3", Version: "v1", Kind: "TestType"} type testTypesClusterClient struct { *kcptesting.Fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go index 3db29e205..6565741d3 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go @@ -41,8 +41,8 @@ import ( existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "ClusterTestType"} +var clusterTestTypesResource = schema.GroupVersionResource{Group: "existinginterfaces", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "existinginterfaces", Version: "v1", Kind: "ClusterTestType"} type clusterTestTypesClusterClient struct { *kcptesting.Fake diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go index 8279dd6a9..ed63eca60 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go @@ -42,8 +42,8 @@ import ( kcpexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" ) -var testTypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "TestType"} +var testTypesResource = schema.GroupVersionResource{Group: "existinginterfaces", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "existinginterfaces", Version: "v1", Kind: "TestType"} type testTypesClusterClient struct { *kcptesting.Fake diff --git a/examples/pkg/kcp/clients/informers/externalversions/factory.go b/examples/pkg/kcp/clients/informers/externalversions/factory.go index f6fafbfef..f1b34d929 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcp/clients/informers/externalversions/factory.go @@ -272,18 +272,33 @@ type SharedInformerFactory interface { // InformerFor returns the SharedIndexInformer for obj. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer - Example() exampleinformers.ClusterInterface Example3() example3informers.ClusterInterface + Example() exampleinformers.ClusterInterface + Example() exampleinformers.ClusterInterface + Example() exampleinformers.ClusterInterface + Example() exampleinformers.ClusterInterface Existinginterfaces() existinginterfacesinformers.ClusterInterface Secondexample() secondexampleinformers.ClusterInterface } +func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { + return example3informers.New(f, f.tweakListOptions) +} + func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { return exampleinformers.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { - return example3informers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { + return exampleinformers.New(f, f.tweakListOptions) +} + +func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { + return exampleinformers.New(f, f.tweakListOptions) +} + +func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { + return exampleinformers.New(f, f.tweakListOptions) } func (f *sharedInformerFactory) Existinginterfaces() existinginterfacesinformers.ClusterInterface { @@ -438,18 +453,33 @@ type SharedScopedInformerFactory interface { ForResource(resource schema.GroupVersionResource) (GenericInformer, error) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - Example() exampleinformers.Interface Example3() example3informers.Interface + Example() exampleinformers.Interface + Example() exampleinformers.Interface + Example() exampleinformers.Interface + Example() exampleinformers.Interface Existinginterfaces() existinginterfacesinformers.Interface Secondexample() secondexampleinformers.Interface } +func (f *sharedScopedInformerFactory) Example3() example3informers.Interface { + return example3informers.NewScoped(f, f.namespace, f.tweakListOptions) +} + func (f *sharedScopedInformerFactory) Example() exampleinformers.Interface { return exampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) } -func (f *sharedScopedInformerFactory) Example3() example3informers.Interface { - return example3informers.NewScoped(f, f.namespace, f.tweakListOptions) +func (f *sharedScopedInformerFactory) Example() exampleinformers.Interface { + return exampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) +} + +func (f *sharedScopedInformerFactory) Example() exampleinformers.Interface { + return exampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) +} + +func (f *sharedScopedInformerFactory) Example() exampleinformers.Interface { + return exampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) } func (f *sharedScopedInformerFactory) Existinginterfaces() existinginterfacesinformers.Interface { diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/clientset.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/clientset.go new file mode 100644 index 000000000..ccd35a69d --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/clientset.go @@ -0,0 +1,137 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package exampledashed + +import ( + "fmt" + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/discovery" + "k8s.io/client-go/rest" + "k8s.io/client-go/util/flowcontrol" + + client "acme.corp/pkg/generated/clientsetv2/versioned" + exampledashedv2 "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2" +) + +type ClusterInterface interface { + Cluster(logicalcluster.Path) client.Interface + Discovery() discovery.DiscoveryInterface + ExampleDashedV2() exampledashedv2.ExampleDashedV2ClusterInterface +} + +// ClusterClientset contains the clients for groups. +type ClusterClientset struct { + *discovery.DiscoveryClient + clientCache kcpclient.Cache[*client.Clientset] + exampledashedV2 *exampledashedv2.ExampleDashedV2ClusterClient +} + +// Discovery retrieves the DiscoveryClient +func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// ExampleDashedV2 retrieves the ExampleDashedV2ClusterClient. +func (c *ClusterClientset) ExampleDashedV2() exampledashedv2.ExampleDashedV2ClusterInterface { + return c.exampledashedV2 +} + +// Cluster scopes this clientset to one cluster. +func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +// NewForConfig creates a new ClusterClientset 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) (*ClusterClientset, 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 ClusterClientset 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) (*ClusterClientset, 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) + } + + cache := kcpclient.NewCache(c, httpClient, &kcpclient.Constructor[*client.Clientset]{ + NewForConfigAndClient: client.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + + var cs ClusterClientset + cs.clientCache = cache + var err error + cs.exampledashedV2, err = exampledashedv2.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 ClusterClientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ClusterClientset { + cs, err := NewForConfig(c) + if err != nil { + panic(err) + } + return cs +} diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/fake/clientset.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/fake/clientset.go new file mode 100644 index 000000000..b3992ff46 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/fake/clientset.go @@ -0,0 +1,114 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "github.com/kcp-dev/logicalcluster/v3" + + kcpfakediscovery "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/discovery" + + client "acme.corp/pkg/generated/clientsetv2/versioned" + clientscheme "acme.corp/pkg/generated/clientsetv2/versioned/scheme" + exampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" + kcpclient "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned" + kcpexampledashedv2 "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2" + fakeexampledashedv2 "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/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) *ClusterClientset { + o := kcptesting.NewObjectTracker(clientscheme.Scheme, clientscheme.Codecs.UniversalDecoder()) + o.AddAll(objects...) + + cs := &ClusterClientset{Fake: &kcptesting.Fake{}, tracker: o} + cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: cs.Fake, ClusterPath: logicalcluster.Wildcard} + cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) + cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) + + return cs +} + +var _ kcpclient.ClusterInterface = (*ClusterClientset)(nil) + +// ClusterClientset contains the clients for groups. +type ClusterClientset struct { + *kcptesting.Fake + discovery *kcpfakediscovery.FakeDiscovery + tracker kcptesting.ObjectTracker +} + +// Discovery retrieves the DiscoveryClient +func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { + return c.tracker +} + +// ExampleDashedV2 retrieves the ExampleDashedV2ClusterClient. +func (c *ClusterClientset) ExampleDashedV2() kcpexampledashedv2.ExampleDashedV2ClusterInterface { + return &fakeexampledashedv2.ExampleDashedV2ClusterClient{Fake: c.Fake} +} + +// Cluster scopes this clientset to one cluster. +func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &Clientset{ + Fake: c.Fake, + discovery: &kcpfakediscovery.FakeDiscovery{Fake: c.Fake, ClusterPath: clusterPath}, + tracker: c.tracker.Cluster(clusterPath), + clusterPath: clusterPath, + } +} + +var _ client.Interface = (*Clientset)(nil) + +// Clientset contains the clients for groups. +type Clientset struct { + *kcptesting.Fake + discovery *kcpfakediscovery.FakeDiscovery + tracker kcptesting.ScopedObjectTracker + clusterPath logicalcluster.Path +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { + return c.tracker +} + +// ExampleDashedV2 retrieves the ExampleDashedV2Client. +func (c *Clientset) ExampleDashedV2() exampledashedv2.ExampleDashedV2Interface { + return &fakeexampledashedv2.ExampleDashedV2Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/scheme/register.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/scheme/register.go new file mode 100644 index 000000000..ba0423b10 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/scheme/register.go @@ -0,0 +1,60 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package scheme + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + exampledashedv2.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() { + metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(Scheme)) +} diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/clustertesttype.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..464212a40 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/clustertesttype.go @@ -0,0 +1,72 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "context" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + exampledashedv2client "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +// ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. +// A group's cluster client should implement this interface. +type ClusterTestTypesClusterGetter interface { + ClusterTestTypes() ClusterTestTypeClusterInterface +} + +// ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, +// or scope down to one cluster and return a exampledashedv2client.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) exampledashedv2client.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv2client.ExampleDashedV2Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv2client.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return c.clientCache.ClusterOrDie(clusterPath).ClusterTestTypes() +} + +// List returns the entire collection of all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.ClusterTestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) +} + +// Watch begins to watch all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) +} diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/exampledashed_client.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/exampledashed_client.go new file mode 100644 index 000000000..f944ca048 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/exampledashed_client.go @@ -0,0 +1,95 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + exampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +type ExampleDashedV2ClusterInterface interface { + ExampleDashedV2ClusterScoper + TestTypesClusterGetter + ClusterTestTypesClusterGetter +} + +type ExampleDashedV2ClusterScoper interface { + Cluster(logicalcluster.Path) exampledashedv2.ExampleDashedV2Interface +} + +type ExampleDashedV2ClusterClient struct { + clientCache kcpclient.Cache[*exampledashedv2.ExampleDashedV2Client] +} + +func (c *ExampleDashedV2ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv2.ExampleDashedV2Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *ExampleDashedV2ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *ExampleDashedV2ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new ExampleDashedV2ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV2ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new ExampleDashedV2ClusterClient 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) (*ExampleDashedV2ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*exampledashedv2.ExampleDashedV2Client]{ + NewForConfigAndClient: exampledashedv2.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &ExampleDashedV2ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV2ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV2ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/clustertesttype.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/clustertesttype.go new file mode 100644 index 000000000..e15823fa9 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/clustertesttype.go @@ -0,0 +1,202 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + applyconfigurationsexampledashedv2 "acme.corp/pkg/generated/applyconfigurationsv2/exampledashed/v2" + exampledashedv2client "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "exampledashed", Version: "v2", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "exampledashed", Version: "v2", Kind: "ClusterTestType"} + +type clusterTestTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv2client.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. +func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &exampledashedv2.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv2.ClusterTestTypeList{ListMeta: obj.(*exampledashedv2.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv2.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 across all clusters. +func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +} + +type clusterTestTypesClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *exampledashedv2.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *exampledashedv2.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *exampledashedv2.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &exampledashedv2.ClusterTestType{}) + return err +} + +func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) + + _, err := c.Fake.Invokes(action, &exampledashedv2.ClusterTestTypeList{}) + return err +} + +func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. +func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &exampledashedv2.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv2.ClusterTestTypeList{ListMeta: obj.(*exampledashedv2.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv2.ClusterTestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) +} + +func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv2.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv2.ClusterTestType, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv2.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv2.ClusterTestType, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/exampledashed_client.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/exampledashed_client.go new file mode 100644 index 000000000..53cea8cfe --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/exampledashed_client.go @@ -0,0 +1,73 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "k8s.io/client-go/rest" + + exampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" + kcpexampledashedv2 "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2" +) + +var _ kcpexampledashedv2.ExampleDashedV2ClusterInterface = (*ExampleDashedV2ClusterClient)(nil) + +type ExampleDashedV2ClusterClient struct { + *kcptesting.Fake +} + +func (c *ExampleDashedV2ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv2.ExampleDashedV2Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &ExampleDashedV2Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *ExampleDashedV2ClusterClient) TestTypes() kcpexampledashedv2.TestTypeClusterInterface { + return &testTypesClusterClient{Fake: c.Fake} +} + +func (c *ExampleDashedV2ClusterClient) ClusterTestTypes() kcpexampledashedv2.ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterClient{Fake: c.Fake} +} + +var _ exampledashedv2.ExampleDashedV2Interface = (*ExampleDashedV2Client)(nil) + +type ExampleDashedV2Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *ExampleDashedV2Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *ExampleDashedV2Client) TestTypes(namespace string) exampledashedv2.TestTypeInterface { + return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} + +func (c *ExampleDashedV2Client) ClusterTestTypes() exampledashedv2.ClusterTestTypeInterface { + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/testtype.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/testtype.go new file mode 100644 index 000000000..ee494cd8b --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/testtype.go @@ -0,0 +1,238 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" + + examplev1 "acme.corp/pkg/apis/example/v1" + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + applyconfigurationsexampledashedv2 "acme.corp/pkg/generated/applyconfigurationsv2/exampledashed/v2" + exampledashedv2client "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" + kcpexampledashedv2 "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2" +) + +var testTypesResource = schema.GroupVersionResource{Group: "exampledashed", Version: "v2", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "exampledashed", Version: "v2", Kind: "TestType"} + +type testTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexampledashedv2.TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. +func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &exampledashedv2.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv2.TestTypeList{ListMeta: obj.(*exampledashedv2.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv2.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 across all clusters. +func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +} + +type testTypesNamespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv2client.TestTypeInterface { + return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +} + +type testTypesClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path + Namespace string +} + +func (c *testTypesClient) Create(ctx context.Context, testType *exampledashedv2.TestType, opts metav1.CreateOptions) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) Update(ctx context.Context, testType *exampledashedv2.TestType, opts metav1.UpdateOptions) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *exampledashedv2.TestType, opts metav1.UpdateOptions) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &exampledashedv2.TestType{}) + return err +} + +func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) + + _, err := c.Fake.Invokes(action, &exampledashedv2.TestTypeList{}) + return err +} + +func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &exampledashedv2.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv2.TestTypeList{ListMeta: obj.(*exampledashedv2.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv2.TestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) +} + +func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv2.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv2.TestType, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv2.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv2.TestType, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(testTypesResource, c.ClusterPath, testTypeName, "field", c.Namespace, field), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} + +func (c *testTypesClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, field), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} + +func (c *testTypesClient) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, testTypeName), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/testtype.go b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/testtype.go new file mode 100644 index 000000000..f4ab97ac7 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/exampledashed/versioned/typed/exampledashed/v2/testtype.go @@ -0,0 +1,86 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "context" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + exampledashedv2client "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +// TestTypesClusterGetter has a method to return a TestTypeClusterInterface. +// A group's cluster client should implement this interface. +type TestTypesClusterGetter interface { + TestTypes() TestTypeClusterInterface +} + +// TestTypeClusterInterface can operate on TestTypes across all clusters, +// or scope down to one cluster and return a TestTypesNamespacer. +type TestTypeClusterInterface interface { + Cluster(logicalcluster.Path) TestTypesNamespacer + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv2client.ExampleDashedV2Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} +} + +// List returns the entire collection of all TestTypes across all clusters. +func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all TestTypes across all clusters. +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +} + +// TestTypesNamespacer can scope to objects within a namespace, returning a exampledashedv2client.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) exampledashedv2client.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*exampledashedv2client.ExampleDashedV2Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv2client.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/interface.go b/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..cfddbb62f --- /dev/null +++ b/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/interface.go @@ -0,0 +1,68 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package exampledashed + +import ( + "acme.corp/pkg/kcp/clientsv2/informers/externalversions/example-dashed/v2" + "acme.corp/pkg/kcp/clientsv2/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // V2 provides access to the shared informers in V2. + V2() v2.ClusterInterface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &group{factory: f, tweakListOptions: tweakListOptions} +} + +// V2 returns a new v2.ClusterInterface. +func (g *group) V2() v2.ClusterInterface { + return v2.New(g.factory, g.tweakListOptions) +} + +type Interface interface { + // V2 provides access to the shared informers in V2. + V2() v2.Interface +} + +type scopedGroup struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// New returns a new Interface. +func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V2 returns a new v2.ClusterInterface. +func (g *scopedGroup) V2() v2.Interface { + return v2.NewScoped(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/clustertesttype.go b/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..a6cbcf352 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/clustertesttype.go @@ -0,0 +1,179 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "context" + "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + scopedclientset "acme.corp/pkg/generated/clientsetv2/versioned" + clientset "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned" + "acme.corp/pkg/kcp/clientsv2/informers/externalversions/internalinterfaces" + exampledashedv2listers "acme.corp/pkg/kcp/clientsv2/listers/exampledashed/v2" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv2listers.ClusterTestTypeClusterLister +} + +type clusterTestTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeClusterInformer 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 NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeClusterInformer 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 NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv2.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + }, + f.tweakListOptions, + ) +} + +func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&exampledashedv2.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeClusterInformer) Lister() exampledashedv2listers.ClusterTestTypeClusterLister { + return exampledashedv2listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv2listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type clusterTestTypeInformer struct { + informer cache.SharedIndexInformer + lister exampledashedv2listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *clusterTestTypeInformer) Lister() exampledashedv2listers.ClusterTestTypeLister { + return f.lister +} + +type clusterTestTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&exampledashedv2.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeScopedInformer) Lister() exampledashedv2listers.ClusterTestTypeLister { + return exampledashedv2listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) +} + +// 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 scopedclientset.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 scopedclientset.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.ExampleDashedV2().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv2.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +} diff --git a/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/interface.go b/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/interface.go new file mode 100644 index 000000000..8a89ff05b --- /dev/null +++ b/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/interface.go @@ -0,0 +1,81 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "acme.corp/pkg/kcp/clientsv2/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // TestTypes returns a TestTypeClusterInformer + TestTypes() TestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer + ClusterTestTypes() ClusterTestTypeClusterInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &version{factory: f, tweakListOptions: tweakListOptions} +} + +// TestTypes returns a TestTypeClusterInformer +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeClusterInformer +func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { + return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +type Interface interface { + // TestTypes returns a TestTypeInformer + TestTypes() TestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer + ClusterTestTypes() ClusterTestTypeInformer +} + +type scopedVersion struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// New returns a new ClusterInterface. +func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// TestTypes returns a TestTypeInformer +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeInformer +func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { + return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/testtype.go b/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/testtype.go new file mode 100644 index 000000000..1085ecc76 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/informers/externalversions/exampledashed/v2/testtype.go @@ -0,0 +1,182 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "context" + "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + scopedclientset "acme.corp/pkg/generated/clientsetv2/versioned" + clientset "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned" + "acme.corp/pkg/kcp/clientsv2/informers/externalversions/internalinterfaces" + exampledashedv2listers "acme.corp/pkg/kcp/clientsv2/listers/exampledashed/v2" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv2listers.TestTypeClusterLister +} + +type testTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTestTypeClusterInformer 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 NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeClusterInformer 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 NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().TestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().TestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv2.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, + f.tweakListOptions, + ) +} + +func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&exampledashedv2.TestType{}, f.defaultInformer) +} + +func (f *testTypeClusterInformer) Lister() exampledashedv2listers.TestTypeClusterLister { + return exampledashedv2listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv2listers.TestTypeLister +} + +func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister exampledashedv2listers.TestTypeLister +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *testTypeInformer) Lister() exampledashedv2listers.TestTypeLister { + return f.lister +} + +type testTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&exampledashedv2.TestType{}, f.defaultInformer) +} + +func (f *testTypeScopedInformer) Lister() exampledashedv2listers.TestTypeLister { + return exampledashedv2listers.NewTestTypeLister(f.Informer().GetIndexer()) +} + +// 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 scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, 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 scopedclientset.Interface, resyncPeriod time.Duration, namespace string, 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.ExampleDashedV2().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &exampledashedv2.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, f.namespace, cache.Indexers{ + cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, + }, f.tweakListOptions) +} diff --git a/examples/pkg/kcp/clientsv2/informers/externalversions/factory.go b/examples/pkg/kcp/clientsv2/informers/externalversions/factory.go new file mode 100644 index 000000000..8aece6af3 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/informers/externalversions/factory.go @@ -0,0 +1,428 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package informers + +import ( + "reflect" + "sync" + "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/tools/cache" + + scopedclientset "acme.corp/pkg/generated/clientsetv2/versioned" + clientset "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned" + exampledashedinformers "acme.corp/pkg/kcp/clientsv2/informers/externalversions/exampledashed" + "acme.corp/pkg/kcp/clientsv2/informers/externalversions/internalinterfaces" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*SharedInformerOptions) *SharedInformerOptions + +type SharedInformerOptions struct { + customResync map[reflect.Type]time.Duration + tweakListOptions internalinterfaces.TweakListOptionsFunc + transform cache.TransformFunc + namespace string +} + +type sharedInformerFactory struct { + client clientset.ClusterInterface + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + transform cache.TransformFunc + + informers map[reflect.Type]kcpcache.ScopeableSharedIndexInformer + // 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[metav1.Object]time.Duration) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + for k, v := range resyncConfig { + opts.customResync[reflect.TypeOf(k)] = v + } + return opts + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.tweakListOptions = tweakListOptions + return opts + } +} + +// WithTransform sets a transform on all informers. +func WithTransform(transform cache.TransformFunc) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.transform = transform + return opts + } +} + +// NewSharedInformerFactory constructs a new instance of SharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client clientset.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + defaultResync: defaultResync, + informers: make(map[reflect.Type]kcpcache.ScopeableSharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + opts := &SharedInformerOptions{ + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + opts = opt(opts) + } + + // Forward options to the factory + factory.customResync = opts.customResync + factory.tweakListOptions = opts.tweakListOptions + factory.transform = opts.transform + + return factory +} + +// Start initializes all requested informers. +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() +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]kcpcache.ScopeableSharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]kcpcache.ScopeableSharedIndexInformer{} + 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. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer { + 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) + f.informers[informerType] = informer + + return informer +} + +type ScopedDynamicSharedInformerFactory interface { + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + + // Start initializes all requested informers. They are handled in goroutines + // which run until the stop channel gets closed. + Start(stopCh <-chan struct{}) +} + +// 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 := NewSharedInformerFactoryWithOptions(client, resyncPeriod) +// defer factory.Shutdown() // 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 + + Cluster(logicalcluster.Name) ScopedDynamicSharedInformerFactory + + // 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() + + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) + + // WaitForCacheSync blocks until all started informers' caches were synced + // or the stop channel gets closed. + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + // InformerFor returns the SharedIndexInformer for obj. + InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer + + ExampleDashed() exampledashedinformers.ClusterInterface +} + +func (f *sharedInformerFactory) ExampleDashed() exampledashedinformers.ClusterInterface { + return exampledashedinformers.New(f, f.tweakListOptions) +} + +func (f *sharedInformerFactory) Cluster(clusterName logicalcluster.Name) ScopedDynamicSharedInformerFactory { + return &scopedDynamicSharedInformerFactory{ + sharedInformerFactory: f, + clusterName: clusterName, + } +} + +type scopedDynamicSharedInformerFactory struct { + *sharedInformerFactory + clusterName logicalcluster.Name +} + +func (f *scopedDynamicSharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + clusterInformer, err := f.sharedInformerFactory.ForResource(resource) + if err != nil { + return nil, err + } + return clusterInformer.Cluster(f.clusterName), nil +} + +func (f *scopedDynamicSharedInformerFactory) Start(stopCh <-chan struct{}) { + f.sharedInformerFactory.Start(stopCh) +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.namespace = namespace + return opts + } +} + +type sharedScopedInformerFactory struct { + client scopedclientset.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 +} + +// NewSharedScopedInformerFactory constructs a new instance of SharedInformerFactory for some or all namespaces. +func NewSharedScopedInformerFactory(client scopedclientset.Interface, defaultResync time.Duration, namespace string) SharedScopedInformerFactory { + return NewSharedScopedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace)) +} + +// NewSharedScopedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedScopedInformerFactoryWithOptions(client scopedclientset.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedScopedInformerFactory { + factory := &sharedScopedInformerFactory{ + client: client, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + opts := &SharedInformerOptions{ + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + opts = opt(opts) + } + + // Forward options to the factory + factory.customResync = opts.customResync + factory.tweakListOptions = opts.tweakListOptions + factory.namespace = opts.namespace + + return factory +} + +// Start initializes all requested informers. +func (f *sharedScopedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedScopedInformerFactory) 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. +func (f *sharedScopedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewScopedInformerFunc) 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 +} + +// SharedScopedInformerFactory provides shared informers for resources in all known +// API group versions, scoped to one workspace. +type SharedScopedInformerFactory interface { + internalinterfaces.SharedScopedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + ExampleDashed() exampledashedinformers.Interface +} + +func (f *sharedScopedInformerFactory) ExampleDashed() exampledashedinformers.Interface { + return exampledashedinformers.NewScoped(f, f.namespace, f.tweakListOptions) +} diff --git a/examples/pkg/kcp/clientsv2/informers/externalversions/generic.go b/examples/pkg/kcp/clientsv2/informers/externalversions/generic.go new file mode 100644 index 000000000..5d4cbfca5 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/informers/externalversions/generic.go @@ -0,0 +1,113 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package informers + +import ( + "fmt" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/example-dashed/v2" +) + +type GenericClusterInformer interface { + Cluster(logicalcluster.Name) GenericInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() kcpcache.GenericClusterLister +} + +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericClusterInformer struct { + informer kcpcache.ScopeableSharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.informer +} + +// Lister returns the GenericClusterLister. +func (f *genericClusterInformer) Lister() kcpcache.GenericClusterLister { + return kcpcache.NewGenericClusterLister(f.Informer().GetIndexer(), f.resource) +} + +// Cluster scopes to a GenericInformer. +func (f *genericClusterInformer) Cluster(clusterName logicalcluster.Name) GenericInformer { + return &genericInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().ByCluster(clusterName), + } +} + +type genericInformer struct { + informer cache.SharedIndexInformer + lister cache.GenericLister +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return f.lister +} + +// 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) (GenericClusterInformer, error) { + switch resource { + // Group=example-dashed.dev, Version=V2 + case exampledashedv2.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V2().TestTypes().Informer()}, nil + case exampledashedv2.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V2().ClusterTestTypes().Informer()}, nil + } + + return nil, fmt.Errorf("no informer found for %v", 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 *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=example-dashed.dev, Version=V2 + case exampledashedv2.SchemeGroupVersion.WithResource("testtypes"): + informer := f.ExampleDashed().V2().TestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + case exampledashedv2.SchemeGroupVersion.WithResource("clustertesttypes"): + informer := f.ExampleDashed().V2().ClusterTestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/examples/pkg/kcp/clientsv2/informers/externalversions/internalinterfaces/factory_interfaces.go b/examples/pkg/kcp/clientsv2/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 000000000..d00259625 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,56 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/tools/cache" + + scopedclientset "acme.corp/pkg/generated/clientsetv2/versioned" + clientset "acme.corp/pkg/kcp/clientsv2/exampledashed/versioned" +) + +// NewInformerFunc takes clientset.ClusterInterface and time.Duration to return a ScopeableSharedIndexInformer. +type NewInformerFunc func(clientset.ClusterInterface, time.Duration) kcpcache.ScopeableSharedIndexInformer + +// 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) kcpcache.ScopeableSharedIndexInformer +} + +// NewScopedInformerFunc takes scopedclientset.Interface and time.Duration to return a SharedIndexInformer. +type NewScopedInformerFunc func(scopedclientset.Interface, time.Duration) cache.SharedIndexInformer + +// SharedScopedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedScopedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewScopedInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a metav1.ListOptions. +type TweakListOptionsFunc func(*metav1.ListOptions) diff --git a/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/clustertesttype.go b/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..0d91d9d6d --- /dev/null +++ b/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/clustertesttype.go @@ -0,0 +1,143 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type ClusterTestTypeClusterLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv2.ClusterTestType, err error) + // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister + ClusterTestTypeClusterListerExpansion +} + +type clusterTestTypeClusterLister struct { + indexer cache.Indexer +} + +// NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{indexer: indexer} +} + +// List lists all ClusterTestTypes in the indexer across all workspaces. +func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv2.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv2.ClusterTestType)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. +// All objects returned here must be treated as read-only. +type ClusterTestTypeLister interface { + // List lists all ClusterTestTypes in the workspace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv2.ClusterTestType, err error) + // Get retrieves the ClusterTestType from the indexer for a given workspace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*exampledashedv2.ClusterTestType, error) + ClusterTestTypeListerExpansion +} + +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. +type clusterTestTypeLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all ClusterTestTypes in the indexer for a workspace. +func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*exampledashedv2.ClusterTestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeLister) Get(name string) (*exampledashedv2.ClusterTestType, error) { + key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv2.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv2.ClusterTestType), nil +} + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a workspace-scoped LIST+WATCH +// - uses cache.MetaNamespaceKeyFunc as the key function +func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { + return &clusterTestTypeScopedLister{indexer: indexer} +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +type clusterTestTypeScopedLister struct { + indexer cache.Indexer +} + +// List lists all ClusterTestTypes in the indexer for a workspace. +func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*exampledashedv2.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeScopedLister) Get(name string) (*exampledashedv2.ClusterTestType, error) { + key := name + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv2.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv2.ClusterTestType), nil +} diff --git a/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/clustertesttype_expansion.go b/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/clustertesttype_expansion.go new file mode 100644 index 000000000..2ce875217 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/clustertesttype_expansion.go @@ -0,0 +1,28 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} diff --git a/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/testtype.go b/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/testtype.go new file mode 100644 index 000000000..efa7fb924 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/testtype.go @@ -0,0 +1,196 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type TestTypeClusterLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) TestTypeLister + TestTypeClusterListerExpansion +} + +type testTypeClusterLister struct { + indexer cache.Indexer +} + +// NewTestTypeClusterLister returns a new TestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { + return &testTypeClusterLister{indexer: indexer} +} + +// List lists all TestTypes in the indexer across all workspaces. +func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv2.TestType)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the workspace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) + // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// testTypeLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +type testTypeLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all TestTypes in the indexer for a workspace. +func (s *testTypeLister) List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, 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 workspace and namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) + // Get retrieves the TestType from the indexer for a given workspace, namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*exampledashedv2.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister helps list and get TestTypes. +// All objects returned here must be treated as read-only. +type testTypeNamespaceLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name + namespace string +} + +// List lists all TestTypes in the indexer for a given workspace and namespace. +func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv2.TestType, error) { + key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv2.Resource("testtypes"), name) + } + return obj.(*exampledashedv2.TestType), nil +} + +// NewTestTypeLister returns a new TestTypeLister. +// We assume that the indexer: +// - is fed by a workspace-scoped LIST+WATCH +// - uses cache.MetaNamespaceKeyFunc as the key function +// - has the cache.NamespaceIndex as an index +func NewTestTypeLister(indexer cache.Indexer) *testTypeScopedLister { + return &testTypeScopedLister{indexer: indexer} +} + +// testTypeScopedLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +type testTypeScopedLister struct { + indexer cache.Indexer +} + +// List lists all TestTypes in the indexer for a workspace. +func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (s *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeScopedNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// testTypeScopedNamespaceLister helps list and get TestTypes. +type testTypeScopedNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all TestTypes in the indexer for a given workspace and namespace. +func (s *testTypeScopedNamespaceLister) List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeScopedNamespaceLister) Get(name string) (*exampledashedv2.TestType, error) { + key := s.namespace + "/" + name + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv2.Resource("testtypes"), name) + } + return obj.(*exampledashedv2.TestType), nil +} diff --git a/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/testtype_expansion.go b/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/testtype_expansion.go new file mode 100644 index 000000000..3c8c5b8e7 --- /dev/null +++ b/examples/pkg/kcp/clientsv2/listers/exampledashed/v2/testtype_expansion.go @@ -0,0 +1,31 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +type TestTypeClusterListerExpansion 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/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go index 5905b6d77..b2df4fb09 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/clustertesttype.go @@ -41,8 +41,8 @@ import ( example3v1client "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "ClusterTestType"} +var clusterTestTypesResource = schema.GroupVersionResource{Group: "example3", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "example3", Version: "v1", Kind: "ClusterTestType"} type clusterTestTypesClusterClient struct { *kcptesting.Fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/testtype.go index 4c24bdd12..133363201 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake/testtype.go @@ -43,8 +43,8 @@ import ( kcpexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" ) -var testTypesResource = schema.GroupVersionResource{Group: "example3.some.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "example3.some.corp", Version: "v1", Kind: "TestType"} +var testTypesResource = schema.GroupVersionResource{Group: "example3", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "example3", Version: "v1", Kind: "TestType"} type testTypesClusterClient struct { *kcptesting.Fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go index 3db29e205..6565741d3 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/clustertesttype.go @@ -41,8 +41,8 @@ import ( existinginterfacesv1client "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" ) -var clusterTestTypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "clustertesttypes"} -var clusterTestTypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "ClusterTestType"} +var clusterTestTypesResource = schema.GroupVersionResource{Group: "existinginterfaces", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "existinginterfaces", Version: "v1", Kind: "ClusterTestType"} type clusterTestTypesClusterClient struct { *kcptesting.Fake diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go index b0e7bc947..852b7ddfb 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake/testtype.go @@ -42,8 +42,8 @@ import ( kcpexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" ) -var testTypesResource = schema.GroupVersionResource{Group: "existinginterfaces.acme.corp", Version: "v1", Resource: "testtypes"} -var testTypesKind = schema.GroupVersionKind{Group: "existinginterfaces.acme.corp", Version: "v1", Kind: "TestType"} +var testTypesResource = schema.GroupVersionResource{Group: "existinginterfaces", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "existinginterfaces", Version: "v1", Kind: "TestType"} type testTypesClusterClient struct { *kcptesting.Fake diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go index d0645ef3f..90dfe1eb0 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go @@ -271,18 +271,33 @@ type SharedInformerFactory interface { // InformerFor returns the SharedIndexInformer for obj. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer - Example() exampleinformers.ClusterInterface Example3() example3informers.ClusterInterface + Example() exampleinformers.ClusterInterface + Example() exampleinformers.ClusterInterface + Example() exampleinformers.ClusterInterface + Example() exampleinformers.ClusterInterface Existinginterfaces() existinginterfacesinformers.ClusterInterface Secondexample() secondexampleinformers.ClusterInterface } +func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { + return example3informers.New(f, f.tweakListOptions) +} + func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { return exampleinformers.New(f, f.tweakListOptions) } -func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { - return example3informers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { + return exampleinformers.New(f, f.tweakListOptions) +} + +func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { + return exampleinformers.New(f, f.tweakListOptions) +} + +func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { + return exampleinformers.New(f, f.tweakListOptions) } func (f *sharedInformerFactory) Existinginterfaces() existinginterfacesinformers.ClusterInterface { diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/clientset.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/clientset.go new file mode 100644 index 000000000..f3e410cca --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/clientset.go @@ -0,0 +1,137 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package exampledashed + +import ( + "fmt" + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/discovery" + "k8s.io/client-go/rest" + "k8s.io/client-go/util/flowcontrol" + + client "acme.corp/pkg/generated/clientsetv2/versioned" + exampledashedv2 "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2" +) + +type ClusterInterface interface { + Cluster(logicalcluster.Path) client.Interface + Discovery() discovery.DiscoveryInterface + ExampleDashedV2() exampledashedv2.ExampleDashedV2ClusterInterface +} + +// ClusterClientset contains the clients for groups. +type ClusterClientset struct { + *discovery.DiscoveryClient + clientCache kcpclient.Cache[*client.Clientset] + exampledashedV2 *exampledashedv2.ExampleDashedV2ClusterClient +} + +// Discovery retrieves the DiscoveryClient +func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// ExampleDashedV2 retrieves the ExampleDashedV2ClusterClient. +func (c *ClusterClientset) ExampleDashedV2() exampledashedv2.ExampleDashedV2ClusterInterface { + return c.exampledashedV2 +} + +// Cluster scopes this clientset to one cluster. +func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +// NewForConfig creates a new ClusterClientset 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) (*ClusterClientset, 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 ClusterClientset 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) (*ClusterClientset, 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) + } + + cache := kcpclient.NewCache(c, httpClient, &kcpclient.Constructor[*client.Clientset]{ + NewForConfigAndClient: client.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + + var cs ClusterClientset + cs.clientCache = cache + var err error + cs.exampledashedV2, err = exampledashedv2.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 ClusterClientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ClusterClientset { + cs, err := NewForConfig(c) + if err != nil { + panic(err) + } + return cs +} diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/fake/clientset.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/fake/clientset.go new file mode 100644 index 000000000..1d51fe28a --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/fake/clientset.go @@ -0,0 +1,114 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "github.com/kcp-dev/logicalcluster/v3" + + kcpfakediscovery "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/discovery/fake" + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/discovery" + + client "acme.corp/pkg/generated/clientsetv2/versioned" + clientscheme "acme.corp/pkg/generated/clientsetv2/versioned/scheme" + exampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" + kcpclient "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned" + kcpexampledashedv2 "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2" + fakeexampledashedv2 "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/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) *ClusterClientset { + o := kcptesting.NewObjectTracker(clientscheme.Scheme, clientscheme.Codecs.UniversalDecoder()) + o.AddAll(objects...) + + cs := &ClusterClientset{Fake: &kcptesting.Fake{}, tracker: o} + cs.discovery = &kcpfakediscovery.FakeDiscovery{Fake: cs.Fake, ClusterPath: logicalcluster.Wildcard} + cs.AddReactor("*", "*", kcptesting.ObjectReaction(o)) + cs.AddWatchReactor("*", kcptesting.WatchReaction(o)) + + return cs +} + +var _ kcpclient.ClusterInterface = (*ClusterClientset)(nil) + +// ClusterClientset contains the clients for groups. +type ClusterClientset struct { + *kcptesting.Fake + discovery *kcpfakediscovery.FakeDiscovery + tracker kcptesting.ObjectTracker +} + +// Discovery retrieves the DiscoveryClient +func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { + return c.tracker +} + +// ExampleDashedV2 retrieves the ExampleDashedV2ClusterClient. +func (c *ClusterClientset) ExampleDashedV2() kcpexampledashedv2.ExampleDashedV2ClusterInterface { + return &fakeexampledashedv2.ExampleDashedV2ClusterClient{Fake: c.Fake} +} + +// Cluster scopes this clientset to one cluster. +func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &Clientset{ + Fake: c.Fake, + discovery: &kcpfakediscovery.FakeDiscovery{Fake: c.Fake, ClusterPath: clusterPath}, + tracker: c.tracker.Cluster(clusterPath), + clusterPath: clusterPath, + } +} + +var _ client.Interface = (*Clientset)(nil) + +// Clientset contains the clients for groups. +type Clientset struct { + *kcptesting.Fake + discovery *kcpfakediscovery.FakeDiscovery + tracker kcptesting.ScopedObjectTracker + clusterPath logicalcluster.Path +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { + return c.tracker +} + +// ExampleDashedV2 retrieves the ExampleDashedV2Client. +func (c *Clientset) ExampleDashedV2() exampledashedv2.ExampleDashedV2Interface { + return &fakeexampledashedv2.ExampleDashedV2Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/scheme/register.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/scheme/register.go new file mode 100644 index 000000000..ba0423b10 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/scheme/register.go @@ -0,0 +1,60 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package scheme + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + exampledashedv2.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() { + metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(Scheme)) +} diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/clustertesttype.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..464212a40 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/clustertesttype.go @@ -0,0 +1,72 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "context" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + exampledashedv2client "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +// ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. +// A group's cluster client should implement this interface. +type ClusterTestTypesClusterGetter interface { + ClusterTestTypes() ClusterTestTypeClusterInterface +} + +// ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, +// or scope down to one cluster and return a exampledashedv2client.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) exampledashedv2client.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv2client.ExampleDashedV2Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv2client.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return c.clientCache.ClusterOrDie(clusterPath).ClusterTestTypes() +} + +// List returns the entire collection of all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.ClusterTestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) +} + +// Watch begins to watch all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) +} diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/exampledashed_client.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/exampledashed_client.go new file mode 100644 index 000000000..f944ca048 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/exampledashed_client.go @@ -0,0 +1,95 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + exampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +type ExampleDashedV2ClusterInterface interface { + ExampleDashedV2ClusterScoper + TestTypesClusterGetter + ClusterTestTypesClusterGetter +} + +type ExampleDashedV2ClusterScoper interface { + Cluster(logicalcluster.Path) exampledashedv2.ExampleDashedV2Interface +} + +type ExampleDashedV2ClusterClient struct { + clientCache kcpclient.Cache[*exampledashedv2.ExampleDashedV2Client] +} + +func (c *ExampleDashedV2ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv2.ExampleDashedV2Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *ExampleDashedV2ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *ExampleDashedV2ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new ExampleDashedV2ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV2ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new ExampleDashedV2ClusterClient 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) (*ExampleDashedV2ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*exampledashedv2.ExampleDashedV2Client]{ + NewForConfigAndClient: exampledashedv2.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &ExampleDashedV2ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV2ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV2ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/clustertesttype.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/clustertesttype.go new file mode 100644 index 000000000..e15823fa9 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/clustertesttype.go @@ -0,0 +1,202 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + applyconfigurationsexampledashedv2 "acme.corp/pkg/generated/applyconfigurationsv2/exampledashed/v2" + exampledashedv2client "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "exampledashed", Version: "v2", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "exampledashed", Version: "v2", Kind: "ClusterTestType"} + +type clusterTestTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv2client.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. +func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &exampledashedv2.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv2.ClusterTestTypeList{ListMeta: obj.(*exampledashedv2.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv2.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 across all clusters. +func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +} + +type clusterTestTypesClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *exampledashedv2.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *exampledashedv2.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *exampledashedv2.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &exampledashedv2.ClusterTestType{}) + return err +} + +func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) + + _, err := c.Fake.Invokes(action, &exampledashedv2.ClusterTestTypeList{}) + return err +} + +func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. +func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &exampledashedv2.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv2.ClusterTestTypeList{ListMeta: obj.(*exampledashedv2.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv2.ClusterTestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) +} + +func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*exampledashedv2.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv2.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv2.ClusterTestType, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} + +func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv2.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv2.ClusterTestType, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &exampledashedv2.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.ClusterTestType), err +} diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/exampledashed_client.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/exampledashed_client.go new file mode 100644 index 000000000..c6339e4bb --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/exampledashed_client.go @@ -0,0 +1,73 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "k8s.io/client-go/rest" + + exampledashedv2 "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" + kcpexampledashedv2 "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2" +) + +var _ kcpexampledashedv2.ExampleDashedV2ClusterInterface = (*ExampleDashedV2ClusterClient)(nil) + +type ExampleDashedV2ClusterClient struct { + *kcptesting.Fake +} + +func (c *ExampleDashedV2ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv2.ExampleDashedV2Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &ExampleDashedV2Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *ExampleDashedV2ClusterClient) TestTypes() kcpexampledashedv2.TestTypeClusterInterface { + return &testTypesClusterClient{Fake: c.Fake} +} + +func (c *ExampleDashedV2ClusterClient) ClusterTestTypes() kcpexampledashedv2.ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterClient{Fake: c.Fake} +} + +var _ exampledashedv2.ExampleDashedV2Interface = (*ExampleDashedV2Client)(nil) + +type ExampleDashedV2Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *ExampleDashedV2Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *ExampleDashedV2Client) TestTypes(namespace string) exampledashedv2.TestTypeInterface { + return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} + +func (c *ExampleDashedV2Client) ClusterTestTypes() exampledashedv2.ClusterTestTypeInterface { + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/testtype.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/testtype.go new file mode 100644 index 000000000..63f45ad01 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/fake/testtype.go @@ -0,0 +1,238 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" + + examplev1 "acme.corp/pkg/apis/example/v1" + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + applyconfigurationsexampledashedv2 "acme.corp/pkg/generated/applyconfigurationsv2/exampledashed/v2" + exampledashedv2client "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" + kcpexampledashedv2 "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2" +) + +var testTypesResource = schema.GroupVersionResource{Group: "exampledashed", Version: "v2", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "exampledashed", Version: "v2", Kind: "TestType"} + +type testTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexampledashedv2.TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. +func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &exampledashedv2.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv2.TestTypeList{ListMeta: obj.(*exampledashedv2.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv2.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 across all clusters. +func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +} + +type testTypesNamespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv2client.TestTypeInterface { + return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +} + +type testTypesClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path + Namespace string +} + +func (c *testTypesClient) Create(ctx context.Context, testType *exampledashedv2.TestType, opts metav1.CreateOptions) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) Update(ctx context.Context, testType *exampledashedv2.TestType, opts metav1.UpdateOptions) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *exampledashedv2.TestType, opts metav1.UpdateOptions) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &exampledashedv2.TestType{}) + return err +} + +func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) + + _, err := c.Fake.Invokes(action, &exampledashedv2.TestTypeList{}) + return err +} + +func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &exampledashedv2.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv2.TestTypeList{ListMeta: obj.(*exampledashedv2.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv2.TestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) +} + +func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*exampledashedv2.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv2.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv2.TestType, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv2.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv2.TestType, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &exampledashedv2.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv2.TestType), err +} + +func (c *testTypesClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(testTypesResource, c.ClusterPath, testTypeName, "field", c.Namespace, field), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} + +func (c *testTypesClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, field), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} + +func (c *testTypesClient) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, testTypeName), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/testtype.go b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/testtype.go new file mode 100644 index 000000000..f4ab97ac7 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/exampledashed/versioned/typed/exampledashed/v2/testtype.go @@ -0,0 +1,86 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "context" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + exampledashedv2client "acme.corp/pkg/generated/clientsetv2/versioned/typed/exampledashed/v2" +) + +// TestTypesClusterGetter has a method to return a TestTypeClusterInterface. +// A group's cluster client should implement this interface. +type TestTypesClusterGetter interface { + TestTypes() TestTypeClusterInterface +} + +// TestTypeClusterInterface can operate on TestTypes across all clusters, +// or scope down to one cluster and return a TestTypesNamespacer. +type TestTypeClusterInterface interface { + Cluster(logicalcluster.Path) TestTypesNamespacer + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv2client.ExampleDashedV2Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} +} + +// List returns the entire collection of all TestTypes across all clusters. +func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv2.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all TestTypes across all clusters. +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +} + +// TestTypesNamespacer can scope to objects within a namespace, returning a exampledashedv2client.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) exampledashedv2client.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*exampledashedv2client.ExampleDashedV2Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv2client.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/interface.go b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..ab109c009 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/interface.go @@ -0,0 +1,47 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package exampledashed + +import ( + "acme.corp/pkg/kcpexisting/clientsv2/informers/externalversions/example-dashed/v2" + "acme.corp/pkg/kcpexisting/clientsv2/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // V2 provides access to the shared informers in V2. + V2() v2.ClusterInterface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &group{factory: f, tweakListOptions: tweakListOptions} +} + +// V2 returns a new v2.ClusterInterface. +func (g *group) V2() v2.ClusterInterface { + return v2.New(g.factory, g.tweakListOptions) +} diff --git a/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/clustertesttype.go b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..5c01ada54 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/clustertesttype.go @@ -0,0 +1,124 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "context" + "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + upstreamexampledashedv2informers "acme.corp/pkg/generated/informersv2/externalversions/exampledashed/v2" + upstreamexampledashedv2listers "acme.corp/pkg/generated/listersv2/exampledashed/v2" + clientset "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned" + "acme.corp/pkg/kcpexisting/clientsv2/informers/externalversions/internalinterfaces" + exampledashedv2listers "acme.corp/pkg/kcpexisting/clientsv2/listers/exampledashed/v2" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) upstreamexampledashedv2informers.ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv2listers.ClusterTestTypeClusterLister +} + +type clusterTestTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeClusterInformer 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 NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeClusterInformer 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 NewFilteredClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv2.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + }, + f.tweakListOptions, + ) +} + +func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&exampledashedv2.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeClusterInformer) Lister() exampledashedv2listers.ClusterTestTypeClusterLister { + return exampledashedv2listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +} + +func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexampledashedv2informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type clusterTestTypeInformer struct { + informer cache.SharedIndexInformer + lister upstreamexampledashedv2listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *clusterTestTypeInformer) Lister() upstreamexampledashedv2listers.ClusterTestTypeLister { + return f.lister +} diff --git a/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/interface.go b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/interface.go new file mode 100644 index 000000000..5f57a4aa2 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/interface.go @@ -0,0 +1,53 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "acme.corp/pkg/kcpexisting/clientsv2/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // TestTypes returns a TestTypeClusterInformer + TestTypes() TestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer + ClusterTestTypes() ClusterTestTypeClusterInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &version{factory: f, tweakListOptions: tweakListOptions} +} + +// TestTypes returns a TestTypeClusterInformer +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeClusterInformer +func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { + return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/testtype.go b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/testtype.go new file mode 100644 index 000000000..1a3f58d9f --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed/v2/testtype.go @@ -0,0 +1,124 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + "context" + "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + upstreamexampledashedv2informers "acme.corp/pkg/generated/informersv2/externalversions/exampledashed/v2" + upstreamexampledashedv2listers "acme.corp/pkg/generated/listersv2/exampledashed/v2" + clientset "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned" + "acme.corp/pkg/kcpexisting/clientsv2/informers/externalversions/internalinterfaces" + exampledashedv2listers "acme.corp/pkg/kcpexisting/clientsv2/listers/exampledashed/v2" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) upstreamexampledashedv2informers.TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv2listers.TestTypeClusterLister +} + +type testTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTestTypeClusterInformer 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 NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeClusterInformer 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 NewFilteredTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().TestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV2().TestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv2.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, + f.tweakListOptions, + ) +} + +func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&exampledashedv2.TestType{}, f.defaultInformer) +} + +func (f *testTypeClusterInformer) Lister() exampledashedv2listers.TestTypeClusterLister { + return exampledashedv2listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +} + +func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexampledashedv2informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister upstreamexampledashedv2listers.TestTypeLister +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *testTypeInformer) Lister() upstreamexampledashedv2listers.TestTypeLister { + return f.lister +} diff --git a/examples/pkg/kcpexisting/clientsv2/informers/externalversions/factory.go b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/factory.go new file mode 100644 index 000000000..ff506b69d --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/factory.go @@ -0,0 +1,300 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package informers + +import ( + "reflect" + "sync" + "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/tools/cache" + + upstreaminformers "acme.corp/pkg/generated/informersv2/externalversions" + clientset "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned" + exampledashedinformers "acme.corp/pkg/kcpexisting/clientsv2/informers/externalversions/exampledashed" + "acme.corp/pkg/kcpexisting/clientsv2/informers/externalversions/internalinterfaces" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*SharedInformerOptions) *SharedInformerOptions + +type SharedInformerOptions struct { + customResync map[reflect.Type]time.Duration + tweakListOptions internalinterfaces.TweakListOptionsFunc + transform cache.TransformFunc +} + +type sharedInformerFactory struct { + client clientset.ClusterInterface + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + transform cache.TransformFunc + + informers map[reflect.Type]kcpcache.ScopeableSharedIndexInformer + // 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[metav1.Object]time.Duration) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + for k, v := range resyncConfig { + opts.customResync[reflect.TypeOf(k)] = v + } + return opts + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.tweakListOptions = tweakListOptions + return opts + } +} + +// WithTransform sets a transform on all informers. +func WithTransform(transform cache.TransformFunc) SharedInformerOption { + return func(opts *SharedInformerOptions) *SharedInformerOptions { + opts.transform = transform + return opts + } +} + +// NewSharedInformerFactory constructs a new instance of SharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client clientset.ClusterInterface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client clientset.ClusterInterface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + defaultResync: defaultResync, + informers: make(map[reflect.Type]kcpcache.ScopeableSharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + opts := &SharedInformerOptions{ + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + opts = opt(opts) + } + + // Forward options to the factory + factory.customResync = opts.customResync + factory.tweakListOptions = opts.tweakListOptions + factory.transform = opts.transform + + return factory +} + +// Start initializes all requested informers. +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() +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]kcpcache.ScopeableSharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]kcpcache.ScopeableSharedIndexInformer{} + 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. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer { + 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) + f.informers[informerType] = informer + + return informer +} + +type ScopedDynamicSharedInformerFactory interface { + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (upstreaminformers.GenericInformer, error) + + // Start initializes all requested informers. They are handled in goroutines + // which run until the stop channel gets closed. + Start(stopCh <-chan struct{}) +} + +// 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 := NewSharedInformerFactoryWithOptions(client, resyncPeriod) +// defer factory.Shutdown() // 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 + + Cluster(logicalcluster.Name) ScopedDynamicSharedInformerFactory + + // 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() + + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) + + // WaitForCacheSync blocks until all started informers' caches were synced + // or the stop channel gets closed. + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + // InformerFor returns the SharedIndexInformer for obj. + InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer + + ExampleDashed() exampledashedinformers.ClusterInterface +} + +func (f *sharedInformerFactory) ExampleDashed() exampledashedinformers.ClusterInterface { + return exampledashedinformers.New(f, f.tweakListOptions) +} + +func (f *sharedInformerFactory) Cluster(clusterName logicalcluster.Name) ScopedDynamicSharedInformerFactory { + return &scopedDynamicSharedInformerFactory{ + sharedInformerFactory: f, + clusterName: clusterName, + } +} + +type scopedDynamicSharedInformerFactory struct { + *sharedInformerFactory + clusterName logicalcluster.Name +} + +func (f *scopedDynamicSharedInformerFactory) ForResource(resource schema.GroupVersionResource) (upstreaminformers.GenericInformer, error) { + clusterInformer, err := f.sharedInformerFactory.ForResource(resource) + if err != nil { + return nil, err + } + return clusterInformer.Cluster(f.clusterName), nil +} + +func (f *scopedDynamicSharedInformerFactory) Start(stopCh <-chan struct{}) { + f.sharedInformerFactory.Start(stopCh) +} diff --git a/examples/pkg/kcpexisting/clientsv2/informers/externalversions/generic.go b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/generic.go new file mode 100644 index 000000000..d0c09ce24 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/generic.go @@ -0,0 +1,93 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package informers + +import ( + "fmt" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/example-dashed/v2" + upstreaminformers "acme.corp/pkg/generated/informersv2/externalversions" +) + +type GenericClusterInformer interface { + Cluster(logicalcluster.Name) upstreaminformers.GenericInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() kcpcache.GenericClusterLister +} + +type genericClusterInformer struct { + informer kcpcache.ScopeableSharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.informer +} + +// Lister returns the GenericClusterLister. +func (f *genericClusterInformer) Lister() kcpcache.GenericClusterLister { + return kcpcache.NewGenericClusterLister(f.Informer().GetIndexer(), f.resource) +} + +// Cluster scopes to a GenericInformer. +func (f *genericClusterInformer) Cluster(clusterName logicalcluster.Name) upstreaminformers.GenericInformer { + return &genericInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().ByCluster(clusterName), + } +} + +type genericInformer struct { + informer cache.SharedIndexInformer + lister cache.GenericLister +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return f.lister +} + +// 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) (GenericClusterInformer, error) { + switch resource { + // Group=example-dashed.dev, Version=V2 + case exampledashedv2.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V2().TestTypes().Informer()}, nil + case exampledashedv2.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V2().ClusterTestTypes().Informer()}, nil + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/examples/pkg/kcpexisting/clientsv2/informers/externalversions/internalinterfaces/factory_interfaces.go b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 000000000..87c66fe7f --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,45 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + + clientset "acme.corp/pkg/kcpexisting/clientsv2/exampledashed/versioned" +) + +// NewInformerFunc takes clientset.ClusterInterface and time.Duration to return a ScopeableSharedIndexInformer. +type NewInformerFunc func(clientset.ClusterInterface, time.Duration) kcpcache.ScopeableSharedIndexInformer + +// 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) kcpcache.ScopeableSharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a metav1.ListOptions. +type TweakListOptionsFunc func(*metav1.ListOptions) diff --git a/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/clustertesttype.go b/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/clustertesttype.go new file mode 100644 index 000000000..14ee269b6 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/clustertesttype.go @@ -0,0 +1,98 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + exampledashedv2listers "acme.corp/pkg/generated/listersv2/exampledashed/v2" +) + +// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type ClusterTestTypeClusterLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv2.ClusterTestType, err error) + // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) exampledashedv2listers.ClusterTestTypeLister + ClusterTestTypeClusterListerExpansion +} + +type clusterTestTypeClusterLister struct { + indexer cache.Indexer +} + +// NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{indexer: indexer} +} + +// List lists all ClusterTestTypes in the indexer across all workspaces. +func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv2.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv2.ClusterTestType)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) exampledashedv2listers.ClusterTestTypeLister { + return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// clusterTestTypeLister implements the exampledashedv2listers.ClusterTestTypeLister interface. +type clusterTestTypeLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all ClusterTestTypes in the indexer for a workspace. +func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*exampledashedv2.ClusterTestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeLister) Get(name string) (*exampledashedv2.ClusterTestType, error) { + key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv2.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv2.ClusterTestType), nil +} diff --git a/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/clustertesttype_expansion.go new file mode 100644 index 000000000..8743bfbe7 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/clustertesttype_expansion.go @@ -0,0 +1,25 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/testtype.go b/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/testtype.go new file mode 100644 index 000000000..c8e2306bd --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/testtype.go @@ -0,0 +1,119 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +import ( + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + exampledashedv2 "acme.corp/pkg/apisv2/exampledashed/v2" + exampledashedv2listers "acme.corp/pkg/generated/listersv2/exampledashed/v2" +) + +// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type TestTypeClusterLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) exampledashedv2listers.TestTypeLister + TestTypeClusterListerExpansion +} + +type testTypeClusterLister struct { + indexer cache.Indexer +} + +// NewTestTypeClusterLister returns a new TestTypeClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { + return &testTypeClusterLister{indexer: indexer} +} + +// List lists all TestTypes in the indexer across all workspaces. +func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv2.TestType)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) exampledashedv2listers.TestTypeLister { + return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// testTypeLister implements the exampledashedv2listers.TestTypeLister interface. +type testTypeLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all TestTypes in the indexer for a workspace. +func (s *testTypeLister) List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (s *testTypeLister) TestTypes(namespace string) exampledashedv2listers.TestTypeNamespaceLister { + return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +} + +// testTypeNamespaceLister implements the exampledashedv2listers.TestTypeNamespaceLister interface. +type testTypeNamespaceLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name + namespace string +} + +// List lists all TestTypes in the indexer for a given workspace and namespace. +func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*exampledashedv2.TestType, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv2.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv2.TestType, error) { + key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv2.Resource("testtypes"), name) + } + return obj.(*exampledashedv2.TestType), nil +} diff --git a/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/testtype_expansion.go b/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/testtype_expansion.go new file mode 100644 index 000000000..68f6a8cb3 --- /dev/null +++ b/examples/pkg/kcpexisting/clientsv2/listers/exampledashed/v2/testtype_expansion.go @@ -0,0 +1,25 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 kcp code-generator. DO NOT EDIT. + +package v2 + +// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/go.mod b/go.mod index 1b9a4287b..508bcbd56 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/kcp-dev/code-generator/v2 go 1.22.0 require ( + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.34.1 github.com/spf13/cobra v1.8.1 diff --git a/go.sum b/go.sum index 62c6a3890..32a8e1627 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 2e70d5403..dfdb00358 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -28,35 +28,39 @@ pushd ./examples # Generate deepcopy functions ${CONTROLLER_GEN} object paths=./pkg/apis/... +${CONTROLLER_GEN} object paths=./pkg/apisv2/... -# Generate standard clientset -${KUBE_CLIENT_GEN} \ - --clientset-name versioned \ - --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ - --input-base acme.corp/pkg/apis \ - --input example/v1 \ - --input example/v1alpha1 \ - --input example/v1beta1 \ - --input example/v2 \ - --input example3/v1 \ - --input secondexample/v1 \ - --input existinginterfaces/v1 \ - --output-dir ./pkg/generated/clientset \ - --output-pkg acme.corp/pkg/generated/clientset - -${KUBE_APPLYCONFIGURATION_GEN} \ - --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ - --output-dir ./pkg/generated/applyconfigurations \ - --output-pkg acme.corp/pkg/generated/applyconfigurations \ - acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 +{ + echo "Generating non-dashed clients" + + # Generate standard clientset + ${KUBE_CLIENT_GEN} \ + --clientset-name versioned \ + --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ + --input-base acme.corp/pkg/apis \ + --input example/v1 \ + --input example/v1alpha1 \ + --input example/v1beta1 \ + --input example/v2 \ + --input example3/v1 \ + --input secondexample/v1 \ + --input existinginterfaces/v1 \ + --output-dir ./pkg/generated/clientset \ + --output-pkg acme.corp/pkg/generated/clientset -${KUBE_LISTER_GEN} \ + ${KUBE_APPLYCONFIGURATION_GEN} \ + --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ + --output-dir ./pkg/generated/applyconfigurations \ + --output-pkg acme.corp/pkg/generated/applyconfigurations \ + acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 + + ${KUBE_LISTER_GEN} \ --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ --output-dir ./pkg/generated/listers \ --output-pkg acme.corp/pkg/generated/listers \ acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 -${KUBE_INFORMER_GEN} \ + ${KUBE_INFORMER_GEN} \ --versioned-clientset-package acme.corp/pkg/generated/clientset/versioned \ --listers-package acme.corp/pkg/generated/listers \ --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ @@ -64,20 +68,69 @@ ${KUBE_INFORMER_GEN} \ --output-pkg acme.corp/pkg/generated/informers \ acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 -# Generate cluster-aware clients, informers and listers using generated single-cluster code -./../bin/code-generator \ - "client:standalone=true,outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "lister:apiPackagePath=acme.corp/pkg/apis,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "informer:standalone=true,outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,singleClusterInformerPackagePath=acme.corp/pkg/generated/informers/externalversions,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + # Generate cluster-aware clients, informers and listers using generated single-cluster code + ./../bin/code-generator \ + "client:standalone=true,outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "lister:apiPackagePath=acme.corp/pkg/apis,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "informer:standalone=true,outputPackagePath=acme.corp/pkg/kcpexisting/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterListerPackagePath=acme.corp/pkg/generated/listers,singleClusterInformerPackagePath=acme.corp/pkg/generated/informers/externalversions,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "paths=./pkg/apis/..."\ + "output:dir=./pkg/kcpexisting/clients" + + # Generate cluster-aware clients, informers and listers assuming no single-cluster listers or informers + ./../bin/code-generator \ + "client:standalone=true,outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "lister:apiPackagePath=acme.corp/pkg/apis,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "informer:standalone=true,outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ "paths=./pkg/apis/..." \ - "output:dir=./pkg/kcpexisting/clients" - -# Generate cluster-aware clients, informers and listers assuming no single-cluster listers or informers -./../bin/code-generator \ - "client:standalone=true,outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurations,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "lister:apiPackagePath=acme.corp/pkg/apis,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "informer:standalone=true,outputPackagePath=acme.corp/pkg/kcp/clients,apiPackagePath=acme.corp/pkg/apis,singleClusterClientPackagePath=acme.corp/pkg/generated/clientset/versioned,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ - "paths=./pkg/apis/..." \ - "output:dir=./pkg/kcp/clients" + "output:dir=./pkg/kcp/clients" +} +{ + echo "Generating dashed clients" + + # Generate standard clientset + ${KUBE_CLIENT_GEN} \ + --clientset-name versioned \ + --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ + --input-base acme.corp/pkg/apisv2 \ + --input exampledashed/v2 \ + --output-dir ./pkg/generated/clientsetv2 \ + --output-pkg acme.corp/pkg/generated/clientsetv2 + + ${KUBE_APPLYCONFIGURATION_GEN} \ + --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ + --output-dir ./pkg/generated/applyconfigurationsv2 \ + --output-pkg acme.corp/pkg/generated/applyconfigurationsv2 \ + acme.corp/pkg/apisv2/exampledashed/v2 + + ${KUBE_LISTER_GEN} \ + --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ + --output-dir ./pkg/generated/listersv2 \ + --output-pkg acme.corp/pkg/generated/listersv2 \ + acme.corp/pkg/apisv2/exampledashed/v2 + + ${KUBE_INFORMER_GEN} \ + --versioned-clientset-package acme.corp/pkg/generated/clientset/versioned \ + --listers-package acme.corp/pkg/generated/listersv2 \ + --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ + --output-dir ./pkg/generated/informersv2 \ + --output-pkg acme.corp/pkg/generated/informersv2 \ + acme.corp/pkg/apisv2/exampledashed/v2 + + # Generate cluster-aware clients, informers and listers using generated single-cluster code + ./../bin/code-generator \ + "client:name=exampledashed,standalone=true,outputPackagePath=acme.corp/pkg/kcpexisting/clientsv2,apiPackagePath=acme.corp/pkg/apisv2,singleClusterClientPackagePath=acme.corp/pkg/generated/clientsetv2/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurationsv2,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "lister:name=exampledashed,apiPackagePath=acme.corp/pkg/apisv2,singleClusterListerPackagePath=acme.corp/pkg/generated/listersv2,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "informer:name=exampledashed,standalone=true,outputPackagePath=acme.corp/pkg/kcpexisting/clientsv2,apiPackagePath=acme.corp/pkg/apisv2,singleClusterClientPackagePath=acme.corp/pkg/generated/clientsetv2/versioned,singleClusterListerPackagePath=acme.corp/pkg/generated/listersv2,singleClusterInformerPackagePath=acme.corp/pkg/generated/informersv2/externalversions,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "paths=./pkg/apisv2/..."\ + "output:dir=./pkg/kcpexisting/clientsv2" + + # Generate cluster-aware clients, informers and listers assuming no single-cluster listers or informers + ./../bin/code-generator \ + "client:name=exampledashed,standalone=true,outputPackagePath=acme.corp/pkg/kcp/clientsv2,apiPackagePath=acme.corp/pkg/apisv2,singleClusterClientPackagePath=acme.corp/pkg/generated/clientsetv2/versioned,singleClusterApplyConfigurationsPackagePath=acme.corp/pkg/generated/applyconfigurationsv2,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "lister:name=exampledashed,apiPackagePath=acme.corp/pkg/apisv2,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "informer:name=exampledashed,standalone=true,outputPackagePath=acme.corp/pkg/kcp/clientsv2,apiPackagePath=acme.corp/pkg/apisv2,singleClusterClientPackagePath=acme.corp/pkg/generated/clientsetv2/versioned,headerFile=./../hack/boilerplate/boilerplate.go.txt" \ + "paths=./pkg/apisv2/..." \ + "output:dir=./pkg/kcp/clientsv2" +} popd diff --git a/pkg/generators/clientgen/clientgen.go b/pkg/generators/clientgen/clientgen.go index d6d10a229..0dbbc4a39 100644 --- a/pkg/generators/clientgen/clientgen.go +++ b/pkg/generators/clientgen/clientgen.go @@ -21,6 +21,9 @@ import ( "sort" "strings" + "golang.org/x/text/cases" + "golang.org/x/text/language" + "k8s.io/code-generator/cmd/client-gen/types" "k8s.io/gengo/v2/namer" "k8s.io/klog/v2" @@ -226,8 +229,8 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVersion][]parser.Kind) []types.GroupVersionInfo { - var info []types.GroupVersionInfo +func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[parser.PackageVersion][]parser.Kind) []parser.Group { + var info []parser.Group for group, versions := range groupVersionKinds { for version := range versions { info = append(info, toGroupVersionInfo(group, version)) @@ -240,12 +243,24 @@ func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVer } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ - Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, - LowerCaseGroupGoName: namer.IL(group.GoName), +func toGroupVersionInfo(group parser.Group, version parser.PackageVersion) parser.Group { + goName := strings.Split(group.GoName, ".")[0] + caser := cases.Title(language.English) + parts := strings.Split(goName, "-") + for i, part := range parts { + parts[i] = caser.String(part) + } + goName = strings.Join(parts, "") + + // HACK(mjudeikis): Somehow fake client generation breaks the pattern :/ + group.Group = types.Group(strings.ToLower(goName)) + + return parser.Group{ + Group: group.Group, + Version: parser.Version(namer.IC(version.Version.String())), + // HACK(mjudeikis): This replace is not quite here, but as we collect groups dynamically, we can't provide global marker for it. + PackageAlias: strings.ReplaceAll(strings.ToLower(group.GoName+version.Version.NonEmpty()), "-", ""), + GoName: goName, + LowerCaseGroupGoName: strings.ReplaceAll(namer.IL(group.GoName), "-", ""), } } diff --git a/pkg/generators/informergen/informergen.go b/pkg/generators/informergen/informergen.go index 157585c87..2e8f84237 100644 --- a/pkg/generators/informergen/informergen.go +++ b/pkg/generators/informergen/informergen.go @@ -21,6 +21,9 @@ import ( "sort" "strings" + "golang.org/x/text/cases" + "golang.org/x/text/language" + "k8s.io/code-generator/cmd/client-gen/types" "k8s.io/gengo/v2/namer" "k8s.io/klog/v2" @@ -34,7 +37,7 @@ import ( type Generator struct { // Name is the name of the clientset, e.g. "kubernetes" - ClientsetName string `marker:",optional"` + Name string `marker:",optional"` // ExternalOnly toggles the creation of a "externalversions" sub-directory. Set to true if you are generating // custom code for a project that's not using k8s.io/code-generator/generate-groups.sh for their types. @@ -114,14 +117,14 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { onlyGroups = append(onlyGroups, group) } sort.Slice(onlyGroups, func(i, j int) bool { - return onlyGroups[i].Group.PackageName() < onlyGroups[j].Group.PackageName() + return onlyGroups[i].PackageName() < onlyGroups[j].PackageName() }) - if g.ClientsetName == "" { - g.ClientsetName = "clientset" + if g.Name == "" { + g.Name = "clientset" } - clientsetDir := g.ClientsetName + clientsetDir := g.Name if !g.ExternalOnly { clientsetDir = filepath.Join(clientsetDir, "versioned") } @@ -137,7 +140,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { factoryPath := filepath.Join(informersDir, "factory.go") logger.WithValues("path", factoryPath).Info("generating informer factory") if err := util.WriteGeneratedCode(ctx, headerText, &informergen.Factory{ - Groups: onlyGroups, + Groups: groupInfo, PackagePath: filepath.Join(g.OutputPackagePath, informersDir), ClientsetPackagePath: filepath.Join(g.OutputPackagePath, clientsetDir), SingleClusterClientPackagePath: g.SingleClusterClientPackagePath, @@ -146,12 +149,12 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { return err } - gvks := map[types.Group]map[types.Version][]parser.Kind{} + gvks := map[types.Group]map[parser.Version][]parser.Kind{} for group, versions := range groupVersionKinds { for version, kinds := range versions { info := toGroupVersionInfo(group, version) if _, exists := gvks[info.Group]; !exists { - gvks[info.Group] = map[types.Version][]parser.Kind{} + gvks[info.Group] = map[parser.Version][]parser.Kind{} } gvks[info.Group][info.Version] = kinds } @@ -246,8 +249,8 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVersion][]parser.Kind) []types.GroupVersionInfo { - var info []types.GroupVersionInfo +func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[parser.PackageVersion][]parser.Kind) []parser.Group { + var info []parser.Group for group, versions := range groupVersionKinds { for version := range versions { info = append(info, toGroupVersionInfo(group, version)) @@ -260,12 +263,21 @@ func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVer } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ +func toGroupVersionInfo(group parser.Group, version parser.PackageVersion) parser.Group { + // TODO(mjudeikis): This is a hack to get the goName from the group. We should probably store this in the group. + goName := strings.Split(group.GoName, ".")[0] + caser := cases.Title(language.English) + parts := strings.Split(goName, "-") + for i, part := range parts { + parts[i] = caser.String(part) + } + goName = strings.Join(parts, "") + + return parser.Group{ Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, + Version: parser.Version(namer.IC(version.Version.String())), + PackageAlias: strings.ReplaceAll(strings.ToLower(group.GoName+version.Version.NonEmpty()), "-", ""), + GoName: goName, LowerCaseGroupGoName: namer.IL(group.GoName), } } diff --git a/pkg/generators/listergen/listergen.go b/pkg/generators/listergen/listergen.go index 0aa7ebe48..32199d05b 100644 --- a/pkg/generators/listergen/listergen.go +++ b/pkg/generators/listergen/listergen.go @@ -20,7 +20,6 @@ import ( "path/filepath" "strings" - "k8s.io/code-generator/cmd/client-gen/types" "k8s.io/gengo/v2/namer" "k8s.io/klog/v2" "sigs.k8s.io/controller-tools/pkg/genall" @@ -32,6 +31,9 @@ import ( ) type Generator struct { + // Name is the name of this client-set, e.g. "kubernetes" + Name string `marker:",optional"` + // HeaderFile specifies the header text (e.g. license) to prepend to generated files. HeaderFile string `marker:",optional"` @@ -126,12 +128,12 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ +func toGroupVersionInfo(group parser.Group, version parser.PackageVersion) parser.Group { + return parser.Group{ Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, + Version: parser.Version(namer.IC(version.Version.String())), + PackageAlias: strings.ReplaceAll(strings.ToLower(group.GoName+version.Version.NonEmpty()), "-", ""), + GoName: group.GoName, LowerCaseGroupGoName: namer.IL(group.GoName), } } diff --git a/pkg/internal/clientgen/clientset.go b/pkg/internal/clientgen/clientset.go index 943a15fbb..f3ffcc3e9 100644 --- a/pkg/internal/clientgen/clientset.go +++ b/pkg/internal/clientgen/clientset.go @@ -5,8 +5,7 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - + "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) @@ -15,7 +14,7 @@ type ClientSet struct { Name string // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo + Groups []parser.Group // PackagePath is the package under which this client-set will be exposed. // TODO(skuznets) we should be able to figure this out from the output dir, ideally @@ -66,7 +65,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/util/flowcontrol" -{{range .groups}} {{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.PackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} ) diff --git a/pkg/internal/clientgen/fake_clientset.go b/pkg/internal/clientgen/fake_clientset.go index 511f61e70..9d21b2d25 100644 --- a/pkg/internal/clientgen/fake_clientset.go +++ b/pkg/internal/clientgen/fake_clientset.go @@ -5,8 +5,7 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - + "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) @@ -15,7 +14,7 @@ type FakeClientset struct { Name string // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo + Groups []parser.Group // PackagePath is the package under which this client-set will be exposed. // TODO(skuznets) we should be able to figure this out from the output dir, ideally @@ -65,11 +64,11 @@ import ( clientscheme "{{.singleClusterClientPackagePath}}/scheme" kcpclient "{{.packagePath}}" -{{range .groups}} {{.PackageAlias}} "{{$.singleClusterClientPackagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.PackageAlias}} "{{$.singleClusterClientPackagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} -{{range .groups}} kcp{{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} kcp{{.PackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} -{{range .groups}} fake{{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}/fake" +{{range .groups}} fake{{.PackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}/fake" {{end -}} ) diff --git a/pkg/internal/clientgen/fake_group.go b/pkg/internal/clientgen/fake_group.go index cd3b96b0b..e2536b1e5 100644 --- a/pkg/internal/clientgen/fake_group.go +++ b/pkg/internal/clientgen/fake_group.go @@ -5,15 +5,13 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) type FakeGroup struct { // Group is the group in this client. - Group types.GroupVersionInfo + Group parser.Group // Kinds are the kinds in the group. Kinds []parser.Kind diff --git a/pkg/internal/clientgen/fake_type.go b/pkg/internal/clientgen/fake_type.go index c52abf527..858e30c53 100644 --- a/pkg/internal/clientgen/fake_type.go +++ b/pkg/internal/clientgen/fake_type.go @@ -8,7 +8,6 @@ import ( "text/template" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/code-generator/cmd/client-gen/types" "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" @@ -16,7 +15,7 @@ import ( type FakeTypedClient struct { // Group is the group in this client. - Group types.GroupVersionInfo + Group parser.Group // Kind is the kinds in this file. Kind parser.Kind @@ -148,7 +147,7 @@ import ( {{- if .hasMethods }} "context" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} {{- if "watch" | .kind.SupportedVerbs.Has }} @@ -168,13 +167,13 @@ import ( "k8s.io/apimachinery/pkg/types" {{end}} {{- if and .generateApplyVerbs ("apply" | .kind.SupportedVerbs.Has) }} - applyconfigurations{{.group.PackageAlias}} "{{.singleClusterApplyConfigurationsPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + applyconfigurations{{.group.PackageAlias}} "{{.singleClusterApplyConfigurationsPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} {{- if .kind.IsNamespaced}} - kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} - {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) var {{.kind.Plural | lowerFirst}}Resource = schema.GroupVersionResource{Group: "{{.groupName}}", Version: "{{.group.Version.String | toLower}}", Resource: "{{.kind.Plural | toLower}}"} diff --git a/pkg/internal/clientgen/group.go b/pkg/internal/clientgen/group.go index 9421c1733..898d1732b 100644 --- a/pkg/internal/clientgen/group.go +++ b/pkg/internal/clientgen/group.go @@ -5,15 +5,13 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) type Group struct { // Group is the group in this client. - Group types.GroupVersionInfo + Group parser.Group // Kinds are the kinds in the group. Kinds []parser.Kind @@ -57,7 +55,7 @@ import ( "k8s.io/client-go/rest" - {{.group.PackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) type {{.group.GroupGoName}}{{.group.Version}}ClusterInterface interface { diff --git a/pkg/internal/clientgen/scheme.go b/pkg/internal/clientgen/scheme.go index 6b5524e35..11641e95c 100644 --- a/pkg/internal/clientgen/scheme.go +++ b/pkg/internal/clientgen/scheme.go @@ -5,14 +5,13 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - + "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) type Scheme struct { // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo + Groups []parser.Group // APIPackagePath is the root directory under which API types exist. // e.g. "k8s.io/api" diff --git a/pkg/internal/clientgen/type.go b/pkg/internal/clientgen/type.go index bb5a95e33..667be29b2 100644 --- a/pkg/internal/clientgen/type.go +++ b/pkg/internal/clientgen/type.go @@ -5,15 +5,13 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) type TypedClient struct { // Group is the group in this client. - Group types.GroupVersionInfo + Group parser.Group // Kind is the kinds in this file. Kind parser.Kind @@ -62,10 +60,10 @@ import ( "context" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} - {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) // {{.kind.Plural}}ClusterGetter has a method to return a {{.kind.String}}ClusterInterface. diff --git a/pkg/internal/informergen/factory.go b/pkg/internal/informergen/factory.go index 9563eeaa9..a92284c50 100644 --- a/pkg/internal/informergen/factory.go +++ b/pkg/internal/informergen/factory.go @@ -92,7 +92,7 @@ import ( upstreaminformers "{{.singleClusterInformerPackagePath}}" {{end -}} -{{range .groups}} {{.Group.PackageName}}informers "{{$.packagePath}}/{{.Group.PackageName}}" +{{range .groups}} {{.PackageName}}informers "{{$.packagePath}}/{{.PackageName}}" {{end -}} "{{.packagePath}}/internalinterfaces" @@ -329,13 +329,13 @@ type SharedInformerFactory interface { // InformerFor returns the SharedIndexInformer for obj. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer -{{range .groups}} {{.GoName}}() {{.Group.PackageName}}informers.ClusterInterface +{{range .groups}} {{.GoName}}() {{.PackageName}}informers.ClusterInterface {{end -}} } {{range .groups}} -func (f *sharedInformerFactory) {{.GoName}}() {{.Group.PackageName}}informers.ClusterInterface { - return {{.Group.PackageName}}informers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) {{.GoName}}() {{.PackageName}}informers.ClusterInterface { + return {{.PackageName}}informers.New(f, f.tweakListOptions) } {{end}} @@ -485,14 +485,14 @@ type SharedScopedInformerFactory interface { ForResource(resource schema.GroupVersionResource) (GenericInformer, error) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool -{{range .groups}} {{.GoName}}() {{.Group.PackageName}}informers.Interface +{{range .groups}} {{.GoName}}() {{.PackageName}}informers.Interface {{end -}} } {{range .groups}} -func (f *sharedScopedInformerFactory) {{.GoName}}() {{.Group.PackageName}}informers.Interface { - return {{.Group.PackageName}}informers.NewScoped(f, f.namespace, f.tweakListOptions) +func (f *sharedScopedInformerFactory) {{.GoName}}() {{.PackageName}}informers.Interface { + return {{.PackageName}}informers.NewScoped(f, f.namespace, f.tweakListOptions) } {{end}} {{end}} diff --git a/pkg/internal/informergen/generic.go b/pkg/internal/informergen/generic.go index 18ce9b072..2d56351ca 100644 --- a/pkg/internal/informergen/generic.go +++ b/pkg/internal/informergen/generic.go @@ -27,10 +27,10 @@ import ( type Generic struct { // Groups are the groups in this informer factory. - Groups []types.GroupVersionInfo + Groups []parser.Group // GroupVersionKinds are all the kinds we need to support,indexed by group and version. - GroupVersionKinds map[types.Group]map[types.Version][]parser.Kind + GroupVersionKinds map[types.Group]map[parser.Version][]parser.Kind // APIPackagePath is the root directory under which API types exist. // e.g. "k8s.io/api" diff --git a/pkg/internal/informergen/groupinterface.go b/pkg/internal/informergen/groupinterface.go index 9848d4336..3af2de4e7 100644 --- a/pkg/internal/informergen/groupinterface.go +++ b/pkg/internal/informergen/groupinterface.go @@ -62,7 +62,7 @@ var groupInterface = ` // Code generated by kcp code-generator. DO NOT EDIT. -package {{.group.Group.PackageName}} +package {{.group.PackageName}} import ( {{range .versions}} "{{$.packagePath}}/{{$.group.Group.PackageName}}/{{.PackageName}}" diff --git a/pkg/internal/informergen/informer.go b/pkg/internal/informergen/informer.go index 91b2b35f8..010dd78e2 100644 --- a/pkg/internal/informergen/informer.go +++ b/pkg/internal/informergen/informer.go @@ -20,14 +20,12 @@ import ( "io" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" ) type Informer struct { // Group is the group in this informer. - Group types.GroupVersionInfo + Group parser.Group // Kind is the kind in this file. Kind parser.Kind @@ -105,11 +103,11 @@ import ( kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" "github.com/kcp-dev/logicalcluster/v3" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{.group.PackageAlias}}listers "{{.listerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}}listers "{{.listerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{if .useUpstreamInterfaces -}} - upstream{{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - upstream{{.group.PackageAlias}}informers "{{.singleClusterInformerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + upstream{{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" + upstream{{.group.PackageAlias}}informers "{{.singleClusterInformerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end -}} clientset "{{.clientsetPackagePath}}" @@ -150,13 +148,13 @@ func NewFiltered{{.kind}}ClusterInformer(client clientset.ClusterInterface, resy if tweakListOptions != nil { tweakListOptions(&options) } - return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}().List(context.TODO(), options) + return client.{{.group.GoName}}{{.group.Version}}().{{.kind.Plural}}().List(context.TODO(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}().Watch(context.TODO(), options) + return client.{{.group.GoName}}{{.group.Version}}().{{.kind.Plural}}().Watch(context.TODO(), options) }, }, &{{.group.PackageAlias}}.{{.kind.String}}{}, diff --git a/pkg/internal/listergen/expansions.go b/pkg/internal/listergen/expansions.go index 13edd29ab..5c4f3089c 100644 --- a/pkg/internal/listergen/expansions.go +++ b/pkg/internal/listergen/expansions.go @@ -4,8 +4,6 @@ import ( "io" "text/template" - clientgentypes "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" ) @@ -13,7 +11,7 @@ type Expansions struct { // Group is: // - the name of the API group, e.g. "authorization", // - the version and package path of the API, e.g. "v1" and "k8s.io/api/rbac/v1" - Group clientgentypes.GroupVersionInfo + Group parser.Group // Kind is the kind for which we are generating listers, e.g. "ClusterRole" Kind parser.Kind diff --git a/pkg/internal/listergen/lister.go b/pkg/internal/listergen/lister.go index 48ff2416c..8f1a06959 100644 --- a/pkg/internal/listergen/lister.go +++ b/pkg/internal/listergen/lister.go @@ -4,8 +4,6 @@ import ( "io" "text/template" - clientgentypes "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" ) @@ -13,7 +11,7 @@ type Lister struct { // Group is: // - the name of the API group, e.g. "authorization", // - the version and package path of the API, e.g. "v1" and "k8s.io/api/rbac/v1" - Group clientgentypes.GroupVersionInfo + Group parser.Group // Kind is the kind for which we are generating listers, e.g. "ClusterRole" Kind parser.Kind @@ -58,9 +56,9 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/api/errors" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{if .useUpstreamInterfaces -}} - {{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end -}} ) diff --git a/pkg/parser/extract.go b/pkg/parser/extract.go index 3c4882fa4..672ebc537 100644 --- a/pkg/parser/extract.go +++ b/pkg/parser/extract.go @@ -33,7 +33,7 @@ import ( // isForbiddenGroupVersion hacks around the k8s client-set, where types have +genclient but aren't meant to have // generated clients ... ? -func isForbiddenGroupVersion(group types.Group, version types.Version) bool { +func isForbiddenGroupVersion(group types.Group, version Version) bool { forbidden := map[string]sets.Set[string]{ "abac.authorization.kubernetes.io": sets.New[string]("v0", "v1beta1"), "componentconfig": sets.New[string]("v1alpha1"), @@ -49,15 +49,15 @@ func isForbiddenGroupVersion(group types.Group, version types.Version) bool { // When we are looking at a package, we can determine the group and version by copying the upstream // logic: // https://github.com/kubernetes/kubernetes/blob/f046bdf24e69ac31d3e1ed56926d9a7c715f1cc8/staging/src/k8s.io/code-generator/cmd/lister-gen/generators/lister.go#L93-L106 -func CollectKinds(ctx *genall.GenerationContext, verbs ...string) (map[Group]map[types.PackageVersion][]Kind, error) { - groupVersionKinds := map[Group]map[types.PackageVersion][]Kind{} +func CollectKinds(ctx *genall.GenerationContext, verbs ...string) (map[Group]map[PackageVersion][]Kind, error) { + groupVersionKinds := map[Group]map[PackageVersion][]Kind{} for _, root := range ctx.Roots { logger := klog.Background() logger.V(4).Info("processing " + root.PkgPath) parts := strings.Split(root.PkgPath, "/") groupName := types.Group(parts[len(parts)-2]) - version := types.PackageVersion{ - Version: types.Version(parts[len(parts)-1]), + version := PackageVersion{ + Version: Version(parts[len(parts)-1]), Package: root.PkgPath, } @@ -153,7 +153,7 @@ func CollectKinds(ctx *genall.GenerationContext, verbs ...string) (map[Group]map continue } if _, recorded := groupVersionKinds[group]; !recorded { - groupVersionKinds[group] = map[types.PackageVersion][]Kind{} + groupVersionKinds[group] = map[PackageVersion][]Kind{} } groupVersionKinds[group][version] = append(groupVersionKinds[group][version], kinds...) } diff --git a/pkg/parser/types.go b/pkg/parser/types.go index 00fbd86e5..40c2af0bc 100644 --- a/pkg/parser/types.go +++ b/pkg/parser/types.go @@ -17,6 +17,8 @@ limitations under the License. package parser import ( + "strings" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/code-generator/cmd/client-gen/types" @@ -34,7 +36,20 @@ type Kind struct { type Group struct { types.Group - GoName string + Version Version + PackageAlias string + GoName string + LowerCaseGroupGoName string +} + +func (g Group) PackageName() string { + _g := strings.Split(g.NonEmpty(), ".")[0] + _g = strings.ReplaceAll(_g, "-", "") + return strings.ToLower(_g) +} + +func (g Group) GroupGoName() string { + return g.GoName } func (k *Kind) Plural() string { @@ -53,6 +68,30 @@ func (k *Kind) SupportsListWatch() bool { return k.SupportedVerbs.HasAll("list", "watch") } +type Version string + +func (v Version) String() string { + return string(v) +} + +func (v Version) NonEmpty() string { + if v == "" { + return "internalVersion" + } + return v.String() +} + +func (v Version) PackageName() string { + _v := strings.ReplaceAll(v.NonEmpty(), "-", "") + return strings.ToLower(_v) +} + +type PackageVersion struct { + Version + // The fully qualified package, e.g. k8s.io/kubernetes/pkg/apis/apps, where the types.go is found. + Package string +} + // TODO(skuznets): // add an e2e for a kind that has no verbs, but uses an extension for something // then ensure we add in fake_type.go entries for the extension