From 819f390c26cc48dde21a5272cea27939f551548a Mon Sep 17 00:00:00 2001 From: Mangirdas Judeikis Date: Sun, 8 Dec 2024 16:06:50 +0200 Subject: [PATCH] Add example api with - Signed-off-by: Mangirdas Judeikis On-behalf-of: SAP mangirdas.judeikis@sap.com --- examples/pkg/apis/example-dashed/register.go | 23 ++ examples/pkg/apis/example-dashed/v1/doc.go | 19 ++ .../pkg/apis/example-dashed/v1/register.go | 55 ++++ examples/pkg/apis/example-dashed/v1/types.go | 70 ++++++ .../v1/zz_generated.deepcopy.go | 144 +++++++++++ .../clients/clientset/versioned/clientset.go | 12 + .../clientset/versioned/fake/clientset.go | 13 + .../clientset/versioned/scheme/register.go | 2 + .../example-dashed/v1/clustertesttype.go | 72 ++++++ .../example-dashed/v1/exampledashed_client.go | 95 +++++++ .../example-dashed/v1/fake/clustertesttype.go | 202 +++++++++++++++ .../v1/fake/exampledashed_client.go | 73 ++++++ .../typed/example-dashed/v1/fake/testtype.go | 238 ++++++++++++++++++ .../typed/example-dashed/v1/testtype.go | 86 +++++++ .../example-dashed/interface.go | 68 +++++ .../example-dashed/v1/clustertesttype.go | 179 +++++++++++++ .../example-dashed/v1/interface.go | 81 ++++++ .../example-dashed/v1/testtype.go | 182 ++++++++++++++ .../informers/externalversions/factory.go | 11 + .../informers/externalversions/generic.go | 13 + .../example-dashed/v1/clustertesttype.go | 143 +++++++++++ .../v1/clustertesttype_expansion.go | 28 +++ .../listers/example-dashed/v1/testtype.go | 196 +++++++++++++++ .../example-dashed/v1/testtype_expansion.go | 31 +++ .../clients/clientset/versioned/clientset.go | 12 + .../clientset/versioned/fake/clientset.go | 13 + .../clientset/versioned/scheme/register.go | 2 + .../example-dashed/v1/clustertesttype.go | 72 ++++++ .../example-dashed/v1/exampledashed_client.go | 95 +++++++ .../example-dashed/v1/fake/clustertesttype.go | 202 +++++++++++++++ .../v1/fake/exampledashed_client.go | 73 ++++++ .../typed/example-dashed/v1/fake/testtype.go | 238 ++++++++++++++++++ .../typed/example-dashed/v1/testtype.go | 86 +++++++ .../example-dashed/interface.go | 47 ++++ .../example-dashed/v1/clustertesttype.go | 124 +++++++++ .../example-dashed/v1/interface.go | 53 ++++ .../example-dashed/v1/testtype.go | 124 +++++++++ .../informers/externalversions/factory.go | 6 + .../informers/externalversions/generic.go | 6 + .../example-dashed/v1/clustertesttype.go | 98 ++++++++ .../v1/clustertesttype_expansion.go | 25 ++ .../listers/example-dashed/v1/testtype.go | 119 +++++++++ .../example-dashed/v1/testtype_expansion.go | 25 ++ pkg/generators/clientgen/clientgen.go | 8 +- pkg/generators/informergen/informergen.go | 8 +- pkg/generators/listergen/listergen.go | 8 +- pkg/internal/clientgen/clientset.go | 3 +- pkg/internal/informergen/factory.go | 10 +- pkg/internal/informergen/groupinterface.go | 4 +- pkg/internal/informergen/versioninterface.go | 4 +- pkg/parser/types.go | 21 +- 51 files changed, 3501 insertions(+), 21 deletions(-) create mode 100644 examples/pkg/apis/example-dashed/register.go create mode 100644 examples/pkg/apis/example-dashed/v1/doc.go create mode 100644 examples/pkg/apis/example-dashed/v1/register.go create mode 100644 examples/pkg/apis/example-dashed/v1/types.go create mode 100644 examples/pkg/apis/example-dashed/v1/zz_generated.deepcopy.go create mode 100644 examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/clustertesttype.go create mode 100644 examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/exampledashed_client.go create mode 100644 examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/fake/clustertesttype.go create mode 100644 examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/fake/exampledashed_client.go create mode 100644 examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/fake/testtype.go create mode 100644 examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/testtype.go create mode 100644 examples/pkg/kcp/clients/informers/externalversions/example-dashed/interface.go create mode 100644 examples/pkg/kcp/clients/informers/externalversions/example-dashed/v1/clustertesttype.go create mode 100644 examples/pkg/kcp/clients/informers/externalversions/example-dashed/v1/interface.go create mode 100644 examples/pkg/kcp/clients/informers/externalversions/example-dashed/v1/testtype.go create mode 100644 examples/pkg/kcp/clients/listers/example-dashed/v1/clustertesttype.go create mode 100644 examples/pkg/kcp/clients/listers/example-dashed/v1/clustertesttype_expansion.go create mode 100644 examples/pkg/kcp/clients/listers/example-dashed/v1/testtype.go create mode 100644 examples/pkg/kcp/clients/listers/example-dashed/v1/testtype_expansion.go create mode 100644 examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/clustertesttype.go create mode 100644 examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/exampledashed_client.go create mode 100644 examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/fake/clustertesttype.go create mode 100644 examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/fake/exampledashed_client.go create mode 100644 examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/fake/testtype.go create mode 100644 examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/testtype.go create mode 100644 examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/interface.go create mode 100644 examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/v1/clustertesttype.go create mode 100644 examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/v1/interface.go create mode 100644 examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/v1/testtype.go create mode 100644 examples/pkg/kcpexisting/clients/listers/example-dashed/v1/clustertesttype.go create mode 100644 examples/pkg/kcpexisting/clients/listers/example-dashed/v1/clustertesttype_expansion.go create mode 100644 examples/pkg/kcpexisting/clients/listers/example-dashed/v1/testtype.go create mode 100644 examples/pkg/kcpexisting/clients/listers/example-dashed/v1/testtype_expansion.go diff --git a/examples/pkg/apis/example-dashed/register.go b/examples/pkg/apis/example-dashed/register.go new file mode 100644 index 000000000..588bd50a3 --- /dev/null +++ b/examples/pkg/apis/example-dashed/register.go @@ -0,0 +1,23 @@ +/* +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 + // +groupGoName=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..af87f6ecc --- /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=example-dashed.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/kcp/clients/clientset/versioned/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/clientset.go index aa4ccb8f9..e0a1e4a87 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/clientset.go @@ -33,6 +33,7 @@ import ( "k8s.io/client-go/util/flowcontrol" client "acme.corp/pkg/generated/clientset/versioned" + exampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1" examplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" examplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1" examplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" @@ -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..546a28cb2 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go @@ -31,6 +31,7 @@ import ( client "acme.corp/pkg/generated/clientset/versioned" clientscheme "acme.corp/pkg/generated/clientset/versioned/scheme" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/v1" examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" @@ -39,6 +40,8 @@ import ( 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" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1" + fakeexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/fake" kcpexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1" fakeexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1/fake" kcpexamplev1alpha1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1alpha1" @@ -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..ebaaa02f5 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + exampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" examplev1 "acme.corp/pkg/apis/example/v1" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -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/example-dashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..c44b7ac44 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/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/example-dashed/v1/exampledashed_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/exampledashed_client.go new file mode 100644 index 000000000..abd31bf4f --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/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/example-dashed/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/example-dashed/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/fake/clustertesttype.go new file mode 100644 index 000000000..0c236458f --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/example-dashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/v1" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "example-dashed.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/example-dashed/v1/fake/exampledashed_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/fake/exampledashed_client.go new file mode 100644 index 000000000..ac4b3dafa --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/fake/testtype.go new file mode 100644 index 000000000..5c6005c99 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/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" + + exampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" + examplev1 "acme.corp/pkg/apis/example/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/example-dashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1" +) + +var testTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "example-dashed.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/example-dashed/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/v1/testtype.go new file mode 100644 index 000000000..0835c7995 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/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/informers/externalversions/example-dashed/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example-dashed/interface.go new file mode 100644 index 000000000..2d606209f --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/example-dashed/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/example-dashed/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/example-dashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..78cee7bc0 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/example-dashed/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/example-dashed/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/example-dashed/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/example-dashed/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example-dashed/v1/interface.go new file mode 100644 index 000000000..3034bb594 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/example-dashed/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/example-dashed/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example-dashed/v1/testtype.go new file mode 100644 index 000000000..3135a0857 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/example-dashed/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/example-dashed/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/example-dashed/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..a0ec6f915 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcp/clients/informers/externalversions/factory.go @@ -37,6 +37,7 @@ import ( scopedclientset "acme.corp/pkg/generated/clientset/versioned" clientset "acme.corp/pkg/kcp/clients/clientset/versioned" exampleinformers "acme.corp/pkg/kcp/clients/informers/externalversions/example" + exampledashedinformers "acme.corp/pkg/kcp/clients/informers/externalversions/example-dashed" example3informers "acme.corp/pkg/kcp/clients/informers/externalversions/example3" existinginterfacesinformers "acme.corp/pkg/kcp/clients/informers/externalversions/existinginterfaces" "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" @@ -273,6 +274,7 @@ type SharedInformerFactory interface { InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer Example() exampleinformers.ClusterInterface + Exampledashed() exampledashedinformers.ClusterInterface Example3() example3informers.ClusterInterface Existinginterfaces() existinginterfacesinformers.ClusterInterface Secondexample() secondexampleinformers.ClusterInterface @@ -282,6 +284,10 @@ func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { return exampleinformers.New(f, f.tweakListOptions) } +func (f *sharedInformerFactory) Exampledashed() exampledashedinformers.ClusterInterface { + return example - dashedinformers.New(f, f.tweakListOptions) +} + func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { return example3informers.New(f, f.tweakListOptions) } @@ -439,6 +445,7 @@ type SharedScopedInformerFactory interface { WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool Example() exampleinformers.Interface + Exampledashed() exampledashedinformers.Interface Example3() example3informers.Interface Existinginterfaces() existinginterfacesinformers.Interface Secondexample() secondexampleinformers.Interface @@ -448,6 +455,10 @@ func (f *sharedScopedInformerFactory) Example() exampleinformers.Interface { return exampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) } +func (f *sharedScopedInformerFactory) Exampledashed() exampledashedinformers.Interface { + return example - dashedinformers.NewScoped(f, f.namespace, f.tweakListOptions) +} + func (f *sharedScopedInformerFactory) Example3() example3informers.Interface { return example3informers.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..5366369f0 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcp/clients/informers/externalversions/generic.go @@ -30,6 +30,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/tools/cache" + exampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" examplev1 "acme.corp/pkg/apis/example/v1" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -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=example-dashed.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=example-dashed.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/listers/example-dashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..52d1e5f5e --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example-dashed/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/example-dashed/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/example-dashed/v1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/example-dashed/v1/clustertesttype_expansion.go new file mode 100644 index 000000000..a85e878f1 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example-dashed/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/example-dashed/v1/testtype.go b/examples/pkg/kcp/clients/listers/example-dashed/v1/testtype.go new file mode 100644 index 000000000..12ec7de8a --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example-dashed/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/example-dashed/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/example-dashed/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/example-dashed/v1/testtype_expansion.go new file mode 100644 index 000000000..3f50c325f --- /dev/null +++ b/examples/pkg/kcp/clients/listers/example-dashed/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..179063d48 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go @@ -33,6 +33,7 @@ import ( "k8s.io/client-go/util/flowcontrol" client "acme.corp/pkg/generated/clientset/versioned" + exampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1" examplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" examplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1" examplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" @@ -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..776bee986 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go @@ -31,6 +31,7 @@ import ( client "acme.corp/pkg/generated/clientset/versioned" clientscheme "acme.corp/pkg/generated/clientset/versioned/scheme" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/v1" examplev1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1" examplev1alpha1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1alpha1" examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" @@ -39,6 +40,8 @@ import ( 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" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1" + fakeexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/fake" kcpexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1" fakeexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1/fake" kcpexamplev1alpha1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1alpha1" @@ -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..ebaaa02f5 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + exampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" examplev1 "acme.corp/pkg/apis/example/v1" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -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/example-dashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..c44b7ac44 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/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/example-dashed/v1/exampledashed_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/exampledashed_client.go new file mode 100644 index 000000000..abd31bf4f --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/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/example-dashed/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/example-dashed/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/fake/clustertesttype.go new file mode 100644 index 000000000..0c236458f --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/example-dashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/v1" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "example-dashed.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/example-dashed/v1/fake/exampledashed_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/fake/exampledashed_client.go new file mode 100644 index 000000000..5e4267925 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/fake/testtype.go new file mode 100644 index 000000000..678b8730f --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/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" + + exampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" + examplev1 "acme.corp/pkg/apis/example/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/example-dashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1" +) + +var testTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "example-dashed.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/example-dashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/v1/testtype.go new file mode 100644 index 000000000..0835c7995 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example-dashed/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/example-dashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/example-dashed/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/informers/externalversions/example-dashed/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/interface.go new file mode 100644 index 000000000..6d75795fd --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/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/example-dashed/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/example-dashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..ab7692a5b --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/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/example-dashed/v1" + upstreamexampledashedv1informers "acme.corp/pkg/generated/informers/externalversions/example-dashed/v1" + upstreamexampledashedv1listers "acme.corp/pkg/generated/listers/example-dashed/v1" + clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcpexisting/clients/listers/example-dashed/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/example-dashed/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/v1/interface.go new file mode 100644 index 000000000..ebae731bf --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/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/example-dashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/v1/testtype.go new file mode 100644 index 000000000..77828eb3d --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example-dashed/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/example-dashed/v1" + upstreamexampledashedv1informers "acme.corp/pkg/generated/informers/externalversions/example-dashed/v1" + upstreamexampledashedv1listers "acme.corp/pkg/generated/listers/example-dashed/v1" + clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcpexisting/clients/listers/example-dashed/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..248d05954 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go @@ -37,6 +37,7 @@ import ( upstreaminformers "acme.corp/pkg/generated/informers/externalversions" clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" exampleinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example" + exampledashedinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example-dashed" example3informers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example3" existinginterfacesinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces" "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" @@ -272,6 +273,7 @@ type SharedInformerFactory interface { InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer Example() exampleinformers.ClusterInterface + Exampledashed() exampledashedinformers.ClusterInterface Example3() example3informers.ClusterInterface Existinginterfaces() existinginterfacesinformers.ClusterInterface Secondexample() secondexampleinformers.ClusterInterface @@ -281,6 +283,10 @@ func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { return exampleinformers.New(f, f.tweakListOptions) } +func (f *sharedInformerFactory) Exampledashed() exampledashedinformers.ClusterInterface { + return example - dashedinformers.New(f, f.tweakListOptions) +} + func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { return example3informers.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..a9dc0913a 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go @@ -30,6 +30,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/tools/cache" + exampledashedv1 "acme.corp/pkg/apis/example-dashed/v1" examplev1 "acme.corp/pkg/apis/example/v1" examplev1alpha1 "acme.corp/pkg/apis/example/v1alpha1" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -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=example-dashed.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/listers/example-dashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/example-dashed/v1/clustertesttype.go new file mode 100644 index 000000000..3ed288ef5 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/example-dashed/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/example-dashed/v1" + exampledashedv1listers "acme.corp/pkg/generated/listers/example-dashed/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/example-dashed/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/example-dashed/v1/clustertesttype_expansion.go new file mode 100644 index 000000000..08fb95b1c --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/example-dashed/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/example-dashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/example-dashed/v1/testtype.go new file mode 100644 index 000000000..942714e6f --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/example-dashed/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/example-dashed/v1" + exampledashedv1listers "acme.corp/pkg/generated/listers/example-dashed/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/example-dashed/v1/testtype_expansion.go b/examples/pkg/kcpexisting/clients/listers/example-dashed/v1/testtype_expansion.go new file mode 100644 index 000000000..835da85d6 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/example-dashed/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/pkg/generators/clientgen/clientgen.go b/pkg/generators/clientgen/clientgen.go index d6d10a229..1cfc21a2e 100644 --- a/pkg/generators/clientgen/clientgen.go +++ b/pkg/generators/clientgen/clientgen.go @@ -154,7 +154,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { for group, versions := range groupVersionKinds { for version, kinds := range versions { - groupDir := filepath.Join(clientsetDir, "typed", group.PackageName(), version.PackageName()) + groupDir := filepath.Join(clientsetDir, "typed", group.PackagePath(), version.PackageName()) outputFile := filepath.Join(groupDir, group.PackageName()+"_client.go") logger := logger.WithValues( "group", group.String(), @@ -244,8 +244,8 @@ func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types. return types.GroupVersionInfo{ Group: group.Group, Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, - LowerCaseGroupGoName: namer.IL(group.GoName), + PackageAlias: strings.ReplaceAll(strings.ToLower(group.GoName+version.Version.NonEmpty()), "-", ""), + GroupGoName: strings.ReplaceAll(group.GoName, "-", ""), + LowerCaseGroupGoName: strings.ReplaceAll(namer.IL(group.GoName), "-", ""), } } diff --git a/pkg/generators/informergen/informergen.go b/pkg/generators/informergen/informergen.go index 157585c87..03a43bf0a 100644 --- a/pkg/generators/informergen/informergen.go +++ b/pkg/generators/informergen/informergen.go @@ -178,7 +178,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { } for group, versions := range groupVersionKinds { - groupDir := filepath.Join(informersDir, group.PackageName()) + groupDir := filepath.Join(informersDir, group.PackagePath()) outputFile := filepath.Join(groupDir, "interface.go") logger := logger.WithValues( "group", group.String(), @@ -264,8 +264,8 @@ func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types. return types.GroupVersionInfo{ Group: group.Group, Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, - LowerCaseGroupGoName: namer.IL(group.GoName), + PackageAlias: strings.ReplaceAll(strings.ToLower(group.GoName+version.Version.NonEmpty()), "-", ""), + GroupGoName: strings.ReplaceAll(group.GoName, "-", ""), + LowerCaseGroupGoName: strings.ReplaceAll(namer.IL(group.GoName), "-", ""), } } diff --git a/pkg/generators/listergen/listergen.go b/pkg/generators/listergen/listergen.go index 0aa7ebe48..cd529bd9f 100644 --- a/pkg/generators/listergen/listergen.go +++ b/pkg/generators/listergen/listergen.go @@ -86,7 +86,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { for version, kinds := range versions { groupInfo := toGroupVersionInfo(group, version) for _, kind := range kinds { - listerDir := filepath.Join("listers", group.PackageName(), version.PackageName()) + listerDir := filepath.Join("listers", group.PackagePath(), version.PackageName()) outputFile := filepath.Join(listerDir, strings.ToLower(kind.String())+".go") logger := klog.Background().WithValues( "group", group.String(), @@ -130,8 +130,8 @@ func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types. return types.GroupVersionInfo{ Group: group.Group, Version: types.Version(namer.IC(version.Version.String())), - PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, - LowerCaseGroupGoName: namer.IL(group.GoName), + PackageAlias: strings.ReplaceAll(strings.ToLower(group.GoName+version.Version.NonEmpty()), "-", ""), + GroupGoName: strings.ReplaceAll(group.GoName, "-", ""), + LowerCaseGroupGoName: strings.ReplaceAll(namer.IL(group.GoName), "-", ""), } } diff --git a/pkg/internal/clientgen/clientset.go b/pkg/internal/clientgen/clientset.go index 943a15fbb..59134b7d7 100644 --- a/pkg/internal/clientgen/clientset.go +++ b/pkg/internal/clientgen/clientset.go @@ -38,6 +38,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 +52,7 @@ var clientset = ` // Code generated by kcp code-generator. DO NOT EDIT. -package {{.name}} +package {{.packageName}} import ( "fmt" diff --git a/pkg/internal/informergen/factory.go b/pkg/internal/informergen/factory.go index 9563eeaa9..3465431fb 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}}/{{.Group.PackageName}}" {{end -}} "{{.packagePath}}/internalinterfaces" @@ -329,12 +329,12 @@ 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}} {{.GoNameAlias}}() {{.PackageName}}informers.ClusterInterface {{end -}} } {{range .groups}} -func (f *sharedInformerFactory) {{.GoName}}() {{.Group.PackageName}}informers.ClusterInterface { +func (f *sharedInformerFactory) {{.GoNameAlias}}() {{.PackageName}}informers.ClusterInterface { return {{.Group.PackageName}}informers.New(f, f.tweakListOptions) } {{end}} @@ -485,13 +485,13 @@ 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}} {{.GoNameAlias}}() {{.PackageName}}informers.Interface {{end -}} } {{range .groups}} -func (f *sharedScopedInformerFactory) {{.GoName}}() {{.Group.PackageName}}informers.Interface { +func (f *sharedScopedInformerFactory) {{.GoNameAlias}}() {{.PackageName}}informers.Interface { return {{.Group.PackageName}}informers.NewScoped(f, f.namespace, f.tweakListOptions) } {{end}} diff --git a/pkg/internal/informergen/groupinterface.go b/pkg/internal/informergen/groupinterface.go index 9848d4336..110a93fd9 100644 --- a/pkg/internal/informergen/groupinterface.go +++ b/pkg/internal/informergen/groupinterface.go @@ -18,6 +18,7 @@ package informergen import ( "io" + "strings" "text/template" "k8s.io/code-generator/cmd/client-gen/types" @@ -49,6 +50,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,7 +64,7 @@ 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}}" 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/parser/types.go b/pkg/parser/types.go index 00fbd86e5..e0f9bb619 100644 --- a/pkg/parser/types.go +++ b/pkg/parser/types.go @@ -17,6 +17,8 @@ limitations under the License. package parser import ( + "strings" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/code-generator/cmd/client-gen/types" @@ -34,7 +36,24 @@ type Kind struct { type Group struct { types.Group - GoName string + GoName string `marker:",+groupGoName"` + PackageAlias string +} + +func (g *Group) GoPackageAlias() string { + return strings.ToLower(strings.ReplaceAll(g.GoName, "-", "")) +} + +func (g Group) GoNameAlias() string { + return strings.ReplaceAll(g.GoName, "-", "") +} + +func (g Group) PackagePath() string { + return strings.ToLower(g.Group.PackageName()) +} + +func (g Group) PackageName() string { + return strings.ToLower(strings.ReplaceAll(g.Group.PackageName(), "-", "")) } func (k *Kind) Plural() string {