diff --git a/examples/pkg/apis/example-dashed/doc.go b/examples/pkg/apis/example-dashed/doc.go new file mode 100644 index 000000000..ecff984c9 --- /dev/null +++ b/examples/pkg/apis/example-dashed/doc.go @@ -0,0 +1,22 @@ +/* +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 example + +const ( + // +groupName=exampledashed + GroupName = "example-dashed.dev" +) diff --git a/examples/pkg/apis/example-dashed/v1/doc.go b/examples/pkg/apis/example-dashed/v1/doc.go new file mode 100644 index 000000000..3fe5b34af --- /dev/null +++ b/examples/pkg/apis/example-dashed/v1/doc.go @@ -0,0 +1,19 @@ +/* +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. +*/ + +// +k8s:deepcopy-gen=package,register +// +groupName=exampledashed.some.corp +package v1 diff --git a/examples/pkg/apis/example-dashed/v1/register.go b/examples/pkg/apis/example-dashed/v1/register.go new file mode 100644 index 000000000..0bbbd600d --- /dev/null +++ b/examples/pkg/apis/example-dashed/v1/register.go @@ -0,0 +1,55 @@ +/* +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 v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + + example "acme.corp/pkg/apis/example-dashed" +) + +// SchemeGroupVersion is group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} + +// 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/apis/example-dashed/v1/types.go b/examples/pkg/apis/example-dashed/v1/types.go new file mode 100644 index 000000000..1f1a48209 --- /dev/null +++ b/examples/pkg/apis/example-dashed/v1/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 v1 + +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/apis/example-dashed/v1/zz_generated.deepcopy.go b/examples/pkg/apis/example-dashed/v1/zz_generated.deepcopy.go new file mode 100644 index 000000000..137615d31 --- /dev/null +++ b/examples/pkg/apis/example-dashed/v1/zz_generated.deepcopy.go @@ -0,0 +1,144 @@ +//go:build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package v1 + +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/applyconfigurations/example-dashed/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..a5a71c6fe --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/example-dashed/v1/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 v1 + +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("exampledashed.some.corp/v1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// 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/applyconfigurations/example-dashed/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/example-dashed/v1/clustertesttypestatus.go new file mode 100644 index 000000000..9c966d9ae --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/example-dashed/v1/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 v1 + +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use +// with apply. +type ClusterTestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with +// apply. +func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { + return &ClusterTestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *ClusterTestTypeStatusApplyConfiguration) WithBlah(value string) *ClusterTestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/examples/pkg/generated/applyconfigurations/example-dashed/v1/testtype.go b/examples/pkg/generated/applyconfigurations/example-dashed/v1/testtype.go new file mode 100644 index 000000000..50852472e --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/example-dashed/v1/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 v1 + +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("exampledashed.some.corp/v1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// 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/applyconfigurations/utils.go b/examples/pkg/generated/applyconfigurations/utils.go index 780dec64e..bd74f3734 100644 --- a/examples/pkg/generated/applyconfigurations/utils.go +++ b/examples/pkg/generated/applyconfigurations/utils.go @@ -23,6 +23,7 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" testing "k8s.io/client-go/testing" + exampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" v1 "acme.corp/pkg/apis/example/v1" v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" v1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -30,6 +31,7 @@ import ( example3v1 "acme.corp/pkg/apis/example3/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/example-dashed/v1" examplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" examplev1alpha1 "acme.corp/pkg/generated/applyconfigurations/example/v1alpha1" examplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" @@ -86,6 +88,14 @@ func ForKind(kind schema.GroupVersionKind) interface{} { case example3v1.SchemeGroupVersion.WithKind("TestType"): return &applyconfigurationsexample3v1.TestTypeApplyConfiguration{} + // Group=exampledashed.some.corp, Version=v1 + case exampledashedv1.SchemeGroupVersion.WithKind("ClusterTestType"): + return &applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration{} + case exampledashedv1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): + return &applyconfigurationsexampledashedv1.ClusterTestTypeStatusApplyConfiguration{} + case exampledashedv1.SchemeGroupVersion.WithKind("TestType"): + return &applyconfigurationsexampledashedv1.TestTypeApplyConfiguration{} + // Group=existinginterfaces.acme.corp, Version=v1 case existinginterfacesv1.SchemeGroupVersion.WithKind("ClusterTestType"): return &applyconfigurationsexistinginterfacesv1.ClusterTestTypeApplyConfiguration{} diff --git a/examples/pkg/generated/informers/externalversions/example-dashed/interface.go b/examples/pkg/generated/informers/externalversions/example-dashed/interface.go new file mode 100644 index 000000000..2739bc639 --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/example-dashed/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 ( + v1 "acme.corp/pkg/generated/informers/externalversions/example-dashed/v1" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/generated/informers/externalversions/example-dashed/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..b5f86b469 --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/example-dashed/v1/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 v1 + +import ( + context "context" + time "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + apisexampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + exampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" +) + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1.ClusterTestTypeLister +} + +type clusterTestTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewClusterTestTypeInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &apisexampledashedv1.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(&apisexampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeInformer) Lister() exampledashedv1.ClusterTestTypeLister { + return exampledashedv1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informers/externalversions/example-dashed/v1/interface.go b/examples/pkg/generated/informers/externalversions/example-dashed/v1/interface.go new file mode 100644 index 000000000..066225ba4 --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/example-dashed/v1/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 v1 + +import ( + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // ClusterTestTypes returns a ClusterTestTypeInformer. + ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeInformer. +func (v *version) ClusterTestTypes() ClusterTestTypeInformer { + return &clusterTestTypeInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// TestTypes returns a TestTypeInformer. +func (v *version) TestTypes() TestTypeInformer { + return &testTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/generated/informers/externalversions/example-dashed/v1/testtype.go b/examples/pkg/generated/informers/externalversions/example-dashed/v1/testtype.go new file mode 100644 index 000000000..2af41d1df --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/example-dashed/v1/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 v1 + +import ( + context "context" + time "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + apisexampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + exampledashedv1 "acme.corp/pkg/generated/listers/exampledashed/v1" +) + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1.TestTypeLister +} + +type testTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &apisexampledashedv1.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(&apisexampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeInformer) Lister() exampledashedv1.TestTypeLister { + return exampledashedv1.NewTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go index 42689a431..ba42acb25 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1/clustertesttype.go @@ -19,7 +19,7 @@ limitations under the License. package v1 import ( - "context" + context "context" time "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - examplev1 "acme.corp/pkg/apis/example/v1" + apisexamplev1 "acme.corp/pkg/apis/example/v1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/example/v1" + examplev1 "acme.corp/pkg/generated/listers/example/v1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.ClusterTestTypeLister + Lister() examplev1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -71,7 +71,7 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod return client.ExampleV1().ClusterTestTypes().Watch(context.TODO(), options) }, }, - &examplev1.ClusterTestType{}, + &apisexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +82,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { - return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() examplev1.ClusterTestTypeLister { + return examplev1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1/testtype.go b/examples/pkg/generated/informers/externalversions/example/v1/testtype.go index f5aaf6d95..0b4ffe248 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1/testtype.go @@ -19,7 +19,7 @@ limitations under the License. package v1 import ( - "context" + context "context" time "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - examplev1 "acme.corp/pkg/apis/example/v1" + apisexamplev1 "acme.corp/pkg/apis/example/v1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/example/v1" + examplev1 "acme.corp/pkg/generated/listers/example/v1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.TestTypeLister + Lister() examplev1.TestTypeLister } type testTypeInformer struct { @@ -72,7 +72,7 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r return client.ExampleV1().TestTypes(namespace).Watch(context.TODO(), options) }, }, - &examplev1.TestType{}, + &apisexamplev1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +83,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1.TestTypeLister { - return v1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() examplev1.TestTypeLister { + return examplev1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go index 9f9b47fd2..51b5e4dac 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1alpha1/clustertesttype.go @@ -19,7 +19,7 @@ limitations under the License. package v1alpha1 import ( - "context" + context "context" time "time" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1alpha1.ClusterTestTypeLister + Lister() examplev1alpha1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -71,7 +71,7 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod return client.ExampleV1alpha1().ClusterTestTypes().Watch(context.TODO(), options) }, }, - &examplev1alpha1.ClusterTestType{}, + &apisexamplev1alpha1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +82,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1alpha1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1alpha1.ClusterTestTypeLister { - return v1alpha1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() examplev1alpha1.ClusterTestTypeLister { + return examplev1alpha1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go b/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go index adf49636c..4acc2a1c3 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1alpha1/testtype.go @@ -19,7 +19,7 @@ limitations under the License. package v1alpha1 import ( - "context" + context "context" time "time" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" + apisexamplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" + examplev1alpha1 "acme.corp/pkg/generated/listers/example/v1alpha1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1alpha1.TestTypeLister + Lister() examplev1alpha1.TestTypeLister } type testTypeInformer struct { @@ -72,7 +72,7 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r return client.ExampleV1alpha1().TestTypes(namespace).Watch(context.TODO(), options) }, }, - &examplev1alpha1.TestType{}, + &apisexamplev1alpha1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +83,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1alpha1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1alpha1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1alpha1.TestTypeLister { - return v1alpha1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() examplev1alpha1.TestTypeLister { + return examplev1alpha1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go index 61ed3ecfa..41690c961 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1beta1/clustertesttype.go @@ -19,7 +19,7 @@ limitations under the License. package v1beta1 import ( - "context" + context "context" time "time" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1beta1.ClusterTestTypeLister + Lister() examplev1beta1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -71,7 +71,7 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod return client.ExampleV1beta1().ClusterTestTypes().Watch(context.TODO(), options) }, }, - &examplev1beta1.ClusterTestType{}, + &apisexamplev1beta1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +82,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1beta1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1beta1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1beta1.ClusterTestTypeLister { - return v1beta1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() examplev1beta1.ClusterTestTypeLister { + return examplev1beta1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go index 1af6b4a5a..508085fec 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example/v1beta1/testtype.go @@ -19,7 +19,7 @@ limitations under the License. package v1beta1 import ( - "context" + context "context" time "time" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" + apisexamplev1beta1 "acme.corp/pkg/apis/example/v1beta1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" + examplev1beta1 "acme.corp/pkg/generated/listers/example/v1beta1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1beta1.TestTypeLister + Lister() examplev1beta1.TestTypeLister } type testTypeInformer struct { @@ -72,7 +72,7 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r return client.ExampleV1beta1().TestTypes(namespace).Watch(context.TODO(), options) }, }, - &examplev1beta1.TestType{}, + &apisexamplev1beta1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +83,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev1beta1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev1beta1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1beta1.TestTypeLister { - return v1beta1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() examplev1beta1.TestTypeLister { + return examplev1beta1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go index 6538a040e..b386b3958 100644 --- a/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example/v2/clustertesttype.go @@ -19,7 +19,7 @@ limitations under the License. package v2 import ( - "context" + context "context" time "time" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - examplev2 "acme.corp/pkg/apis/example/v2" + apisexamplev2 "acme.corp/pkg/apis/example/v2" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v2 "acme.corp/pkg/generated/listers/example/v2" + examplev2 "acme.corp/pkg/generated/listers/example/v2" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v2.ClusterTestTypeLister + Lister() examplev2.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -71,7 +71,7 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod return client.ExampleV2().ClusterTestTypes().Watch(context.TODO(), options) }, }, - &examplev2.ClusterTestType{}, + &apisexamplev2.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +82,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev2.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev2.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v2.ClusterTestTypeLister { - return v2.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() examplev2.ClusterTestTypeLister { + return examplev2.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example/v2/testtype.go b/examples/pkg/generated/informers/externalversions/example/v2/testtype.go index 217f95beb..aa53616c6 100644 --- a/examples/pkg/generated/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example/v2/testtype.go @@ -19,7 +19,7 @@ limitations under the License. package v2 import ( - "context" + context "context" time "time" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - examplev2 "acme.corp/pkg/apis/example/v2" + apisexamplev2 "acme.corp/pkg/apis/example/v2" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v2 "acme.corp/pkg/generated/listers/example/v2" + examplev2 "acme.corp/pkg/generated/listers/example/v2" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v2.TestTypeLister + Lister() examplev2.TestTypeLister } type testTypeInformer struct { @@ -72,7 +72,7 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r return client.ExampleV2().TestTypes(namespace).Watch(context.TODO(), options) }, }, - &examplev2.TestType{}, + &apisexamplev2.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +83,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&examplev2.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexamplev2.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v2.TestTypeLister { - return v2.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() examplev2.TestTypeLister { + return examplev2.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go index 284219e3f..d5c14e570 100644 --- a/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/example3/v1/clustertesttype.go @@ -19,7 +19,7 @@ limitations under the License. package v1 import ( - "context" + context "context" time "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - example3v1 "acme.corp/pkg/apis/example3/v1" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/example3/v1" + example3v1 "acme.corp/pkg/generated/listers/example3/v1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.ClusterTestTypeLister + Lister() example3v1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -71,7 +71,7 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod return client.Example3V1().ClusterTestTypes().Watch(context.TODO(), options) }, }, - &example3v1.ClusterTestType{}, + &apisexample3v1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +82,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&example3v1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexample3v1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { - return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() example3v1.ClusterTestTypeLister { + return example3v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go b/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go index e9b5b1aa7..4bd066041 100644 --- a/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/example3/v1/testtype.go @@ -19,7 +19,7 @@ limitations under the License. package v1 import ( - "context" + context "context" time "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - example3v1 "acme.corp/pkg/apis/example3/v1" + apisexample3v1 "acme.corp/pkg/apis/example3/v1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/example3/v1" + example3v1 "acme.corp/pkg/generated/listers/example3/v1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.TestTypeLister + Lister() example3v1.TestTypeLister } type testTypeInformer struct { @@ -72,7 +72,7 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r return client.Example3V1().TestTypes(namespace).Watch(context.TODO(), options) }, }, - &example3v1.TestType{}, + &apisexample3v1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +83,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&example3v1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexample3v1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1.TestTypeLister { - return v1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() example3v1.TestTypeLister { + return example3v1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go index f2ad5f554..6f0c2c5e3 100644 --- a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/clustertesttype.go @@ -19,7 +19,7 @@ limitations under the License. package v1 import ( - "context" + context "context" time "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.ClusterTestTypeLister + Lister() existinginterfacesv1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -71,7 +71,7 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod return client.ExistinginterfacesV1().ClusterTestTypes().Watch(context.TODO(), options) }, }, - &existinginterfacesv1.ClusterTestType{}, + &apisexistinginterfacesv1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +82,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexistinginterfacesv1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { - return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() existinginterfacesv1.ClusterTestTypeLister { + return existinginterfacesv1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go index b3f448d76..3f66f9524 100644 --- a/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/existinginterfaces/v1/testtype.go @@ -19,7 +19,7 @@ limitations under the License. package v1 import ( - "context" + context "context" time "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" + apisexistinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" + existinginterfacesv1 "acme.corp/pkg/generated/listers/existinginterfaces/v1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.TestTypeLister + Lister() existinginterfacesv1.TestTypeLister } type testTypeInformer struct { @@ -72,7 +72,7 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r return client.ExistinginterfacesV1().TestTypes(namespace).Watch(context.TODO(), options) }, }, - &existinginterfacesv1.TestType{}, + &apisexistinginterfacesv1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +83,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&existinginterfacesv1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apisexistinginterfacesv1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1.TestTypeLister { - return v1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() existinginterfacesv1.TestTypeLister { + return existinginterfacesv1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/factory.go b/examples/pkg/generated/informers/externalversions/factory.go index 02a666102..f37177fe5 100644 --- a/examples/pkg/generated/informers/externalversions/factory.go +++ b/examples/pkg/generated/informers/externalversions/factory.go @@ -30,6 +30,7 @@ import ( versioned "acme.corp/pkg/generated/clientset/versioned" example "acme.corp/pkg/generated/informers/externalversions/example" + exampledashed "acme.corp/pkg/generated/informers/externalversions/example-dashed" example3 "acme.corp/pkg/generated/informers/externalversions/example3" existinginterfaces "acme.corp/pkg/generated/informers/externalversions/existinginterfaces" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" @@ -259,6 +260,7 @@ type SharedInformerFactory interface { InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer Example() example.Interface + Exampledashed() exampledashed.Interface Example3() example3.Interface Existinginterfaces() existinginterfaces.Interface Secondexample() secondexample.Interface @@ -268,6 +270,10 @@ func (f *sharedInformerFactory) Example() example.Interface { return example.New(f, f.namespace, f.tweakListOptions) } +func (f *sharedInformerFactory) Exampledashed() exampledashed.Interface { + return exampledashed.New(f, f.namespace, f.tweakListOptions) +} + func (f *sharedInformerFactory) Example3() example3.Interface { return example3.New(f, f.namespace, f.tweakListOptions) } diff --git a/examples/pkg/generated/informers/externalversions/generic.go b/examples/pkg/generated/informers/externalversions/generic.go index 9337b236d..dec2cbda0 100644 --- a/examples/pkg/generated/informers/externalversions/generic.go +++ b/examples/pkg/generated/informers/externalversions/generic.go @@ -19,11 +19,12 @@ limitations under the License. package externalversions import ( - "fmt" + fmt "fmt" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" + exampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" v1 "acme.corp/pkg/apis/example/v1" v1alpha1 "acme.corp/pkg/apis/example/v1alpha1" v1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -89,6 +90,12 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case example3v1.SchemeGroupVersion.WithResource("testtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil + // Group=exampledashed.some.corp, Version=v1 + case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Exampledashed().V1().ClusterTestTypes().Informer()}, nil + case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Exampledashed().V1().TestTypes().Informer()}, nil + // Group=existinginterfaces.acme.corp, Version=v1 case existinginterfacesv1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Existinginterfaces().V1().ClusterTestTypes().Informer()}, nil diff --git a/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go index bc2d6b573..bd71b4a9d 100644 --- a/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/generated/informers/externalversions/secondexample/v1/clustertesttype.go @@ -19,7 +19,7 @@ limitations under the License. package v1 import ( - "context" + context "context" time "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" ) // ClusterTestTypeInformer provides access to a shared informer and lister for // ClusterTestTypes. type ClusterTestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.ClusterTestTypeLister + Lister() secondexamplev1.ClusterTestTypeLister } type clusterTestTypeInformer struct { @@ -71,7 +71,7 @@ func NewFilteredClusterTestTypeInformer(client versioned.Interface, resyncPeriod return client.SecondexampleV1().ClusterTestTypes().Watch(context.TODO(), options) }, }, - &secondexamplev1.ClusterTestType{}, + &apissecondexamplev1.ClusterTestType{}, resyncPeriod, indexers, ) @@ -82,9 +82,9 @@ func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, re } func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.ClusterTestType{}, f.defaultInformer) + return f.factory.InformerFor(&apissecondexamplev1.ClusterTestType{}, f.defaultInformer) } -func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { - return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +func (f *clusterTestTypeInformer) Lister() secondexamplev1.ClusterTestTypeLister { + return secondexamplev1.NewClusterTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go b/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go index 358462eb4..e23cc299e 100644 --- a/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/generated/informers/externalversions/secondexample/v1/testtype.go @@ -19,7 +19,7 @@ limitations under the License. package v1 import ( - "context" + context "context" time "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,17 +27,17 @@ import ( watch "k8s.io/apimachinery/pkg/watch" cache "k8s.io/client-go/tools/cache" - secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" + apissecondexamplev1 "acme.corp/pkg/apis/secondexample/v1" versioned "acme.corp/pkg/generated/clientset/versioned" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" - v1 "acme.corp/pkg/generated/listers/secondexample/v1" + secondexamplev1 "acme.corp/pkg/generated/listers/secondexample/v1" ) // TestTypeInformer provides access to a shared informer and lister for // TestTypes. type TestTypeInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.TestTypeLister + Lister() secondexamplev1.TestTypeLister } type testTypeInformer struct { @@ -72,7 +72,7 @@ func NewFilteredTestTypeInformer(client versioned.Interface, namespace string, r return client.SecondexampleV1().TestTypes(namespace).Watch(context.TODO(), options) }, }, - &secondexamplev1.TestType{}, + &apissecondexamplev1.TestType{}, resyncPeriod, indexers, ) @@ -83,9 +83,9 @@ func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPer } func (f *testTypeInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&secondexamplev1.TestType{}, f.defaultInformer) + return f.factory.InformerFor(&apissecondexamplev1.TestType{}, f.defaultInformer) } -func (f *testTypeInformer) Lister() v1.TestTypeLister { - return v1.NewTestTypeLister(f.Informer().GetIndexer()) +func (f *testTypeInformer) Lister() secondexamplev1.TestTypeLister { + return secondexamplev1.NewTestTypeLister(f.Informer().GetIndexer()) } diff --git a/examples/pkg/generated/listers/example-dashed/v1/clustertesttype.go b/examples/pkg/generated/listers/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..d03533f3a --- /dev/null +++ b/examples/pkg/generated/listers/example-dashed/v1/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 v1 + +import ( + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" + "k8s.io/client-go/tools/cache" + + v1 "acme.corp/pkg/apis/example-dashed/v1" +) + +// ClusterTestTypeLister helps list ClusterTestTypes. +// All objects returned here must be treated as read-only. +type ClusterTestTypeLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) + // Get retrieves the ClusterTestType from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.ClusterTestType, error) + ClusterTestTypeListerExpansion +} + +// clusterTestTypeLister implements the ClusterTestTypeLister interface. +type clusterTestTypeLister struct { + listers.ResourceIndexer[*v1.ClusterTestType] +} + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{listers.New[*v1.ClusterTestType](indexer, v1.Resource("clustertesttype"))} +} diff --git a/examples/pkg/generated/listers/example-dashed/v1/expansion_generated.go b/examples/pkg/generated/listers/example-dashed/v1/expansion_generated.go new file mode 100644 index 000000000..35b3a43bb --- /dev/null +++ b/examples/pkg/generated/listers/example-dashed/v1/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 v1 + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/generated/listers/example-dashed/v1/testtype.go b/examples/pkg/generated/listers/example-dashed/v1/testtype.go new file mode 100644 index 000000000..46bc541eb --- /dev/null +++ b/examples/pkg/generated/listers/example-dashed/v1/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 v1 + +import ( + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" + "k8s.io/client-go/tools/cache" + + v1 "acme.corp/pkg/apis/example-dashed/v1" +) + +// TestTypeLister helps list TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.TestType, err error) + // TestTypes returns an object that can list and get TestTypes. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// testTypeLister implements the TestTypeLister interface. +type testTypeLister struct { + listers.ResourceIndexer[*v1.TestType] +} + +// NewTestTypeLister returns a new TestTypeLister. +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{listers.New[*v1.TestType](indexer, v1.Resource("testtype"))} +} + +// TestTypes returns an object that can list and get TestTypes. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return testTypeNamespaceLister{listers.NewNamespaced[*v1.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 []*v1.TestType, err error) + // Get retrieves the TestType from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + listers.ResourceIndexer[*v1.TestType] +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/clientset.go index aa4ccb8f9..d29554766 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/clientset.go @@ -38,6 +38,7 @@ import ( examplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" ) @@ -46,6 +47,7 @@ type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface Example3V1() example3v1.Example3V1ClusterInterface + ExampledashedV1() exampledashedv1.ExampledashedV1ClusterInterface ExampleV1() examplev1.ExampleV1ClusterInterface ExampleV1alpha1() examplev1alpha1.ExampleV1alpha1ClusterInterface ExampleV1beta1() examplev1beta1.ExampleV1beta1ClusterInterface @@ -59,6 +61,7 @@ type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] example3V1 *example3v1.Example3V1ClusterClient + exampledashedV1 *exampledashedv1.ExampledashedV1ClusterClient exampleV1 *examplev1.ExampleV1ClusterClient exampleV1alpha1 *examplev1alpha1.ExampleV1alpha1ClusterClient exampleV1beta1 *examplev1beta1.ExampleV1beta1ClusterClient @@ -80,6 +83,11 @@ func (c *ClusterClientset) Example3V1() example3v1.Example3V1ClusterInterface { return c.example3V1 } +// ExampledashedV1 retrieves the ExampledashedV1ClusterClient. +func (c *ClusterClientset) ExampledashedV1() exampledashedv1.ExampledashedV1ClusterInterface { + return c.exampledashedV1 +} + // ExampleV1 retrieves the ExampleV1ClusterClient. func (c *ClusterClientset) ExampleV1() examplev1.ExampleV1ClusterInterface { return c.exampleV1 @@ -166,6 +174,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli if err != nil { return nil, err } + cs.exampledashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err diff --git a/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go index 0ee45174b..e6ddf7345 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go @@ -36,6 +36,7 @@ import ( examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" kcpclient "acme.corp/pkg/kcp/clients/clientset/versioned" @@ -49,6 +50,8 @@ import ( fakeexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake" kcpexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" fakeexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" + fakeexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake" kcpexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" fakeexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake" kcpsecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" @@ -94,6 +97,11 @@ func (c *ClusterClientset) Example3V1() kcpexample3v1.Example3V1ClusterInterface return &fakeexample3v1.Example3V1ClusterClient{Fake: c.Fake} } +// ExampledashedV1 retrieves the ExampledashedV1ClusterClient. +func (c *ClusterClientset) ExampledashedV1() kcpexampledashedv1.ExampledashedV1ClusterInterface { + return &fakeexampledashedv1.ExampledashedV1ClusterClient{Fake: c.Fake} +} + // ExampleV1 retrieves the ExampleV1ClusterClient. func (c *ClusterClientset) ExampleV1() kcpexamplev1.ExampleV1ClusterInterface { return &fakeexamplev1.ExampleV1ClusterClient{Fake: c.Fake} @@ -161,6 +169,11 @@ func (c *Clientset) Example3V1() example3v1.Example3V1Interface { return &fakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } +// ExampledashedV1 retrieves the ExampledashedV1Client. +func (c *Clientset) ExampledashedV1() exampledashedv1.ExampledashedV1Interface { + return &fakeexampledashedv1.ExampledashedV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} + // ExampleV1 retrieves the ExampleV1Client. func (c *Clientset) ExampleV1() examplev1.ExampleV1Interface { return &fakeexamplev1.ExampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} diff --git a/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go b/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go index 2a57d2e75..e852e298e 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go @@ -33,6 +33,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -42,6 +43,7 @@ var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ example3v1.AddToScheme, + exampledashedv1.AddToScheme, examplev1.AddToScheme, examplev1alpha1.AddToScheme, examplev1beta1.AddToScheme, diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..f3047a533 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +// 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 exampledashedv1client.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampledashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.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) (*exampledashedv1.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/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go new file mode 100644 index 000000000..68f7dbd86 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/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 v1 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +type ExampledashedV1ClusterInterface interface { + ExampledashedV1ClusterScoper + TestTypesClusterGetter + ClusterTestTypesClusterGetter +} + +type ExampledashedV1ClusterScoper interface { + Cluster(logicalcluster.Path) exampledashedv1.ExampledashedV1Interface +} + +type ExampledashedV1ClusterClient struct { + clientCache kcpclient.Cache[*exampledashedv1.ExampledashedV1Client] +} + +func (c *ExampledashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampledashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *ExampledashedV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *ExampledashedV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new ExampledashedV1ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampledashedV1ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new ExampledashedV1ClusterClient 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) (*ExampledashedV1ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*exampledashedv1.ExampledashedV1Client]{ + NewForConfigAndClient: exampledashedv1.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &ExampledashedV1ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new ExampledashedV1ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampledashedV1ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go new file mode 100644 index 000000000..10e39104d --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "exampledashed.some.corp", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "exampledashed.some.corp", Version: "v1", Kind: "ClusterTestType"} + +type clusterTestTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.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) (*exampledashedv1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &exampledashedv1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.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 *exampledashedv1.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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), &exampledashedv1.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, &exampledashedv1.ClusterTestTypeList{}) + return err +} + +func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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) (*exampledashedv1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &exampledashedv1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.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) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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"), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go new file mode 100644 index 000000000..54387657b --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/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" + + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" +) + +var _ kcpexampledashedv1.ExampledashedV1ClusterInterface = (*ExampledashedV1ClusterClient)(nil) + +type ExampledashedV1ClusterClient struct { + *kcptesting.Fake +} + +func (c *ExampledashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampledashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &ExampledashedV1Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *ExampledashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { + return &testTypesClusterClient{Fake: c.Fake} +} + +func (c *ExampledashedV1ClusterClient) ClusterTestTypes() kcpexampledashedv1.ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterClient{Fake: c.Fake} +} + +var _ exampledashedv1.ExampledashedV1Interface = (*ExampledashedV1Client)(nil) + +type ExampledashedV1Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *ExampledashedV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *ExampledashedV1Client) TestTypes(namespace string) exampledashedv1.TestTypeInterface { + return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} + +func (c *ExampledashedV1Client) ClusterTestTypes() exampledashedv1.ClusterTestTypeInterface { + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go new file mode 100644 index 000000000..93d4ff3cc --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/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" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" +) + +var testTypesResource = schema.GroupVersionResource{Group: "exampledashed.some.corp", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "exampledashed.some.corp", Version: "v1", Kind: "TestType"} + +type testTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexampledashedv1.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) (*exampledashedv1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &exampledashedv1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.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) exampledashedv1client.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 *exampledashedv1.TestType, opts metav1.CreateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Update(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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), &exampledashedv1.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, &exampledashedv1.TestTypeList{}) + return err +} + +func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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) (*exampledashedv1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &exampledashedv1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.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) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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"), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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/clients/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go new file mode 100644 index 000000000..27bd419d6 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +// 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) (*exampledashedv1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampledashedV1Client] +} + +// 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) (*exampledashedv1.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 exampledashedv1client.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) exampledashedv1client.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampledashedV1Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv1client.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/clustertesttype.go new file mode 100644 index 000000000..c820faa3f --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + somegroup2v1client "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" +) + +// 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 somegroup2v1client.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) somegroup2v1client.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*somegroup2v1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*somegroup2v1client.Somegroup2V1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) somegroup2v1client.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) (*somegroup2v1.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/clients/clientset/versioned/typed/somegroup2/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/fake/clustertesttype.go new file mode 100644 index 000000000..2018f62cb --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + applyconfigurationssomegroup2v1 "acme.corp/pkg/generated/applyconfigurations/somegroup2/v1" + somegroup2v1client "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "somegroup2", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "somegroup2", Version: "v1", Kind: "ClusterTestType"} + +type clusterTestTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) somegroup2v1client.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) (*somegroup2v1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &somegroup2v1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &somegroup2v1.ClusterTestTypeList{ListMeta: obj.(*somegroup2v1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*somegroup2v1.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 *somegroup2v1.ClusterTestType, opts metav1.CreateOptions) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *somegroup2v1.ClusterTestType, opts metav1.UpdateOptions) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *somegroup2v1.ClusterTestType, opts metav1.UpdateOptions) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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), &somegroup2v1.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, &somegroup2v1.ClusterTestTypeList{}) + return err +} + +func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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) (*somegroup2v1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &somegroup2v1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &somegroup2v1.ClusterTestTypeList{ListMeta: obj.(*somegroup2v1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*somegroup2v1.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) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationssomegroup2v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*somegroup2v1.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), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationssomegroup2v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*somegroup2v1.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"), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/fake/somegroup2_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/fake/somegroup2_client.go new file mode 100644 index 000000000..26f212b97 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/fake/somegroup2_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" + + somegroup2v1 "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" + kcpsomegroup2v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1" +) + +var _ kcpsomegroup2v1.Somegroup2V1ClusterInterface = (*Somegroup2V1ClusterClient)(nil) + +type Somegroup2V1ClusterClient struct { + *kcptesting.Fake +} + +func (c *Somegroup2V1ClusterClient) Cluster(clusterPath logicalcluster.Path) somegroup2v1.Somegroup2V1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &Somegroup2V1Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *Somegroup2V1ClusterClient) TestTypes() kcpsomegroup2v1.TestTypeClusterInterface { + return &testTypesClusterClient{Fake: c.Fake} +} + +func (c *Somegroup2V1ClusterClient) ClusterTestTypes() kcpsomegroup2v1.ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterClient{Fake: c.Fake} +} + +var _ somegroup2v1.Somegroup2V1Interface = (*Somegroup2V1Client)(nil) + +type Somegroup2V1Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *Somegroup2V1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *Somegroup2V1Client) TestTypes(namespace string) somegroup2v1.TestTypeInterface { + return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} + +func (c *Somegroup2V1Client) ClusterTestTypes() somegroup2v1.ClusterTestTypeInterface { + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/fake/testtype.go new file mode 100644 index 000000000..e89acf609 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/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" + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + applyconfigurationssomegroup2v1 "acme.corp/pkg/generated/applyconfigurations/somegroup2/v1" + somegroup2v1client "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" + kcpsomegroup2v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1" +) + +var testTypesResource = schema.GroupVersionResource{Group: "somegroup2", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "somegroup2", Version: "v1", Kind: "TestType"} + +type testTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpsomegroup2v1.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) (*somegroup2v1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &somegroup2v1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &somegroup2v1.TestTypeList{ListMeta: obj.(*somegroup2v1.TestTypeList).ListMeta} + for _, item := range obj.(*somegroup2v1.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) somegroup2v1client.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 *somegroup2v1.TestType, opts metav1.CreateOptions) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.TestType), err +} + +func (c *testTypesClient) Update(ctx context.Context, testType *somegroup2v1.TestType, opts metav1.UpdateOptions) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.TestType), err +} + +func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *somegroup2v1.TestType, opts metav1.UpdateOptions) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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), &somegroup2v1.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, &somegroup2v1.TestTypeList{}) + return err +} + +func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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) (*somegroup2v1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &somegroup2v1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &somegroup2v1.TestTypeList{ListMeta: obj.(*somegroup2v1.TestTypeList).ListMeta} + for _, item := range obj.(*somegroup2v1.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) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.TestType), err +} + +func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationssomegroup2v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*somegroup2v1.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), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.TestType), err +} + +func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationssomegroup2v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*somegroup2v1.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"), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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/clients/clientset/versioned/typed/somegroup2/v1/somegroup2_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/somegroup2_client.go new file mode 100644 index 000000000..6ec323b7e --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/somegroup2_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 v1 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + somegroup2v1 "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" +) + +type Somegroup2V1ClusterInterface interface { + Somegroup2V1ClusterScoper + TestTypesClusterGetter + ClusterTestTypesClusterGetter +} + +type Somegroup2V1ClusterScoper interface { + Cluster(logicalcluster.Path) somegroup2v1.Somegroup2V1Interface +} + +type Somegroup2V1ClusterClient struct { + clientCache kcpclient.Cache[*somegroup2v1.Somegroup2V1Client] +} + +func (c *Somegroup2V1ClusterClient) Cluster(clusterPath logicalcluster.Path) somegroup2v1.Somegroup2V1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *Somegroup2V1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *Somegroup2V1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new Somegroup2V1ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*Somegroup2V1ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new Somegroup2V1ClusterClient 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) (*Somegroup2V1ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*somegroup2v1.Somegroup2V1Client]{ + NewForConfigAndClient: somegroup2v1.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &Somegroup2V1ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new Somegroup2V1ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Somegroup2V1ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/testtype.go new file mode 100644 index 000000000..8bc379b6a --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + somegroup2v1client "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" +) + +// 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) (*somegroup2v1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*somegroup2v1client.Somegroup2V1Client] +} + +// 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) (*somegroup2v1.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 somegroup2v1client.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) somegroup2v1client.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*somegroup2v1client.Somegroup2V1Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) somegroup2v1client.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..31fab0eab --- /dev/null +++ b/examples/pkg/kcp/clients/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/clients/informers/externalversions/exampledashed/v1" + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // V1 provides access to the shared informers in V1. + V1() v1.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} +} + +// V1 returns a new v1.ClusterInterface. +func (g *group) V1() v1.ClusterInterface { + return v1.New(g.factory, g.tweakListOptions) +} + +type Interface interface { + // V1 provides access to the shared informers in V1. + V1() v1.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} +} + +// V1 returns a new v1.ClusterInterface. +func (g *scopedGroup) V1() v1.Interface { + return v1.NewScoped(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..ff46fe7bf --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + scopedclientset "acme.corp/pkg/generated/clientset/versioned" + clientset "acme.corp/pkg/kcp/clients/clientset/versioned" + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcp/clients/listers/exampledashed/v1" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1listers.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.ExampledashedV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.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(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeClusterInformer) Lister() exampledashedv1listers.ClusterTestTypeClusterLister { + return exampledashedv1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1listers.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 exampledashedv1listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *clusterTestTypeInformer) Lister() exampledashedv1listers.ClusterTestTypeLister { + return f.lister +} + +type clusterTestTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeScopedInformer) Lister() exampledashedv1listers.ClusterTestTypeLister { + return exampledashedv1listers.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.ExampledashedV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.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/clients/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go new file mode 100644 index 000000000..3034bb594 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/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 v1 + +import ( + "acme.corp/pkg/kcp/clients/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/clients/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go new file mode 100644 index 000000000..00d0d1924 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + scopedclientset "acme.corp/pkg/generated/clientset/versioned" + clientset "acme.corp/pkg/kcp/clients/clientset/versioned" + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcp/clients/listers/exampledashed/v1" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1listers.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.ExampledashedV1().TestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().TestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.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(&exampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeClusterInformer) Lister() exampledashedv1listers.TestTypeClusterLister { + return exampledashedv1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1listers.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 exampledashedv1listers.TestTypeLister +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *testTypeInformer) Lister() exampledashedv1listers.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(&exampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeScopedInformer) Lister() exampledashedv1listers.TestTypeLister { + return exampledashedv1listers.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.ExampledashedV1().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &exampledashedv1.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/clients/informers/externalversions/factory.go b/examples/pkg/kcp/clients/informers/externalversions/factory.go index f6fafbfef..f649660f9 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcp/clients/informers/externalversions/factory.go @@ -38,6 +38,7 @@ import ( clientset "acme.corp/pkg/kcp/clients/clientset/versioned" exampleinformers "acme.corp/pkg/kcp/clients/informers/externalversions/example" example3informers "acme.corp/pkg/kcp/clients/informers/externalversions/example3" + exampledashedinformers "acme.corp/pkg/kcp/clients/informers/externalversions/exampledashed" existinginterfacesinformers "acme.corp/pkg/kcp/clients/informers/externalversions/existinginterfaces" "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" secondexampleinformers "acme.corp/pkg/kcp/clients/informers/externalversions/secondexample" @@ -274,6 +275,7 @@ type SharedInformerFactory interface { Example() exampleinformers.ClusterInterface Example3() example3informers.ClusterInterface + Exampledashed() exampledashedinformers.ClusterInterface Existinginterfaces() existinginterfacesinformers.ClusterInterface Secondexample() secondexampleinformers.ClusterInterface } @@ -286,6 +288,10 @@ func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { return example3informers.New(f, f.tweakListOptions) } +func (f *sharedInformerFactory) Exampledashed() exampledashedinformers.ClusterInterface { + return exampledashedinformers.New(f, f.tweakListOptions) +} + func (f *sharedInformerFactory) Existinginterfaces() existinginterfacesinformers.ClusterInterface { return existinginterfacesinformers.New(f, f.tweakListOptions) } @@ -440,6 +446,7 @@ type SharedScopedInformerFactory interface { Example() exampleinformers.Interface Example3() example3informers.Interface + Exampledashed() exampledashedinformers.Interface Existinginterfaces() existinginterfacesinformers.Interface Secondexample() secondexampleinformers.Interface } @@ -452,6 +459,10 @@ func (f *sharedScopedInformerFactory) Example3() example3informers.Interface { return example3informers.NewScoped(f, f.namespace, f.tweakListOptions) } +func (f *sharedScopedInformerFactory) Exampledashed() exampledashedinformers.Interface { + return exampledashedinformers.NewScoped(f, f.namespace, f.tweakListOptions) +} + func (f *sharedScopedInformerFactory) Existinginterfaces() existinginterfacesinformers.Interface { return existinginterfacesinformers.NewScoped(f, f.namespace, f.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/generic.go b/examples/pkg/kcp/clients/informers/externalversions/generic.go index 0e9e4a29d..5a725c2a0 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcp/clients/informers/externalversions/generic.go @@ -35,6 +35,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -97,6 +98,11 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().ClusterTestTypes().Informer()}, nil + // Group=exampledashed.some.corp, Version=V1 + case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Exampledashed().V1().TestTypes().Informer()}, nil + case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Exampledashed().V1().ClusterTestTypes().Informer()}, nil // Group=example, Version=V1 case examplev1.SchemeGroupVersion.WithResource("testtypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil @@ -143,6 +149,13 @@ func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionRe case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): informer := f.Example3().V1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + // Group=exampledashed.some.corp, Version=V1 + case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Exampledashed().V1().TestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + informer := f.Exampledashed().V1().ClusterTestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil // Group=example, Version=V1 case examplev1.SchemeGroupVersion.WithResource("testtypes"): informer := f.Example().V1().TestTypes().Informer() diff --git a/examples/pkg/kcp/clients/informers/externalversions/somegroup2/interface.go b/examples/pkg/kcp/clients/informers/externalversions/somegroup2/interface.go new file mode 100644 index 000000000..770955ff2 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/somegroup2/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 somegroup2 + +import ( + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + "acme.corp/pkg/kcp/clients/informers/externalversions/somegroup2/v1" +) + +type ClusterInterface interface { + // V1 provides access to the shared informers in V1. + V1() v1.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} +} + +// V1 returns a new v1.ClusterInterface. +func (g *group) V1() v1.ClusterInterface { + return v1.New(g.factory, g.tweakListOptions) +} + +type Interface interface { + // V1 provides access to the shared informers in V1. + V1() v1.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} +} + +// V1 returns a new v1.ClusterInterface. +func (g *scopedGroup) V1() v1.Interface { + return v1.NewScoped(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/somegroup2/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/somegroup2/v1/clustertesttype.go new file mode 100644 index 000000000..35a25619f --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + scopedclientset "acme.corp/pkg/generated/clientset/versioned" + clientset "acme.corp/pkg/kcp/clients/clientset/versioned" + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + somegroup2v1listers "acme.corp/pkg/kcp/clients/listers/somegroup2/v1" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() somegroup2v1listers.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.Somegroup2V1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Somegroup2V1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &somegroup2v1.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(&somegroup2v1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeClusterInformer) Lister() somegroup2v1listers.ClusterTestTypeClusterLister { + return somegroup2v1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() somegroup2v1listers.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 somegroup2v1listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *clusterTestTypeInformer) Lister() somegroup2v1listers.ClusterTestTypeLister { + return f.lister +} + +type clusterTestTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&somegroup2v1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeScopedInformer) Lister() somegroup2v1listers.ClusterTestTypeLister { + return somegroup2v1listers.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.Somegroup2V1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Somegroup2V1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &somegroup2v1.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/clients/informers/externalversions/somegroup2/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/somegroup2/v1/interface.go new file mode 100644 index 000000000..3034bb594 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/somegroup2/v1/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 v1 + +import ( + "acme.corp/pkg/kcp/clients/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/clients/informers/externalversions/somegroup2/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/somegroup2/v1/testtype.go new file mode 100644 index 000000000..8521edb01 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + scopedclientset "acme.corp/pkg/generated/clientset/versioned" + clientset "acme.corp/pkg/kcp/clients/clientset/versioned" + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + somegroup2v1listers "acme.corp/pkg/kcp/clients/listers/somegroup2/v1" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() somegroup2v1listers.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.Somegroup2V1().TestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Somegroup2V1().TestTypes().Watch(context.TODO(), options) + }, + }, + &somegroup2v1.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(&somegroup2v1.TestType{}, f.defaultInformer) +} + +func (f *testTypeClusterInformer) Lister() somegroup2v1listers.TestTypeClusterLister { + return somegroup2v1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() somegroup2v1listers.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 somegroup2v1listers.TestTypeLister +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *testTypeInformer) Lister() somegroup2v1listers.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(&somegroup2v1.TestType{}, f.defaultInformer) +} + +func (f *testTypeScopedInformer) Lister() somegroup2v1listers.TestTypeLister { + return somegroup2v1listers.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.Somegroup2V1().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Somegroup2V1().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &somegroup2v1.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/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..943a047e7 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" +) + +// 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 []*exampledashedv1.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 []*exampledashedv1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv1.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 []*exampledashedv1.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) (*exampledashedv1.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 []*exampledashedv1.ClusterTestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv1.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 []*exampledashedv1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeScopedLister) Get(name string) (*exampledashedv1.ClusterTestType, error) { + key := name + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv1.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv1.ClusterTestType), nil +} diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype_expansion.go new file mode 100644 index 000000000..a85e878f1 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/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 v1 + +// 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/clients/listers/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go new file mode 100644 index 000000000..30453a7d2 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" +) + +// 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 []*exampledashedv1.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 []*exampledashedv1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv1.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 []*exampledashedv1.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 []*exampledashedv1.TestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.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 []*exampledashedv1.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) (*exampledashedv1.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 []*exampledashedv1.TestType, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("testtypes"), name) + } + return obj.(*exampledashedv1.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 []*exampledashedv1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.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 []*exampledashedv1.TestType, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeScopedNamespaceLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("testtypes"), name) + } + return obj.(*exampledashedv1.TestType), nil +} diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype_expansion.go new file mode 100644 index 000000000..3f50c325f --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/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 v1 + +// 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/kcp/clients/listers/somegroup2/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/somegroup2/v1/clustertesttype.go new file mode 100644 index 000000000..4efa00eb4 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" +) + +// 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 []*somegroup2v1.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 []*somegroup2v1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*somegroup2v1.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 []*somegroup2v1.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) (*somegroup2v1.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 []*somegroup2v1.ClusterTestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeLister) Get(name string) (*somegroup2v1.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(somegroup2v1.Resource("clustertesttypes"), name) + } + return obj.(*somegroup2v1.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 []*somegroup2v1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeScopedLister) Get(name string) (*somegroup2v1.ClusterTestType, error) { + key := name + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(somegroup2v1.Resource("clustertesttypes"), name) + } + return obj.(*somegroup2v1.ClusterTestType), nil +} diff --git a/examples/pkg/kcp/clients/listers/somegroup2/v1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/somegroup2/v1/clustertesttype_expansion.go new file mode 100644 index 000000000..a85e878f1 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/somegroup2/v1/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 v1 + +// 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/clients/listers/somegroup2/v1/testtype.go b/examples/pkg/kcp/clients/listers/somegroup2/v1/testtype.go new file mode 100644 index 000000000..5198b1333 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" +) + +// 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 []*somegroup2v1.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 []*somegroup2v1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*somegroup2v1.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 []*somegroup2v1.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 []*somegroup2v1.TestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.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 []*somegroup2v1.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) (*somegroup2v1.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 []*somegroup2v1.TestType, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeNamespaceLister) Get(name string) (*somegroup2v1.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(somegroup2v1.Resource("testtypes"), name) + } + return obj.(*somegroup2v1.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 []*somegroup2v1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.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 []*somegroup2v1.TestType, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeScopedNamespaceLister) Get(name string) (*somegroup2v1.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(somegroup2v1.Resource("testtypes"), name) + } + return obj.(*somegroup2v1.TestType), nil +} diff --git a/examples/pkg/kcp/clients/listers/somegroup2/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/somegroup2/v1/testtype_expansion.go new file mode 100644 index 000000000..3f50c325f --- /dev/null +++ b/examples/pkg/kcp/clients/listers/somegroup2/v1/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 v1 + +// 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/clientset.go b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go index 5db861f6a..b4e3e1b25 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go @@ -38,6 +38,7 @@ import ( examplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" ) @@ -46,6 +47,7 @@ type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface Example3V1() example3v1.Example3V1ClusterInterface + ExampledashedV1() exampledashedv1.ExampledashedV1ClusterInterface ExampleV1() examplev1.ExampleV1ClusterInterface ExampleV1alpha1() examplev1alpha1.ExampleV1alpha1ClusterInterface ExampleV1beta1() examplev1beta1.ExampleV1beta1ClusterInterface @@ -59,6 +61,7 @@ type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] example3V1 *example3v1.Example3V1ClusterClient + exampledashedV1 *exampledashedv1.ExampledashedV1ClusterClient exampleV1 *examplev1.ExampleV1ClusterClient exampleV1alpha1 *examplev1alpha1.ExampleV1alpha1ClusterClient exampleV1beta1 *examplev1beta1.ExampleV1beta1ClusterClient @@ -80,6 +83,11 @@ func (c *ClusterClientset) Example3V1() example3v1.Example3V1ClusterInterface { return c.example3V1 } +// ExampledashedV1 retrieves the ExampledashedV1ClusterClient. +func (c *ClusterClientset) ExampledashedV1() exampledashedv1.ExampledashedV1ClusterInterface { + return c.exampledashedV1 +} + // ExampleV1 retrieves the ExampleV1ClusterClient. func (c *ClusterClientset) ExampleV1() examplev1.ExampleV1ClusterInterface { return c.exampleV1 @@ -166,6 +174,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli if err != nil { return nil, err } + cs.exampledashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.exampleV1, err = examplev1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go index ec95d4394..0285aaa83 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go @@ -36,6 +36,7 @@ import ( examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" kcpclient "acme.corp/pkg/kcpexisting/clients/clientset/versioned" @@ -49,6 +50,8 @@ import ( fakeexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake" kcpexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" fakeexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" + fakeexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake" kcpexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" fakeexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake" kcpsecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" @@ -94,6 +97,11 @@ func (c *ClusterClientset) Example3V1() kcpexample3v1.Example3V1ClusterInterface return &fakeexample3v1.Example3V1ClusterClient{Fake: c.Fake} } +// ExampledashedV1 retrieves the ExampledashedV1ClusterClient. +func (c *ClusterClientset) ExampledashedV1() kcpexampledashedv1.ExampledashedV1ClusterInterface { + return &fakeexampledashedv1.ExampledashedV1ClusterClient{Fake: c.Fake} +} + // ExampleV1 retrieves the ExampleV1ClusterClient. func (c *ClusterClientset) ExampleV1() kcpexamplev1.ExampleV1ClusterInterface { return &fakeexamplev1.ExampleV1ClusterClient{Fake: c.Fake} @@ -161,6 +169,11 @@ func (c *Clientset) Example3V1() example3v1.Example3V1Interface { return &fakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } +// ExampledashedV1 retrieves the ExampledashedV1Client. +func (c *Clientset) ExampledashedV1() exampledashedv1.ExampledashedV1Interface { + return &fakeexampledashedv1.ExampledashedV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} + // ExampleV1 retrieves the ExampleV1Client. func (c *Clientset) ExampleV1() examplev1.ExampleV1Interface { return &fakeexamplev1.ExampleV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go index 2a57d2e75..e852e298e 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go @@ -33,6 +33,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -42,6 +43,7 @@ var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ example3v1.AddToScheme, + exampledashedv1.AddToScheme, examplev1.AddToScheme, examplev1alpha1.AddToScheme, examplev1beta1.AddToScheme, diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..f3047a533 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +// 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 exampledashedv1client.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampledashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.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) (*exampledashedv1.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/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go new file mode 100644 index 000000000..68f7dbd86 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/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 v1 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +type ExampledashedV1ClusterInterface interface { + ExampledashedV1ClusterScoper + TestTypesClusterGetter + ClusterTestTypesClusterGetter +} + +type ExampledashedV1ClusterScoper interface { + Cluster(logicalcluster.Path) exampledashedv1.ExampledashedV1Interface +} + +type ExampledashedV1ClusterClient struct { + clientCache kcpclient.Cache[*exampledashedv1.ExampledashedV1Client] +} + +func (c *ExampledashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampledashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *ExampledashedV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *ExampledashedV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new ExampledashedV1ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampledashedV1ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new ExampledashedV1ClusterClient 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) (*ExampledashedV1ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*exampledashedv1.ExampledashedV1Client]{ + NewForConfigAndClient: exampledashedv1.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &ExampledashedV1ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new ExampledashedV1ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampledashedV1ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go new file mode 100644 index 000000000..10e39104d --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "exampledashed.some.corp", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "exampledashed.some.corp", Version: "v1", Kind: "ClusterTestType"} + +type clusterTestTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.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) (*exampledashedv1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &exampledashedv1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.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 *exampledashedv1.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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), &exampledashedv1.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, &exampledashedv1.ClusterTestTypeList{}) + return err +} + +func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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) (*exampledashedv1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &exampledashedv1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.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) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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"), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go new file mode 100644 index 000000000..62ed880a9 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/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" + + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" +) + +var _ kcpexampledashedv1.ExampledashedV1ClusterInterface = (*ExampledashedV1ClusterClient)(nil) + +type ExampledashedV1ClusterClient struct { + *kcptesting.Fake +} + +func (c *ExampledashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampledashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &ExampledashedV1Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *ExampledashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { + return &testTypesClusterClient{Fake: c.Fake} +} + +func (c *ExampledashedV1ClusterClient) ClusterTestTypes() kcpexampledashedv1.ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterClient{Fake: c.Fake} +} + +var _ exampledashedv1.ExampledashedV1Interface = (*ExampledashedV1Client)(nil) + +type ExampledashedV1Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *ExampledashedV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *ExampledashedV1Client) TestTypes(namespace string) exampledashedv1.TestTypeInterface { + return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} + +func (c *ExampledashedV1Client) ClusterTestTypes() exampledashedv1.ClusterTestTypeInterface { + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go new file mode 100644 index 000000000..6d458e556 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/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" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" +) + +var testTypesResource = schema.GroupVersionResource{Group: "exampledashed.some.corp", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "exampledashed.some.corp", Version: "v1", Kind: "TestType"} + +type testTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexampledashedv1.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) (*exampledashedv1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &exampledashedv1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.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) exampledashedv1client.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 *exampledashedv1.TestType, opts metav1.CreateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Update(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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), &exampledashedv1.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, &exampledashedv1.TestTypeList{}) + return err +} + +func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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) (*exampledashedv1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &exampledashedv1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.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) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.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"), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.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/clients/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go new file mode 100644 index 000000000..27bd419d6 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +// 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) (*exampledashedv1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampledashedV1Client] +} + +// 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) (*exampledashedv1.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 exampledashedv1client.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) exampledashedv1client.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampledashedV1Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv1client.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/clustertesttype.go new file mode 100644 index 000000000..c820faa3f --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + somegroup2v1client "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" +) + +// 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 somegroup2v1client.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) somegroup2v1client.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*somegroup2v1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*somegroup2v1client.Somegroup2V1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) somegroup2v1client.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) (*somegroup2v1.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/clients/clientset/versioned/typed/somegroup2/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/fake/clustertesttype.go new file mode 100644 index 000000000..2018f62cb --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + applyconfigurationssomegroup2v1 "acme.corp/pkg/generated/applyconfigurations/somegroup2/v1" + somegroup2v1client "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "somegroup2", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "somegroup2", Version: "v1", Kind: "ClusterTestType"} + +type clusterTestTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) somegroup2v1client.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) (*somegroup2v1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &somegroup2v1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &somegroup2v1.ClusterTestTypeList{ListMeta: obj.(*somegroup2v1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*somegroup2v1.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 *somegroup2v1.ClusterTestType, opts metav1.CreateOptions) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *somegroup2v1.ClusterTestType, opts metav1.UpdateOptions) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *somegroup2v1.ClusterTestType, opts metav1.UpdateOptions) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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), &somegroup2v1.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, &somegroup2v1.ClusterTestTypeList{}) + return err +} + +func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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) (*somegroup2v1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &somegroup2v1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &somegroup2v1.ClusterTestTypeList{ListMeta: obj.(*somegroup2v1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*somegroup2v1.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) (*somegroup2v1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationssomegroup2v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*somegroup2v1.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), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationssomegroup2v1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*somegroup2v1.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"), &somegroup2v1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.ClusterTestType), err +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/fake/somegroup2_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/fake/somegroup2_client.go new file mode 100644 index 000000000..afd57720c --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/fake/somegroup2_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" + + somegroup2v1 "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" + kcpsomegroup2v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1" +) + +var _ kcpsomegroup2v1.Somegroup2V1ClusterInterface = (*Somegroup2V1ClusterClient)(nil) + +type Somegroup2V1ClusterClient struct { + *kcptesting.Fake +} + +func (c *Somegroup2V1ClusterClient) Cluster(clusterPath logicalcluster.Path) somegroup2v1.Somegroup2V1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &Somegroup2V1Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *Somegroup2V1ClusterClient) TestTypes() kcpsomegroup2v1.TestTypeClusterInterface { + return &testTypesClusterClient{Fake: c.Fake} +} + +func (c *Somegroup2V1ClusterClient) ClusterTestTypes() kcpsomegroup2v1.ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterClient{Fake: c.Fake} +} + +var _ somegroup2v1.Somegroup2V1Interface = (*Somegroup2V1Client)(nil) + +type Somegroup2V1Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *Somegroup2V1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *Somegroup2V1Client) TestTypes(namespace string) somegroup2v1.TestTypeInterface { + return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} + +func (c *Somegroup2V1Client) ClusterTestTypes() somegroup2v1.ClusterTestTypeInterface { + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/fake/testtype.go new file mode 100644 index 000000000..197188ddb --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/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" + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + applyconfigurationssomegroup2v1 "acme.corp/pkg/generated/applyconfigurations/somegroup2/v1" + somegroup2v1client "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" + kcpsomegroup2v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1" +) + +var testTypesResource = schema.GroupVersionResource{Group: "somegroup2", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "somegroup2", Version: "v1", Kind: "TestType"} + +type testTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpsomegroup2v1.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) (*somegroup2v1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &somegroup2v1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &somegroup2v1.TestTypeList{ListMeta: obj.(*somegroup2v1.TestTypeList).ListMeta} + for _, item := range obj.(*somegroup2v1.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) somegroup2v1client.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 *somegroup2v1.TestType, opts metav1.CreateOptions) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.TestType), err +} + +func (c *testTypesClient) Update(ctx context.Context, testType *somegroup2v1.TestType, opts metav1.UpdateOptions) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.TestType), err +} + +func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *somegroup2v1.TestType, opts metav1.UpdateOptions) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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), &somegroup2v1.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, &somegroup2v1.TestTypeList{}) + return err +} + +func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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) (*somegroup2v1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &somegroup2v1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &somegroup2v1.TestTypeList{ListMeta: obj.(*somegroup2v1.TestTypeList).ListMeta} + for _, item := range obj.(*somegroup2v1.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) (*somegroup2v1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.TestType), err +} + +func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationssomegroup2v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*somegroup2v1.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), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.TestType), err +} + +func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationssomegroup2v1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*somegroup2v1.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"), &somegroup2v1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*somegroup2v1.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/clients/clientset/versioned/typed/somegroup2/v1/somegroup2_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/somegroup2_client.go new file mode 100644 index 000000000..6ec323b7e --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/somegroup2_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 v1 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + somegroup2v1 "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" +) + +type Somegroup2V1ClusterInterface interface { + Somegroup2V1ClusterScoper + TestTypesClusterGetter + ClusterTestTypesClusterGetter +} + +type Somegroup2V1ClusterScoper interface { + Cluster(logicalcluster.Path) somegroup2v1.Somegroup2V1Interface +} + +type Somegroup2V1ClusterClient struct { + clientCache kcpclient.Cache[*somegroup2v1.Somegroup2V1Client] +} + +func (c *Somegroup2V1ClusterClient) Cluster(clusterPath logicalcluster.Path) somegroup2v1.Somegroup2V1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *Somegroup2V1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *Somegroup2V1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new Somegroup2V1ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*Somegroup2V1ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new Somegroup2V1ClusterClient 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) (*Somegroup2V1ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*somegroup2v1.Somegroup2V1Client]{ + NewForConfigAndClient: somegroup2v1.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &Somegroup2V1ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new Somegroup2V1ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Somegroup2V1ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/testtype.go new file mode 100644 index 000000000..8bc379b6a --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + somegroup2v1client "acme.corp/pkg/generated/clientset/versioned/typed/somegroup2/v1" +) + +// 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) (*somegroup2v1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*somegroup2v1client.Somegroup2V1Client] +} + +// 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) (*somegroup2v1.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 somegroup2v1client.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) somegroup2v1client.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*somegroup2v1client.Somegroup2V1Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) somegroup2v1client.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..8d96762d0 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/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/clients/informers/externalversions/exampledashed/v1" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // V1 provides access to the shared informers in V1. + V1() v1.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} +} + +// V1 returns a new v1.ClusterInterface. +func (g *group) V1() v1.ClusterInterface { + return v1.New(g.factory, g.tweakListOptions) +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..c65b61a3f --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + upstreamexampledashedv1informers "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" + upstreamexampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" + clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcpexisting/clients/listers/exampledashed/v1" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1listers.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.ExampledashedV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.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(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeClusterInformer) Lister() exampledashedv1listers.ClusterTestTypeClusterLister { + return exampledashedv1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +} + +func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type clusterTestTypeInformer struct { + informer cache.SharedIndexInformer + lister upstreamexampledashedv1listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *clusterTestTypeInformer) Lister() upstreamexampledashedv1listers.ClusterTestTypeLister { + return f.lister +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go new file mode 100644 index 000000000..ebae731bf --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/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 v1 + +import ( + "acme.corp/pkg/kcpexisting/clients/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/clients/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go new file mode 100644 index 000000000..e2991d0f6 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + upstreamexampledashedv1informers "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" + upstreamexampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" + clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcpexisting/clients/listers/exampledashed/v1" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1listers.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.ExampledashedV1().TestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampledashedV1().TestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.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(&exampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeClusterInformer) Lister() exampledashedv1listers.TestTypeClusterLister { + return exampledashedv1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +} + +func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister upstreamexampledashedv1listers.TestTypeLister +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *testTypeInformer) Lister() upstreamexampledashedv1listers.TestTypeLister { + return f.lister +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go index d0645ef3f..6054028bd 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go @@ -38,6 +38,7 @@ import ( clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" exampleinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example" example3informers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example3" + exampledashedinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/exampledashed" existinginterfacesinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces" "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" secondexampleinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/secondexample" @@ -273,6 +274,7 @@ type SharedInformerFactory interface { Example() exampleinformers.ClusterInterface Example3() example3informers.ClusterInterface + Exampledashed() exampledashedinformers.ClusterInterface Existinginterfaces() existinginterfacesinformers.ClusterInterface Secondexample() secondexampleinformers.ClusterInterface } @@ -285,6 +287,10 @@ func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { return example3informers.New(f, f.tweakListOptions) } +func (f *sharedInformerFactory) Exampledashed() exampledashedinformers.ClusterInterface { + return exampledashedinformers.New(f, f.tweakListOptions) +} + func (f *sharedInformerFactory) Existinginterfaces() existinginterfacesinformers.ClusterInterface { return existinginterfacesinformers.New(f, f.tweakListOptions) } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go index 96a664308..5d7875030 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go @@ -35,6 +35,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" upstreaminformers "acme.corp/pkg/generated/informers/externalversions" @@ -93,6 +94,11 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().ClusterTestTypes().Informer()}, nil + // Group=exampledashed.some.corp, Version=V1 + case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Exampledashed().V1().TestTypes().Informer()}, nil + case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Exampledashed().V1().ClusterTestTypes().Informer()}, nil // Group=example, Version=V1 case examplev1.SchemeGroupVersion.WithResource("testtypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/interface.go new file mode 100644 index 000000000..72e79108b --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/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 somegroup2 + +import ( + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1" +) + +type ClusterInterface interface { + // V1 provides access to the shared informers in V1. + V1() v1.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} +} + +// V1 returns a new v1.ClusterInterface. +func (g *group) V1() v1.ClusterInterface { + return v1.New(g.factory, g.tweakListOptions) +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1/clustertesttype.go new file mode 100644 index 000000000..0d6916c34 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + upstreamsomegroup2v1informers "acme.corp/pkg/generated/informers/externalversions/somegroup2/v1" + upstreamsomegroup2v1listers "acme.corp/pkg/generated/listers/somegroup2/v1" + clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + somegroup2v1listers "acme.corp/pkg/kcpexisting/clients/listers/somegroup2/v1" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) upstreamsomegroup2v1informers.ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() somegroup2v1listers.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.Somegroup2V1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Somegroup2V1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &somegroup2v1.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(&somegroup2v1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeClusterInformer) Lister() somegroup2v1listers.ClusterTestTypeClusterLister { + return somegroup2v1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +} + +func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamsomegroup2v1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type clusterTestTypeInformer struct { + informer cache.SharedIndexInformer + lister upstreamsomegroup2v1listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *clusterTestTypeInformer) Lister() upstreamsomegroup2v1listers.ClusterTestTypeLister { + return f.lister +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1/interface.go new file mode 100644 index 000000000..ebae731bf --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1/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 v1 + +import ( + "acme.corp/pkg/kcpexisting/clients/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/clients/informers/externalversions/somegroup2/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1/testtype.go new file mode 100644 index 000000000..daae3acfb --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + upstreamsomegroup2v1informers "acme.corp/pkg/generated/informers/externalversions/somegroup2/v1" + upstreamsomegroup2v1listers "acme.corp/pkg/generated/listers/somegroup2/v1" + clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + somegroup2v1listers "acme.corp/pkg/kcpexisting/clients/listers/somegroup2/v1" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) upstreamsomegroup2v1informers.TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() somegroup2v1listers.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.Somegroup2V1().TestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Somegroup2V1().TestTypes().Watch(context.TODO(), options) + }, + }, + &somegroup2v1.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(&somegroup2v1.TestType{}, f.defaultInformer) +} + +func (f *testTypeClusterInformer) Lister() somegroup2v1listers.TestTypeClusterLister { + return somegroup2v1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +} + +func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamsomegroup2v1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister upstreamsomegroup2v1listers.TestTypeLister +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *testTypeInformer) Lister() upstreamsomegroup2v1listers.TestTypeLister { + return f.lister +} diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..ed5630a23 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" +) + +// 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 []*exampledashedv1.ClusterTestType, err error) + // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) exampledashedv1listers.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 []*exampledashedv1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv1.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) exampledashedv1listers.ClusterTestTypeLister { + return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// clusterTestTypeLister implements the exampledashedv1listers.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 []*exampledashedv1.ClusterTestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv1.ClusterTestType), nil +} diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype_expansion.go new file mode 100644 index 000000000..08fb95b1c --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/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 v1 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go new file mode 100644 index 000000000..07d6dc46d --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" +) + +// 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 []*exampledashedv1.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) exampledashedv1listers.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 []*exampledashedv1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv1.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) exampledashedv1listers.TestTypeLister { + return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// testTypeLister implements the exampledashedv1listers.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 []*exampledashedv1.TestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (s *testTypeLister) TestTypes(namespace string) exampledashedv1listers.TestTypeNamespaceLister { + return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +} + +// testTypeNamespaceLister implements the exampledashedv1listers.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 []*exampledashedv1.TestType, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv1.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(exampledashedv1.Resource("testtypes"), name) + } + return obj.(*exampledashedv1.TestType), nil +} diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype_expansion.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype_expansion.go new file mode 100644 index 000000000..835da85d6 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/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 v1 + +// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/clustertesttype.go new file mode 100644 index 000000000..3d6511e13 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + somegroup2v1listers "acme.corp/pkg/generated/listers/somegroup2/v1" +) + +// 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 []*somegroup2v1.ClusterTestType, err error) + // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) somegroup2v1listers.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 []*somegroup2v1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*somegroup2v1.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) somegroup2v1listers.ClusterTestTypeLister { + return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// clusterTestTypeLister implements the somegroup2v1listers.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 []*somegroup2v1.ClusterTestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeLister) Get(name string) (*somegroup2v1.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(somegroup2v1.Resource("clustertesttypes"), name) + } + return obj.(*somegroup2v1.ClusterTestType), nil +} diff --git a/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/clustertesttype_expansion.go new file mode 100644 index 000000000..08fb95b1c --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/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 v1 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/testtype.go new file mode 100644 index 000000000..7f07eaa73 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/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 v1 + +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" + + somegroup2v1 "acme.corp/pkg/apis/somegroup2/v1" + somegroup2v1listers "acme.corp/pkg/generated/listers/somegroup2/v1" +) + +// 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 []*somegroup2v1.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) somegroup2v1listers.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 []*somegroup2v1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*somegroup2v1.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) somegroup2v1listers.TestTypeLister { + return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// testTypeLister implements the somegroup2v1listers.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 []*somegroup2v1.TestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (s *testTypeLister) TestTypes(namespace string) somegroup2v1listers.TestTypeNamespaceLister { + return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +} + +// testTypeNamespaceLister implements the somegroup2v1listers.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 []*somegroup2v1.TestType, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*somegroup2v1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeNamespaceLister) Get(name string) (*somegroup2v1.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(somegroup2v1.Resource("testtypes"), name) + } + return obj.(*somegroup2v1.TestType), nil +} diff --git a/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/testtype_expansion.go b/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/testtype_expansion.go new file mode 100644 index 000000000..835da85d6 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/somegroup2/v1/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 v1 + +// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/go.mod b/go.mod index 1b9a4287b..3f1643e4e 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,18 @@ module github.com/kcp-dev/code-generator/v2 -go 1.22.0 +go 1.22.2 + +toolchain go1.22.2 require ( github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.34.1 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 - golang.org/x/tools v0.24.0 + golang.org/x/tools v0.26.0 k8s.io/apimachinery v0.31.0 k8s.io/code-generator v0.31.0 - k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7 + k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 k8s.io/klog/v2 v2.130.1 sigs.k8s.io/controller-tools v0.16.1 ) @@ -27,13 +29,15 @@ require ( github.com/nxadm/tail v1.4.8 // indirect github.com/onsi/ginkgo/v2 v2.20.0 // indirect golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect - golang.org/x/mod v0.20.0 // indirect - golang.org/x/net v0.28.0 // indirect + golang.org/x/mod v0.21.0 // indirect + golang.org/x/net v0.30.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.24.0 // indirect - golang.org/x/text v0.17.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace k8s.io/code-generator => github.com/mjudeikis/k8s-code-generator v0.0.0-20241212195604-7425a34e0969 diff --git a/go.sum b/go.sum index 62c6a3890..e9139a19e 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mjudeikis/k8s-code-generator v0.0.0-20241212195604-7425a34e0969 h1:d6vbz/g8+2pcyh9+UaPkW9xLRLhAhqktSogawKcWxKU= +github.com/mjudeikis/k8s-code-generator v0.0.0-20241212195604-7425a34e0969/go.mod h1:7+BXLlH/ZgrKmGSML4AoJytgJxvepfK+DbxxrWKc7mw= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -73,15 +75,15 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA= golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= -golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -98,17 +100,17 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -119,8 +121,8 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -136,10 +138,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc= k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= -k8s.io/code-generator v0.31.0 h1:w607nrMi1KeDKB3/F/J4lIoOgAwc+gV9ZKew4XRfMp8= -k8s.io/code-generator v0.31.0/go.mod h1:84y4w3es8rOJOUUP1rLsIiGlO1JuEaPFXQPA9e/K6U0= -k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7 h1:cErOOTkQ3JW19o4lo91fFurouhP8NcoBvb7CkvhZZpk= -k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU= +k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 h1:si3PfKm8dDYxgfbeA6orqrtLkvvIeH8UqffFJDl0bz4= +k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= sigs.k8s.io/controller-tools v0.16.1 h1:gvIsZm+2aimFDIBiDKumR7EBkc+oLxljoUVfRbDI6RI= diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 2e70d5403..c15c7ec28 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -48,13 +48,13 @@ ${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 + 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/example-dashed/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 + 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/example-dashed/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 ${KUBE_INFORMER_GEN} \ --versioned-clientset-package acme.corp/pkg/generated/clientset/versioned \ @@ -62,7 +62,7 @@ ${KUBE_INFORMER_GEN} \ --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ --output-dir ./pkg/generated/informers \ --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 + 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/example-dashed/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 \ diff --git a/pkg/generators/clientgen/clientgen.go b/pkg/generators/clientgen/clientgen.go index d6d10a229..bae3cb579 100644 --- a/pkg/generators/clientgen/clientgen.go +++ b/pkg/generators/clientgen/clientgen.go @@ -226,8 +226,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[types.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 +240,12 @@ 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 types.PackageVersion) parser.Group { + return parser.Group{ Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), + Version: parser.Version(namer.IC(version.Version.String())), PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, + GoName: group.GoName, LowerCaseGroupGoName: namer.IL(group.GoName), } } diff --git a/pkg/generators/informergen/informergen.go b/pkg/generators/informergen/informergen.go index 157585c87..c24514b5c 100644 --- a/pkg/generators/informergen/informergen.go +++ b/pkg/generators/informergen/informergen.go @@ -146,12 +146,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 } @@ -184,9 +184,9 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { "group", group.String(), ) - var onlyVersions []types.Version + var onlyVersions []parser.Version for version := range versions { - onlyVersions = append(onlyVersions, types.Version(namer.IC(version.Version.String()))) + onlyVersions = append(onlyVersions, parser.Version(namer.IC(version.Version.String()))) } sort.Slice(onlyVersions, func(i, j int) bool { return onlyVersions[i].PackageName() < onlyVersions[j].PackageName() @@ -246,8 +246,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[types.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 +260,12 @@ 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 types.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())), + GoName: group.GoName, LowerCaseGroupGoName: namer.IL(group.GoName), } } diff --git a/pkg/generators/listergen/listergen.go b/pkg/generators/listergen/listergen.go index 0aa7ebe48..cde9d6b7b 100644 --- a/pkg/generators/listergen/listergen.go +++ b/pkg/generators/listergen/listergen.go @@ -126,12 +126,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 types.PackageVersion) parser.Group { + return parser.Group{ Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), + Version: parser.Version(namer.IC(version.Version.String())), PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, + GoName: group.GoName, LowerCaseGroupGoName: namer.IL(group.GoName), } } diff --git a/pkg/internal/clientgen/clientset.go b/pkg/internal/clientgen/clientset.go index 943a15fbb..b42849c40 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 @@ -38,6 +37,7 @@ func (c *ClientSet) WriteContent(w io.Writer) error { m := map[string]interface{}{ "name": c.Name, + "packageName": strings.ReplaceAll(c.Name, "-", ""), "packagePath": c.PackagePath, "groups": c.Groups, "singleClusterClientPackagePath": c.SingleClusterClientPackagePath, @@ -51,7 +51,7 @@ var clientset = ` // Code generated by kcp code-generator. DO NOT EDIT. -package {{.name}} +package {{.packageName}} import ( "fmt" @@ -66,14 +66,14 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/util/flowcontrol" -{{range .groups}} {{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} ) type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface -{{range .groups}} {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface +{{range .groups}} {{.GroupGoName}}{{.Version}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface {{end -}} } @@ -81,7 +81,7 @@ type ClusterInterface interface { type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] -{{range .groups}} {{.LowerCaseGroupGoName}}{{.Version}} *{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient +{{range .groups}} {{.GroupGoNameLower}}{{.Version}} *{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient {{end -}} } @@ -95,8 +95,8 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { {{range .groups}} // {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}ClusterClient. -func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { - return c.{{.LowerCaseGroupGoName}}{{.Version}} +func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { + return c.{{.GroupGoNameLower}}{{.Version}} } {{end -}} @@ -152,7 +152,7 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli var cs ClusterClientset cs.clientCache = cache var err error -{{range .groups}} cs.{{.LowerCaseGroupGoName}}{{.Version}}, err = {{.PackageAlias}}.NewForConfigAndClient(&configShallowCopy, httpClient) +{{range .groups}} cs.{{.GroupGoNameLower}}{{.Version}}, err = {{.GoPackageAlias}}.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } diff --git a/pkg/internal/clientgen/fake_clientset.go b/pkg/internal/clientgen/fake_clientset.go index 511f61e70..a1c55251f 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}} {{.GoPackageAlias}} "{{$.singleClusterClientPackagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} -{{range .groups}} kcp{{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} kcp{{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} -{{range .groups}} fake{{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}/fake" +{{range .groups}} fake{{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}/fake" {{end -}} ) @@ -109,8 +108,8 @@ func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { {{range .groups}} // {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}ClusterClient. -func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() kcp{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { - return &fake{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient{Fake: c.Fake} +func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() kcp{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { + return &fake{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient{Fake: c.Fake} } {{end -}} @@ -148,8 +147,8 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { {{range .groups}} // {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}Client. -func (c *Clientset) {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Interface { - return &fake{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Client{Fake: c.Fake, ClusterPath: c.clusterPath} +func (c *Clientset) {{.GroupGoName}}{{.Version}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}Interface { + return &fake{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}Client{Fake: c.Fake, ClusterPath: c.clusterPath} } {{end -}} ` diff --git a/pkg/internal/clientgen/fake_group.go b/pkg/internal/clientgen/fake_group.go index cd3b96b0b..8d9f6672d 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 @@ -59,17 +57,17 @@ import ( "github.com/kcp-dev/logicalcluster/v3" "k8s.io/client-go/rest" - kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{.group.PackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + kcp{{.group.GoPackageAlias}} "{{.packagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) -var _ kcp{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}ClusterInterface = (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient)(nil) +var _ kcp{{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}ClusterInterface = (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient)(nil) type {{.group.GroupGoName}}{{.group.Version}}ClusterClient struct { *kcptesting.Fake } -func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { +func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -77,12 +75,12 @@ func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterP } {{ range .kinds}} -func (c *{{$.group.GroupGoName}}{{$.group.Version}}ClusterClient) {{.Plural}}() kcp{{$.group.PackageAlias}}.{{.String}}ClusterInterface { +func (c *{{$.group.GroupGoName}}{{$.group.Version}}ClusterClient) {{.Plural}}() kcp{{$.group.GoPackageAlias}}.{{.String}}ClusterInterface { return &{{.Plural | lowerFirst}}ClusterClient{Fake: c.Fake} } {{end -}} -var _ {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface = (*{{.group.GroupGoName}}{{.group.Version}}Client)(nil) +var _ {{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface = (*{{.group.GroupGoName}}{{.group.Version}}Client)(nil) type {{.group.GroupGoName}}{{.group.Version}}Client struct { *kcptesting.Fake @@ -95,7 +93,7 @@ func (c *{{.group.GroupGoName}}{{.group.Version}}Client) RESTClient() rest.Inter } {{ range .kinds}} -func (c *{{$.group.GroupGoName}}{{$.group.Version}}Client) {{.Plural}}({{if .IsNamespaced}}namespace string{{end}}) {{$.group.PackageAlias}}.{{.String}}Interface { +func (c *{{$.group.GroupGoName}}{{$.group.Version}}Client) {{.Plural}}({{if .IsNamespaced}}namespace string{{end}}) {{$.group.GoPackageAlias}}.{{.String}}Interface { return &{{.Plural | lowerFirst}}Client{Fake: c.Fake, ClusterPath: c.ClusterPath{{if .IsNamespaced}}, Namespace: namespace{{end}}} } {{end -}} diff --git a/pkg/internal/clientgen/fake_type.go b/pkg/internal/clientgen/fake_type.go index c52abf527..00099ab4a 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.GoPackageAlias}} "{{.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.GoPackageAlias}} "{{.singleClusterApplyConfigurationsPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} {{- if .kind.IsNamespaced}} - kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + kcp{{.group.GoPackageAlias}} "{{.packagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} - {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}}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}}"} @@ -185,7 +184,7 @@ type {{.kind.Plural | lowerFirst}}ClusterClient struct { } // Cluster scopes the client down to a particular cluster. -func (c *{{.kind.Plural | lowerFirst}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}kcp{{.group.PackageAlias}}.{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} { +func (c *{{.kind.Plural | lowerFirst}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}kcp{{.group.GoPackageAlias}}.{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}} { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -198,8 +197,8 @@ func (c *{{.kind.Plural | lowerFirst}}ClusterClient) Cluster(clusterPath logical {{ if .kind.SupportsListWatch }} // List takes label and field selectors, and returns the list of {{.kind.Plural}} that match those selectors across all clusters. -func (c *{{.kind.Plural | lowerFirst}}ClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, logicalcluster.Wildcard, {{if .kind.IsNamespaced}}metav1.NamespaceAll, {{end}}opts), &{{.group.PackageAlias}}.{{.kind.String}}List{}) +func (c *{{.kind.Plural | lowerFirst}}ClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}List, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, logicalcluster.Wildcard, {{if .kind.IsNamespaced}}metav1.NamespaceAll, {{end}}opts), &{{.group.GoPackageAlias}}.{{.kind.String}}List{}) if obj == nil { return nil, err } @@ -208,8 +207,8 @@ func (c *{{.kind.Plural | lowerFirst}}ClusterClient) List(ctx context.Context, o if label == nil { label = labels.Everything() } - list := &{{.group.PackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).ListMeta} - for _, item := range obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).Items { + list := &{{.group.GoPackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).ListMeta} + for _, item := range obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } @@ -229,7 +228,7 @@ type {{.kind.Plural | lowerFirst}}Namespacer struct { ClusterPath logicalcluster.Path } -func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.PackageAlias}}client.{{.kind.String}}Interface { +func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.GoPackageAlias}}client.{{.kind.String}}Interface { return &{{.kind.Plural | lowerFirst}}Client{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} } {{ end -}} @@ -241,38 +240,38 @@ type {{.kind.Plural | lowerFirst}}Client struct { } {{if "create" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Create(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.CreateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}CreateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) Create(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{.kind.String}}, opts metav1.CreateOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}CreateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if "update" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Update(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) Update(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if "updateStatus" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) UpdateStatus(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, "status", {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) UpdateStatus(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, "status", {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if "delete" | .kind.SupportedVerbs.Has}} func (c *{{.kind.Plural | lowerFirst}}Client) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}DeleteActionWithOptions({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, opts), &{{.group.PackageAlias}}.{{.kind.String}}{}) + _, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}DeleteActionWithOptions({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, opts), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) return err } {{end -}} @@ -281,25 +280,25 @@ func (c *{{.kind.Plural | lowerFirst}}Client) Delete(ctx context.Context, name s func (c *{{.kind.Plural | lowerFirst}}Client) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { action := kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}DeleteCollectionAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}listOpts) - _, err := c.Fake.Invokes(action, &{{.group.PackageAlias}}.{{.kind.String}}List{}) + _, err := c.Fake.Invokes(action, &{{.group.GoPackageAlias}}.{{.kind.String}}List{}) return err } {{end -}} {{if "get" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Get(ctx context.Context, name string, options metav1.GetOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}GetAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) Get(ctx context.Context, name string, options metav1.GetOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}GetAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if "list" | .kind.SupportedVerbs.Has}} // List takes label and field selectors, and returns the list of {{.kind.Plural}} that match those selectors. -func (c *{{.kind.Plural | lowerFirst}}Client) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}opts), &{{.group.PackageAlias}}.{{.kind.String}}List{}) +func (c *{{.kind.Plural | lowerFirst}}Client) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}List, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}opts), &{{.group.GoPackageAlias}}.{{.kind.String}}List{}) if obj == nil { return nil, err } @@ -308,8 +307,8 @@ func (c *{{.kind.Plural | lowerFirst}}Client) List(ctx context.Context, opts met if label == nil { label = labels.Everything() } - list := &{{.group.PackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).ListMeta} - for _, item := range obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).Items { + list := &{{.group.GoPackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).ListMeta} + for _, item := range obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } @@ -325,17 +324,17 @@ func (c *{{.kind.Plural | lowerFirst}}Client) Watch(ctx context.Context, opts me {{end -}} {{if "patch" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, pt, data, subresources...), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, pt, data, subresources...), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if and .generateApplyVerbs ("apply" | .kind.SupportedVerbs.Has) }} -func (c *{{.kind.Plural | lowerFirst}}Client) Apply(ctx context.Context, applyConfiguration *applyconfigurations{{.group.PackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (c *{{.kind.Plural | lowerFirst}}Client) Apply(ctx context.Context, applyConfiguration *applyconfigurations{{.group.GoPackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { if applyConfiguration == nil { return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") } @@ -347,16 +346,16 @@ func (c *{{.kind.Plural | lowerFirst}}Client) Apply(ctx context.Context, applyCo if name == nil { return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") } - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data), &{{.group.PackageAlias}}.{{.kind.String}}{}) + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if and .generateApplyVerbs ("applyStatus" | .kind.SupportedVerbs.Has) }} -func (c *{{.kind.Plural | lowerFirst}}Client) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurations{{.group.PackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (c *{{.kind.Plural | lowerFirst}}Client) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurations{{.group.GoPackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { if applyConfiguration == nil { return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") } @@ -368,17 +367,17 @@ func (c *{{.kind.Plural | lowerFirst}}Client) ApplyStatus(ctx context.Context, a if name == nil { return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") } - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data, "status"), &{{.group.PackageAlias}}.{{.kind.String}}{}) + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data, "status"), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{range .kind.Extensions}} {{if eq .Verb "create"}} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, {{if .InputType}}{{.InputType | lowerFirst}} *{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}{{$.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{$.kind.String}}{{end}}, opts metav1.CreateOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { +func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, {{if .InputType}}{{.InputType | lowerFirst}} *{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}{{$.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{$.kind.String}}{{end}}, opts metav1.CreateOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { obj, err := c.Fake.Invokes(kcptesting.New{{if not $.kind.IsNamespaced}}Root{{end}}CreateSubresourceAction({{$.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{$.kind.String | lowerFirst}}Name, "{{.Subresource}}", {{if $.kind.IsNamespaced}}c.Namespace, {{end}}{{if .InputType}}{{.InputType | lowerFirst}}{{else}}{{$.kind.String | lowerFirst}}{{end}}), &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}{}) if obj == nil { return nil, err @@ -440,7 +439,7 @@ func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{end -}} {{if and $.generateApplyVerbs (eq .Verb "apply") }} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, applyConfiguration {{if .InputType}}*{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}*applyconfigurations{{$.group.PackageAlias}}.{{$.kind.String}}ApplyConfiguration,{{end}}, opts metav1.ApplyOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { +func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, applyConfiguration {{if .InputType}}*{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}*applyconfigurations{{$.group.GoPackageAlias}}.{{$.kind.String}}ApplyConfiguration,{{end}}, opts metav1.ApplyOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { if applyConfiguration == nil { return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") } diff --git a/pkg/internal/clientgen/group.go b/pkg/internal/clientgen/group.go index 9421c1733..89dfa91ba 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.GoPackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) type {{.group.GroupGoName}}{{.group.Version}}ClusterInterface interface { @@ -67,14 +65,14 @@ type {{.group.GroupGoName}}{{.group.Version}}ClusterInterface interface { } type {{.group.GroupGoName}}{{.group.Version}}ClusterScoper interface { - Cluster(logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface + Cluster(logicalcluster.Path) {{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface } type {{.group.GroupGoName}}{{.group.Version}}ClusterClient struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client] + clientCache kcpclient.Cache[*{{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client] } -func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { +func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -101,8 +99,8 @@ func NewForConfig(c *rest.Config) (*{{.group.GroupGoName}}{{.group.Version}}Clus // NewForConfigAndClient creates a new {{.group.GroupGoName}}{{.group.Version}}ClusterClient 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) (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient, error) { - cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client]{ - NewForConfigAndClient: {{.group.PackageAlias}}.NewForConfigAndClient, + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*{{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client]{ + NewForConfigAndClient: {{.group.GoPackageAlias}}.NewForConfigAndClient, }) if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err diff --git a/pkg/internal/clientgen/scheme.go b/pkg/internal/clientgen/scheme.go index 6b5524e35..305e98cdd 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" @@ -51,7 +50,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" -{{range .groups}} {{.PackageAlias}} "{{$.apiPackagePath}}/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.GoPackageAlias}} "{{$.apiPackagePath}}/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} ) @@ -59,7 +58,7 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ -{{range .groups}} {{.PackageAlias}}.AddToScheme, +{{range .groups}} {{.GoPackageAlias}}.AddToScheme, {{end -}} } diff --git a/pkg/internal/clientgen/type.go b/pkg/internal/clientgen/type.go index bb5a95e33..a633c46c2 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.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} - {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) // {{.kind.Plural}}ClusterGetter has a method to return a {{.kind.String}}ClusterInterface. @@ -76,24 +74,24 @@ type {{.kind.Plural}}ClusterGetter interface { {{ if .kind.SupportsListWatch -}} // {{.kind.String}}ClusterInterface can operate on {{.kind.Plural}} across all clusters, -// or scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}}. +// or scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}}. {{ else -}} -// {{.kind.String}}ClusterInterface can scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}}. +// {{.kind.String}}ClusterInterface can scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}}. {{ end -}} type {{.kind.String}}ClusterInterface interface { - Cluster(logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} + Cluster(logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}} {{- if .kind.SupportsListWatch }} - List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) + List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}List, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {{ end -}} } type {{.kind.Plural | lowerFirst}}ClusterInterface struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] + clientCache kcpclient.Cache[*{{.group.GoPackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] } // Cluster scopes the client down to a particular cluster. -func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} { +func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}} { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -106,7 +104,7 @@ func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Cluster(clusterPath logi {{ if .kind.SupportsListWatch }} // List returns the entire collection of all {{.kind.Plural}} across all clusters. -func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { +func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}List, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).{{.kind.Plural}}({{if .kind.IsNamespaced }}metav1.NamespaceAll{{end}}).List(ctx, opts) } @@ -117,17 +115,17 @@ func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Watch(ctx context.Contex {{ end -}} {{ if .kind.IsNamespaced -}} -// {{.kind.Plural}}Namespacer can scope to objects within a namespace, returning a {{.group.PackageAlias}}client.{{.kind.String}}Interface. +// {{.kind.Plural}}Namespacer can scope to objects within a namespace, returning a {{.group.GoPackageAlias}}client.{{.kind.String}}Interface. type {{.kind.Plural}}Namespacer interface { - Namespace(string) {{.group.PackageAlias}}client.{{.kind.String}}Interface + Namespace(string) {{.group.GoPackageAlias}}client.{{.kind.String}}Interface } type {{.kind.Plural | lowerFirst}}Namespacer struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] + clientCache kcpclient.Cache[*{{.group.GoPackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] clusterPath logicalcluster.Path } -func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.PackageAlias}}client.{{.kind.String}}Interface { +func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.GoPackageAlias}}client.{{.kind.String}}Interface { return n.clientCache.ClusterOrDie(n.clusterPath).{{.kind.Plural}}(namespace) } {{ end -}} diff --git a/pkg/internal/informergen/factory.go b/pkg/internal/informergen/factory.go index 9563eeaa9..c125a378f 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}} {{.GroupGoName}}() {{.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) {{.GroupGoName}}() {{.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}} {{.GroupGoName}}() {{.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) {{.GroupGoName}}() {{.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..3a863838d 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" @@ -78,7 +78,7 @@ import ( upstreaminformers "{{.singleClusterInformerPackagePath}}" {{end -}} -{{range .groups}} {{.PackageAlias}} "{{$.apiPackagePath}}/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.GoPackageAlias}} "{{$.apiPackagePath}}/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} ) @@ -138,7 +138,7 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) { switch resource { {{range $group := .groups}} // Group={{.Group.NonEmpty}}, Version={{.Version}} -{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.PackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): +{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.GoPackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.{{$group.GroupGoName}}().{{$group.Version}}().{{$kind.Plural}}().Informer()}, nil {{end -}} {{end -}} @@ -153,7 +153,7 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionResource) ({{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer, error) { switch resource { {{range $group := .groups}} // Group={{.Group.NonEmpty}}, Version={{.Version}} -{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.PackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): +{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.GoPackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): informer := f.{{$group.GroupGoName}}().{{$group.Version}}().{{$kind.Plural}}().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil {{end -}} diff --git a/pkg/internal/informergen/groupinterface.go b/pkg/internal/informergen/groupinterface.go index 9848d4336..b2f1d156e 100644 --- a/pkg/internal/informergen/groupinterface.go +++ b/pkg/internal/informergen/groupinterface.go @@ -18,10 +18,9 @@ package informergen import ( "io" + "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" ) @@ -30,7 +29,7 @@ type GroupInterface struct { Group parser.Group // Versions are the versions of this group for which we're generating interfaces - Versions []types.Version + Versions []parser.Version // PackagePath is the package under which these informers will be exposed. // e.g. "github.com/kcp-dev/client-go/clients/informers" @@ -49,6 +48,7 @@ func (g GroupInterface) WriteContent(w io.Writer) error { m := map[string]interface{}{ "group": g.Group, + "packageName": strings.ReplaceAll(g.Group.PackageName(), "-", ""), "packagePath": g.PackagePath, "versions": g.Versions, "useUpstreamInterfaces": g.UseUpstreamInterfaces, @@ -62,10 +62,10 @@ var groupInterface = ` // Code generated by kcp code-generator. DO NOT EDIT. -package {{.group.Group.PackageName}} +package {{.packageName}} import ( -{{range .versions}} "{{$.packagePath}}/{{$.group.Group.PackageName}}/{{.PackageName}}" +{{range .versions}} "{{$.packagePath}}/{{$.group.PackageName}}/{{.PackageName}}" {{end -}} "{{.packagePath}}/internalinterfaces" diff --git a/pkg/internal/informergen/informer.go b/pkg/internal/informergen/informer.go index 91b2b35f8..8405a0744 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.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}}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.GoPackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" + upstream{{.group.GoPackageAlias}}informers "{{.singleClusterInformerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end -}} clientset "{{.clientsetPackagePath}}" @@ -123,9 +121,9 @@ import ( // {{.kind}}ClusterInformer provides access to a shared informer and lister for // {{.kind.Plural}}. type {{.kind}}ClusterInformer interface { - Cluster(logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.PackageAlias}}informers.{{end}}{{.kind}}Informer + Cluster(logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.GoPackageAlias}}informers.{{end}}{{.kind}}Informer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() {{.group.PackageAlias}}listers.{{.kind}}ClusterLister + Lister() {{.group.GoPackageAlias}}listers.{{.kind}}ClusterLister } type {{.kind.String | lowerFirst}}ClusterInformer struct { @@ -159,7 +157,7 @@ func NewFiltered{{.kind}}ClusterInformer(client clientset.ClusterInterface, resy return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}().Watch(context.TODO(), options) }, }, - &{{.group.PackageAlias}}.{{.kind.String}}{}, + &{{.group.GoPackageAlias}}.{{.kind.String}}{}, resyncPeriod, indexers, ) @@ -175,11 +173,11 @@ func (f *{{.kind.String|lowerFirst}}ClusterInformer) defaultInformer(client clie } func (f *{{.kind.String|lowerFirst}}ClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&{{.group.PackageAlias}}.{{.kind}}{}, f.defaultInformer) + return f.factory.InformerFor(&{{.group.GoPackageAlias}}.{{.kind}}{}, f.defaultInformer) } -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Lister() {{.group.PackageAlias}}listers.{{.kind.String}}ClusterLister { - return {{.group.PackageAlias}}listers.New{{.kind}}ClusterLister(f.Informer().GetIndexer()) +func (f *{{.kind.String|lowerFirst}}ClusterInformer) Lister() {{.group.GoPackageAlias}}listers.{{.kind.String}}ClusterLister { + return {{.group.GoPackageAlias}}listers.New{{.kind}}ClusterLister(f.Informer().GetIndexer()) } {{ if not .useUpstreamInterfaces }} @@ -187,11 +185,11 @@ func (f *{{.kind.String|lowerFirst}}ClusterInformer) Lister() {{.group.PackageAl // {{.kind.Plural}}. type {{.kind}}Informer interface { Informer() cache.SharedIndexInformer - Lister() {{.group.PackageAlias}}listers.{{.kind}}Lister + Lister() {{.group.GoPackageAlias}}listers.{{.kind}}Lister } {{end -}} -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.PackageAlias}}informers.{{end}}{{.kind}}Informer { +func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.GoPackageAlias}}informers.{{end}}{{.kind}}Informer { return &{{.kind.String|lowerFirst}}Informer{ informer: f.Informer().Cluster(clusterName), lister: f.Lister().Cluster(clusterName), @@ -200,14 +198,14 @@ func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logical type {{.kind.String|lowerFirst}}Informer struct { informer cache.SharedIndexInformer - lister {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.PackageAlias}}listers.{{.kind.String}}Lister + lister {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.GoPackageAlias}}listers.{{.kind.String}}Lister } func (f *{{.kind.String|lowerFirst}}Informer) Informer() cache.SharedIndexInformer { return f.informer } -func (f *{{.kind.String|lowerFirst}}Informer) Lister() {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.PackageAlias}}listers.{{.kind.String}}Lister { +func (f *{{.kind.String|lowerFirst}}Informer) Lister() {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.GoPackageAlias}}listers.{{.kind.String}}Lister { return f.lister } @@ -219,11 +217,11 @@ type {{.kind.String | lowerFirst}}ScopedInformer struct { } func (f *{{.kind.String|lowerFirst}}ScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&{{.group.PackageAlias}}.{{.kind}}{}, f.defaultInformer) + return f.factory.InformerFor(&{{.group.GoPackageAlias}}.{{.kind}}{}, f.defaultInformer) } -func (f *{{.kind.String|lowerFirst}}ScopedInformer) Lister() {{.group.PackageAlias}}listers.{{.kind.String}}Lister { - return {{.group.PackageAlias}}listers.New{{.kind}}Lister(f.Informer().GetIndexer()) +func (f *{{.kind.String|lowerFirst}}ScopedInformer) Lister() {{.group.GoPackageAlias}}listers.{{.kind.String}}Lister { + return {{.group.GoPackageAlias}}listers.New{{.kind}}Lister(f.Informer().GetIndexer()) } // New{{.kind}}Informer constructs a new informer for {{.kind.String}} type. @@ -252,7 +250,7 @@ func NewFiltered{{.kind}}Informer(client scopedclientset.Interface, resyncPeriod return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}({{if .kind.IsNamespaced}}namespace{{end -}}).Watch(context.TODO(), options) }, }, - &{{.group.PackageAlias}}.{{.kind.String}}{}, + &{{.group.GoPackageAlias}}.{{.kind.String}}{}, resyncPeriod, indexers, ) diff --git a/pkg/internal/informergen/versioninterface.go b/pkg/internal/informergen/versioninterface.go index fb20d35ac..41905a2bf 100644 --- a/pkg/internal/informergen/versioninterface.go +++ b/pkg/internal/informergen/versioninterface.go @@ -18,6 +18,7 @@ package informergen import ( "io" + "strings" "text/template" "k8s.io/code-generator/cmd/client-gen/types" @@ -51,6 +52,7 @@ func (v *VersionInterface) WriteContent(w io.Writer) error { "version": v.Version, "kinds": v.Kinds, "packagePath": v.PackagePath, + "packageName": strings.ReplaceAll(v.Version.PackageName(), "-", ""), "useUpstreamInterfaces": v.UseUpstreamInterfaces, } return templ.Execute(w, m) @@ -62,7 +64,7 @@ var versionInterfaceTemplate = ` // Code generated by kcp code-generator. DO NOT EDIT. -package {{.version.PackageName}} +package {{.packageName}} import ( "{{.packagePath}}/internalinterfaces" 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..662c53e92 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.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{if .useUpstreamInterfaces -}} - {{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end -}} ) @@ -69,12 +67,12 @@ import ( type {{.kind.String}}ClusterLister interface { // List lists all {{.kind.Plural}} in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) + List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) // Cluster returns a lister that can list and get {{.kind.Plural}} in one workspace. {{if not .useUpstreamInterfaces -}} Cluster(clusterName logicalcluster.Name) {{.kind.String}}Lister {{else -}} - Cluster(clusterName logicalcluster.Name){{.group.PackageAlias}}listers.{{.kind.String}}Lister + Cluster(clusterName logicalcluster.Name){{.group.GoPackageAlias}}listers.{{.kind.String}}Lister {{end -}} {{.kind.String}}ClusterListerExpansion } @@ -96,9 +94,9 @@ func New{{.kind.String}}ClusterLister(indexer cache.Indexer) *{{.kind.String | l } // List lists all {{.kind.Plural}} in the indexer across all workspaces. -func (s *{{.kind.String | lowerFirst}}ClusterLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}ClusterLister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, m.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } @@ -107,7 +105,7 @@ func (s *{{.kind.String | lowerFirst}}ClusterLister) List(selector labels.Select {{if not .useUpstreamInterfaces -}} func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logicalcluster.Name) {{.kind.String}}Lister { {{else -}} -func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logicalcluster.Name){{.group.PackageAlias}}listers.{{.kind.String}}Lister { +func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logicalcluster.Name){{.group.GoPackageAlias}}listers.{{.kind.String}}Lister { {{end -}} return &{{.kind.String | lowerFirst}}Lister{indexer: s.indexer, clusterName: clusterName} } @@ -122,11 +120,11 @@ func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logical type {{.kind.String}}Lister interface { // List lists all {{.kind.Plural}} in the workspace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) + List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) {{ if not .kind.IsNamespaced -}} // Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. // Objects returned here must be treated as read-only. - Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) + Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) {{else -}} // {{.kind.Plural}} returns a lister that can list and get {{.kind.Plural}} in one workspace and namespace. {{.kind.Plural}}(namespace string) {{.kind.String}}NamespaceLister @@ -138,7 +136,7 @@ type {{.kind.String}}Lister interface { {{if not .useUpstreamInterfaces -}} // {{.kind.String | lowerFirst}}Lister can list all {{.kind.Plural}} inside a workspace{{ if .kind.IsNamespaced }} or scope down to a {{.kind.String}}Lister for one namespace{{end}}. {{else -}} -// {{.kind.String | lowerFirst}}Lister implements the {{.group.PackageAlias}}listers.{{.kind.String}}Lister interface. +// {{.kind.String | lowerFirst}}Lister implements the {{.group.GoPackageAlias}}listers.{{.kind.String}}Lister interface. {{end -}} type {{.kind.String | lowerFirst}}Lister struct { indexer cache.Indexer @@ -146,32 +144,32 @@ type {{.kind.String | lowerFirst}}Lister struct { } // List lists all {{.kind.Plural}} in the indexer for a workspace. -func (s *{{.kind.String | lowerFirst}}Lister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}Lister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } {{ if not .kind.IsNamespaced -}} // Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. -func (s *{{.kind.String | lowerFirst}}Lister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (s *{{.kind.String | lowerFirst}}Lister) Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, 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({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) + return nil, errors.NewNotFound({{.group.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil } {{ else -}} // {{.kind.Plural}} returns an object that can list and get {{.kind.Plural}} in one namespace. {{if not .useUpstreamInterfaces -}} func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) {{.kind.String}}NamespaceLister { {{else -}} -func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) {{.group.PackageAlias}}listers.{{.kind.String}}NamespaceLister { +func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) {{.group.GoPackageAlias}}listers.{{.kind.String}}NamespaceLister { {{end -}} return &{{.kind.String | lowerFirst}}NamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} } @@ -182,10 +180,10 @@ func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) type {{.kind.String}}NamespaceLister interface { // List lists all {{.kind.Plural}} in the workspace and namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) + List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) // Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) + Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) {{.kind.String}}NamespaceListerExpansion } {{end -}} @@ -195,7 +193,7 @@ type {{.kind.String}}NamespaceLister interface { // All objects returned here must be treated as read-only. {{ end -}} {{ if .useUpstreamInterfaces -}} -// {{.kind.String | lowerFirst}}NamespaceLister implements the {{.group.PackageAlias}}listers.{{.kind.String}}NamespaceLister interface. +// {{.kind.String | lowerFirst}}NamespaceLister implements the {{.group.GoPackageAlias}}listers.{{.kind.String}}NamespaceLister interface. {{ end -}} type {{.kind.String | lowerFirst}}NamespaceLister struct { indexer cache.Indexer @@ -204,24 +202,24 @@ type {{.kind.String | lowerFirst}}NamespaceLister struct { } // List lists all {{.kind.Plural}} in the indexer for a given workspace and namespace. -func (s *{{.kind.String | lowerFirst}}NamespaceLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}NamespaceLister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } // Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. -func (s *{{.kind.String | lowerFirst}}NamespaceLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (s *{{.kind.String | lowerFirst}}NamespaceLister) Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, 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({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) + return nil, errors.NewNotFound({{.group.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil } {{ end -}} @@ -243,25 +241,25 @@ type {{.kind.String | lowerFirst}}ScopedLister struct { } // List lists all {{.kind.Plural}} in the indexer for a workspace. -func (s *{{.kind.String | lowerFirst}}ScopedLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}ScopedLister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } {{ if not .kind.IsNamespaced -}} // Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. -func (s *{{.kind.String | lowerFirst}}ScopedLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (s *{{.kind.String | lowerFirst}}ScopedLister) Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { key := name obj, exists, err := s.indexer.GetByKey(key) if err != nil { return nil, err } if !exists { - return nil, errors.NewNotFound({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) + return nil, errors.NewNotFound({{.group.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil } {{ else -}} // {{.kind.Plural}} returns an object that can list and get {{.kind.Plural}} in one namespace. @@ -276,24 +274,24 @@ type {{.kind.String | lowerFirst}}ScopedNamespaceLister struct { } // List lists all {{.kind.Plural}} in the indexer for a given workspace and namespace. -func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } // Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. -func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { key := s.namespace + "/" + name obj, exists, err := s.indexer.GetByKey(key) if err != nil { return nil, err } if !exists { - return nil, errors.NewNotFound({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) + return nil, errors.NewNotFound({{.group.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil } {{ end -}} {{end -}} diff --git a/pkg/parser/types.go b/pkg/parser/types.go index 00fbd86e5..845e78fcf 100644 --- a/pkg/parser/types.go +++ b/pkg/parser/types.go @@ -17,6 +17,11 @@ limitations under the License. package parser import ( + "strings" + + "golang.org/x/text/cases" + "golang.org/x/text/language" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/code-generator/cmd/client-gen/types" @@ -34,7 +39,41 @@ type Kind struct { type Group struct { types.Group - GoName string + GoName string `marker:",+groupGoName"` + Version Version + PackageAlias string + LowerCaseGroupGoName string +} + +func (g Group) GoPackageAlias() string { + if g.PackageAlias == "" { + panic("PackageAlias is empty. Programmer error.") + } + return strings.ReplaceAll(g.PackageAlias, "-", "") +} + +func (g Group) GroupGoName() string { + if g.GoName == "" { + panic("GroupGoName is empty. Programmer error.") + } + caser := cases.Title(language.English) + parts := strings.Split(g.GoName, "-") + for i, part := range parts { + parts[i] = caser.String(part) + } + return strings.Join(parts, "") +} + +func (g Group) GroupGoNameLower() string { + if g.LowerCaseGroupGoName == "" { + panic("LowerCaseGroupGoName is empty. Programmer error.") + } + result := strings.ToLower(g.LowerCaseGroupGoName) + return strings.ReplaceAll(result, "-", "") +} + +func (g Group) PackageName() string { + return strings.ToLower(strings.ReplaceAll(g.Group.PackageName(), "-", "")) } func (k *Kind) Plural() string { @@ -53,6 +92,24 @@ 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) +} + // 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