From 4969f434788a436203cc6b7a5bd4b8255dd6a9bb Mon Sep 17 00:00:00 2001 From: Mangirdas Judeikis Date: Mon, 2 Sep 2024 16:15:35 +0300 Subject: [PATCH] bump to 1.31 --- examples/pkg/apis/example/v1beta1/types.go | 1 - .../pkg/generated/clientset/versioned/doc.go | 20 ------- .../example/v1beta1/fake/fake_testtype.go | 32 ++++++++++++ .../typed/example/v1beta1/testtype.go | 10 ++-- .../example/v1beta1/interface.go | 7 +++ .../informers/externalversions/generic.go | 2 + .../example/v1beta1/expansion_generated.go | 8 +++ .../typed/example/v1beta1/fake/testtype.go | 52 +++++++++++++++++++ .../typed/example/v1beta1/testtype.go | 21 +++++++- .../example/v1beta1/interface.go | 14 +++++ .../informers/externalversions/generic.go | 5 ++ .../typed/example/v1beta1/fake/testtype.go | 52 +++++++++++++++++++ .../typed/example/v1beta1/testtype.go | 21 +++++++- .../example/v1beta1/interface.go | 7 +++ .../informers/externalversions/generic.go | 2 + go.mod | 4 +- go.sum | 8 +-- 17 files changed, 234 insertions(+), 32 deletions(-) delete mode 100644 examples/pkg/generated/clientset/versioned/doc.go diff --git a/examples/pkg/apis/example/v1beta1/types.go b/examples/pkg/apis/example/v1beta1/types.go index e153e6401..8445bdd08 100644 --- a/examples/pkg/apis/example/v1beta1/types.go +++ b/examples/pkg/apis/example/v1beta1/types.go @@ -19,7 +19,6 @@ package v1beta1 import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // +genclient -// +genclient:skipVerbs=list,watch // 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 { diff --git a/examples/pkg/generated/clientset/versioned/doc.go b/examples/pkg/generated/clientset/versioned/doc.go deleted file mode 100644 index af41e7fdc..000000000 --- a/examples/pkg/generated/clientset/versioned/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright The KCP Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen-v0.26.3. DO NOT EDIT. - -// This package has the automatically generated clientset. -package versioned diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_testtype.go index 3d6996ac6..11c9f12bb 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/fake/fake_testtype.go @@ -22,7 +22,9 @@ import ( "context" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" testing "k8s.io/client-go/testing" v1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -50,6 +52,36 @@ func (c *FakeTestTypes) Get(ctx context.Context, name string, options v1.GetOpti return obj.(*v1beta1.TestType), err } +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *FakeTestTypes) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.TestTypeList, err error) { + emptyResult := &v1beta1.TestTypeList{} + obj, err := c.Fake. + Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.TestTypeList{ListMeta: obj.(*v1beta1.TestTypeList).ListMeta} + for _, item := range obj.(*v1beta1.TestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested testTypes. +func (c *FakeTestTypes) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) + +} + // Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. func (c *FakeTestTypes) Create(ctx context.Context, testType *v1beta1.TestType, opts v1.CreateOptions) (result *v1beta1.TestType, err error) { emptyResult := &v1beta1.TestType{} diff --git a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go index 4abb14acf..e87e5ae96 100644 --- a/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go +++ b/examples/pkg/generated/clientset/versioned/typed/example/v1beta1/testtype.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" gentype "k8s.io/client-go/gentype" v1beta1 "acme.corp/pkg/apis/example/v1beta1" @@ -42,23 +43,26 @@ type TestTypeInterface interface { Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.TestType, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.TestTypeList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.TestType, err error) TestTypeExpansion } // testTypes implements TestTypeInterface type testTypes struct { - *gentype.Client[*v1beta1.TestType] + *gentype.ClientWithList[*v1beta1.TestType, *v1beta1.TestTypeList] } // newTestTypes returns a TestTypes func newTestTypes(c *ExampleV1beta1Client, namespace string) *testTypes { return &testTypes{ - gentype.NewClient[*v1beta1.TestType]( + gentype.NewClientWithList[*v1beta1.TestType, *v1beta1.TestTypeList]( "testtypes", c.RESTClient(), scheme.ParameterCodec, namespace, - func() *v1beta1.TestType { return &v1beta1.TestType{} }), + func() *v1beta1.TestType { return &v1beta1.TestType{} }, + func() *v1beta1.TestTypeList { return &v1beta1.TestTypeList{} }), } } diff --git a/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go b/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go index 764abb273..4620985b5 100644 --- a/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go +++ b/examples/pkg/generated/informers/externalversions/example/v1beta1/interface.go @@ -26,6 +26,8 @@ import ( type Interface interface { // ClusterTestTypes returns a ClusterTestTypeInformer. ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer } type version struct { @@ -43,3 +45,8 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList func (v *version) ClusterTestTypes() ClusterTestTypeInformer { return &clusterTestTypeInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } + +// TestTypes returns a TestTypeInformer. +func (v *version) TestTypes() TestTypeInformer { + return &testTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/generated/informers/externalversions/generic.go b/examples/pkg/generated/informers/externalversions/generic.go index 1031500f3..9337b236d 100644 --- a/examples/pkg/generated/informers/externalversions/generic.go +++ b/examples/pkg/generated/informers/externalversions/generic.go @@ -74,6 +74,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // Group=example, Version=v1beta1 case v1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().ClusterTestTypes().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("testtypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().TestTypes().Informer()}, nil // Group=example, Version=v2 case v2.SchemeGroupVersion.WithResource("clustertesttypes"): diff --git a/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go b/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go index 080a41bc5..37d6e59e6 100644 --- a/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go +++ b/examples/pkg/generated/listers/example/v1beta1/expansion_generated.go @@ -21,3 +21,11 @@ package v1beta1 // ClusterTestTypeListerExpansion allows custom methods to be added to // ClusterTestTypeLister. type ClusterTestTypeListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go index 577bc4d7b..a23f81fcb 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go @@ -30,8 +30,11 @@ import ( 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" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" @@ -55,6 +58,31 @@ func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexa 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) (*examplev1beta1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev1beta1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &examplev1beta1.TestTypeList{ListMeta: obj.(*examplev1beta1.TestTypeList).ListMeta} + for _, item := range obj.(*examplev1beta1.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 @@ -114,6 +142,30 @@ func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.G return obj.(*examplev1beta1.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) (*examplev1beta1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev1beta1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &examplev1beta1.TestTypeList{ListMeta: obj.(*examplev1beta1.TestTypeList).ListMeta} + for _, item := range obj.(*examplev1beta1.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) (*examplev1beta1.TestType, error) { obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev1beta1.TestType{}) if obj == nil { diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go index cfae770e1..5c84ea007 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1/testtype.go @@ -22,9 +22,15 @@ limitations under the License. package v1beta1 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" + + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) @@ -34,9 +40,12 @@ type TestTypesClusterGetter interface { TestTypes() TestTypeClusterInterface } -// TestTypeClusterInterface can scope down to one cluster and return a TestTypesNamespacer. +// 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) (*examplev1beta1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) } type testTypesClusterInterface struct { @@ -52,6 +61,16 @@ func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) Tes 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) (*examplev1beta1.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 examplev1beta1client.TestTypeInterface. type TestTypesNamespacer interface { Namespace(string) examplev1beta1client.TestTypeInterface diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go index 758358ee6..610484c07 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/interface.go @@ -26,6 +26,8 @@ import ( ) type ClusterInterface interface { + // TestTypes returns a TestTypeClusterInformer + TestTypes() TestTypeClusterInformer // ClusterTestTypes returns a ClusterTestTypeClusterInformer ClusterTestTypes() ClusterTestTypeClusterInformer } @@ -40,12 +42,19 @@ func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalin 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 } @@ -61,6 +70,11 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin 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/generic.go b/examples/pkg/kcp/clients/informers/externalversions/generic.go index 02cbb364d..0e9e4a29d 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcp/clients/informers/externalversions/generic.go @@ -108,6 +108,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().ClusterTestTypes().Informer()}, nil // Group=example, Version=V1beta1 + case examplev1beta1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().TestTypes().Informer()}, nil case examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().ClusterTestTypes().Informer()}, nil // Group=example, Version=V2 @@ -156,6 +158,9 @@ func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionRe informer := f.Example().V1alpha1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil // Group=example, Version=V1beta1 + case examplev1beta1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.Example().V1beta1().TestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil case examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): informer := f.Example().V1beta1().ClusterTestTypes().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go index be3536bca..f08cef981 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/fake/testtype.go @@ -30,8 +30,11 @@ import ( 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" examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" applyconfigurationsexamplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" @@ -55,6 +58,31 @@ func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexa 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) (*examplev1beta1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &examplev1beta1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &examplev1beta1.TestTypeList{ListMeta: obj.(*examplev1beta1.TestTypeList).ListMeta} + for _, item := range obj.(*examplev1beta1.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 @@ -114,6 +142,30 @@ func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.G return obj.(*examplev1beta1.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) (*examplev1beta1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &examplev1beta1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &examplev1beta1.TestTypeList{ListMeta: obj.(*examplev1beta1.TestTypeList).ListMeta} + for _, item := range obj.(*examplev1beta1.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) (*examplev1beta1.TestType, error) { obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &examplev1beta1.TestType{}) if obj == nil { diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/testtype.go index cfae770e1..5c84ea007 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/testtype.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1/testtype.go @@ -22,9 +22,15 @@ limitations under the License. package v1beta1 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" + + examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev1beta1client "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" ) @@ -34,9 +40,12 @@ type TestTypesClusterGetter interface { TestTypes() TestTypeClusterInterface } -// TestTypeClusterInterface can scope down to one cluster and return a TestTypesNamespacer. +// 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) (*examplev1beta1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) } type testTypesClusterInterface struct { @@ -52,6 +61,16 @@ func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) Tes 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) (*examplev1beta1.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 examplev1beta1client.TestTypeInterface. type TestTypesNamespacer interface { Namespace(string) examplev1beta1client.TestTypeInterface diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go index 667f35557..557112ccb 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/interface.go @@ -26,6 +26,8 @@ import ( ) type ClusterInterface interface { + // TestTypes returns a TestTypeClusterInformer + TestTypes() TestTypeClusterInformer // ClusterTestTypes returns a ClusterTestTypeClusterInformer ClusterTestTypes() ClusterTestTypeClusterInformer } @@ -40,6 +42,11 @@ func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalin 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/generic.go b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go index f6a0e1ccd..96a664308 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go @@ -104,6 +104,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case examplev1alpha1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1alpha1().ClusterTestTypes().Informer()}, nil // Group=example, Version=V1beta1 + case examplev1beta1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().TestTypes().Informer()}, nil case examplev1beta1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example().V1beta1().ClusterTestTypes().Informer()}, nil // Group=example, Version=V2 diff --git a/go.mod b/go.mod index b0463fbd3..1b9a4287b 100644 --- a/go.mod +++ b/go.mod @@ -12,11 +12,11 @@ require ( k8s.io/code-generator v0.31.0 k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7 k8s.io/klog/v2 v2.130.1 - sigs.k8s.io/controller-tools v0.15.0 + sigs.k8s.io/controller-tools v0.16.1 ) require ( - github.com/fatih/color v1.16.0 // indirect + github.com/fatih/color v1.17.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/google/go-cmp v0.6.0 // indirect diff --git a/go.sum b/go.sum index a2bbaea0b..62c6a3890 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= -github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= +github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= @@ -142,5 +142,5 @@ k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7 h1:cErOOTkQ3JW19o4lo91fFurouh k8s.io/gengo/v2 v2.0.0-20240826214909-a7b603a56eb7/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -sigs.k8s.io/controller-tools v0.15.0 h1:4dxdABXGDhIa68Fiwaif0vcu32xfwmgQ+w8p+5CxoAI= -sigs.k8s.io/controller-tools v0.15.0/go.mod h1:8zUSS2T8Hx0APCNRhJWbS3CAQEbIxLa07khzh7pZmXM= +sigs.k8s.io/controller-tools v0.16.1 h1:gvIsZm+2aimFDIBiDKumR7EBkc+oLxljoUVfRbDI6RI= +sigs.k8s.io/controller-tools v0.16.1/go.mod h1:0I0xqjR65YTfoO12iR+mZR6s6UAVcUARgXRlsu0ljB0=