diff --git a/examples/go.mod b/examples/go.mod index 8aff2ec5..5a86e3c2 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -13,6 +13,8 @@ require ( sigs.k8s.io/structured-merge-diff/v4 v4.4.2 ) +replace github.com/kcp-dev/apimachinery/v2 => github.com/ntnn/kcp-apimachinery/v2 v2.0.1-0.20250428144613-bc81e2899ce5 + require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect diff --git a/examples/go.sum b/examples/go.sum index f3b7a264..81694f5d 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -41,8 +41,6 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20241230150911-cd7529a844f3 h1:c9j9T9Q5g7o8VhC1SqfN/J/RdbcKQODbg3giJUigtYI= -github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20241230150911-cd7529a844f3/go.mod h1:LRmJklLHYYIpEPIYG4GaF8NkCCrmMMQbaMQlhaOTjvU= github.com/kcp-dev/client-go v0.0.0-20230927101349-0416c830e3b1 h1:cyRhjhVSmcUqsMg0wh+DB/DjlpV58nhRpJYxRgCjayA= github.com/kcp-dev/client-go v0.0.0-20230927101349-0416c830e3b1/go.mod h1:XfQFbR0lb2SsNEiAcR0ktxzgjlcJQpiWLX+OHw3a5ac= github.com/kcp-dev/logicalcluster/v3 v3.0.4 h1:q7KngML/QM7sWl8aVzmfZF0TPMnBwYNxsPKfwUvvBvU= @@ -65,6 +63,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/ntnn/kcp-apimachinery/v2 v2.0.1-0.20250428144613-bc81e2899ce5 h1:mX0T75UptYapqS2S9FGpFv9Ot3d3Igu5WQdvqXNwJxg= +github.com/ntnn/kcp-apimachinery/v2 v2.0.1-0.20250428144613-bc81e2899ce5/go.mod h1:jnMZxVnCuKlkIXc4J1Qtmy1Lyo171CDF/RQhNAo0tvA= github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM= github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4= diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go index 239d4b96..668b7cf5 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1/clustertesttype.go @@ -42,6 +42,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1listers.ClusterTestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister examplev1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go index f9582f25..626a4470 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1/testtype.go @@ -42,6 +42,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1listers.TestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister examplev1listers.TestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go index e634ede9..9bfbcbbe 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/clustertesttype.go @@ -42,6 +42,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1alpha1listers.ClusterTestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister examplev1alpha1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go index 82fc872a..bc374d7a 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1alpha1/testtype.go @@ -42,6 +42,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1alpha1listers.TestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister examplev1alpha1listers.TestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go index ba4713aa..ea875e9e 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/clustertesttype.go @@ -42,6 +42,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1beta1listers.ClusterTestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister examplev1beta1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go index 08da0852..32883411 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v1beta1/testtype.go @@ -42,6 +42,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1beta1listers.TestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister examplev1beta1listers.TestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go index 2411f841..c4acc02f 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v2/clustertesttype.go @@ -42,6 +42,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev2listers.ClusterTestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister examplev2listers.ClusterTestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go index 784880e2..f8f57f85 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example/v2/testtype.go @@ -42,6 +42,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev2listers.TestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister examplev2listers.TestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go index da7c4934..f93faddc 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/clustertesttype.go @@ -42,6 +42,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() example3v1listers.ClusterTestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister example3v1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go index caf44c3f..69990de1 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/example3/v1/testtype.go @@ -42,6 +42,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() example3v1listers.TestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister example3v1listers.TestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go index d1243504..25f1d178 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -42,6 +42,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() exampledashedv1listers.ClusterTestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister exampledashedv1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go index 17921565..f26974bb 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go @@ -42,6 +42,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() exampledashedv1listers.TestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister exampledashedv1listers.TestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go index 14cc85b5..249b0166 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go @@ -42,6 +42,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() existinginterfacesv1listers.ClusterTestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister existinginterfacesv1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go index 9382e7b2..41c927ad 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/existinginterfaces/v1/testtype.go @@ -42,6 +42,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() existinginterfacesv1listers.TestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister existinginterfacesv1listers.TestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/generic.go b/examples/pkg/kcp/clients/informers/externalversions/generic.go index ed203408..423cd6ea 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcp/clients/informers/externalversions/generic.go @@ -19,6 +19,7 @@ limitations under the License. package informers import ( + "context" "fmt" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" @@ -39,6 +40,7 @@ import ( type GenericClusterInformer interface { Cluster(logicalcluster.Name) GenericInformer + ClusterWithContext(context.Context, logicalcluster.Name) GenericInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() kcpcache.GenericClusterLister } @@ -71,6 +73,15 @@ func (f *genericClusterInformer) Cluster(clusterName logicalcluster.Name) Generi } } +// ClusterWithContext scopes to a GenericInformer and unregisters all +// handles registered through it once the provided context is canceled. +func (f *genericClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) GenericInformer { + return &genericInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().ByCluster(clusterName), + } +} + type genericInformer struct { informer cache.SharedIndexInformer lister cache.GenericLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go index 0a06a6f9..40a2ab3e 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/clustertesttype.go @@ -42,6 +42,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() secondexamplev1listers.ClusterTestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister secondexamplev1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go index e9cc42de..f7e000f0 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/kcp/clients/informers/externalversions/secondexample/v1/testtype.go @@ -42,6 +42,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() secondexamplev1listers.TestTypeClusterLister } @@ -113,6 +114,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister secondexamplev1listers.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go index dab7403e..8fd9a20d 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/clustertesttype.go @@ -43,6 +43,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexamplev1informers.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexamplev1informers.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1listers.ClusterTestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexamplev1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexamplev1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go index d48722d2..c1163c35 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1/testtype.go @@ -43,6 +43,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexamplev1informers.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexamplev1informers.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1listers.TestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstr } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexamplev1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexamplev1listers.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go index 6b2d21aa..b753d2ef 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/clustertesttype.go @@ -43,6 +43,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexamplev1alpha1informers.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexamplev1alpha1informers.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1alpha1listers.ClusterTestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexamplev1alpha1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexamplev1alpha1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go index f543be7c..b54859fd 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1alpha1/testtype.go @@ -43,6 +43,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexamplev1alpha1informers.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexamplev1alpha1informers.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1alpha1listers.TestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstr } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexamplev1alpha1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexamplev1alpha1listers.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go index 965f2805..96483e5c 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/clustertesttype.go @@ -43,6 +43,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexamplev1beta1informers.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexamplev1beta1informers.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1beta1listers.ClusterTestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexamplev1beta1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexamplev1beta1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go index f0e926c4..71c35ead 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v1beta1/testtype.go @@ -43,6 +43,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexamplev1beta1informers.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexamplev1beta1informers.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev1beta1listers.TestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstr } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexamplev1beta1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexamplev1beta1listers.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go index 481393bc..90f13f88 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/clustertesttype.go @@ -43,6 +43,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexamplev2informers.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexamplev2informers.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev2listers.ClusterTestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexamplev2informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexamplev2listers.ClusterTestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go index 3d26b6d8..e8fc5130 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example/v2/testtype.go @@ -43,6 +43,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexamplev2informers.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexamplev2informers.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() examplev2listers.TestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstr } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexamplev2informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexamplev2listers.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go index 2b3bb741..4818b69e 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/clustertesttype.go @@ -43,6 +43,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexample3v1informers.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexample3v1informers.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() example3v1listers.ClusterTestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexample3v1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexample3v1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go index fd4da045..27ec5ba0 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/example3/v1/testtype.go @@ -43,6 +43,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexample3v1informers.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexample3v1informers.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() example3v1listers.TestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstr } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexample3v1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexample3v1listers.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go index f1145ffb..4ca24679 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -43,6 +43,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() exampledashedv1listers.ClusterTestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexampledashedv1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go index aec1b8ae..f9055002 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go @@ -43,6 +43,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() exampledashedv1listers.TestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstr } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexampledashedv1listers.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go index f5d1b148..b7a206c4 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/clustertesttype.go @@ -43,6 +43,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexistinginterfacesv1informers.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexistinginterfacesv1informers.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() existinginterfacesv1listers.ClusterTestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexistinginterfacesv1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexistinginterfacesv1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go index d19fc2bc..412098de 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces/v1/testtype.go @@ -43,6 +43,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamexistinginterfacesv1informers.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamexistinginterfacesv1informers.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() existinginterfacesv1listers.TestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstr } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamexistinginterfacesv1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister upstreamexistinginterfacesv1listers.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go index 611135ec..a70d34cf 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go @@ -19,6 +19,7 @@ limitations under the License. package informers import ( + "context" "fmt" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" @@ -40,6 +41,7 @@ import ( type GenericClusterInformer interface { Cluster(logicalcluster.Name) upstreaminformers.GenericInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreaminformers.GenericInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() kcpcache.GenericClusterLister } @@ -67,6 +69,15 @@ func (f *genericClusterInformer) Cluster(clusterName logicalcluster.Name) upstre } } +// ClusterWithContext scopes to a GenericInformer and unregisters all +// handles registered through it once the provided context is canceled. +func (f *genericClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreaminformers.GenericInformer { + return &genericInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().ByCluster(clusterName), + } +} + type genericInformer struct { informer cache.SharedIndexInformer lister cache.GenericLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go index b491026c..5eadc935 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/clustertesttype.go @@ -43,6 +43,7 @@ import ( // ClusterTestTypes. type ClusterTestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamsecondexamplev1informers.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamsecondexamplev1informers.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() secondexamplev1listers.ClusterTestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (f *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamsecondexamplev1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister upstreamsecondexamplev1listers.ClusterTestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go index c286f92a..4d55093c 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/secondexample/v1/testtype.go @@ -43,6 +43,7 @@ import ( // TestTypes. type TestTypeClusterInformer interface { Cluster(logicalcluster.Name) upstreamsecondexamplev1informers.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) upstreamsecondexamplev1informers.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() secondexamplev1listers.TestTypeClusterLister } @@ -107,6 +108,13 @@ func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstr } } +func (f *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) upstreamsecondexamplev1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister upstreamsecondexamplev1listers.TestTypeLister diff --git a/pkg/internal/clientgen/clientset.go b/pkg/internal/clientgen/clientset.go index 668b730e..c9694ec9 100644 --- a/pkg/internal/clientgen/clientset.go +++ b/pkg/internal/clientgen/clientset.go @@ -58,7 +58,7 @@ import ( "github.com/kcp-dev/logicalcluster/v3" client "{{.singleClusterClientPackagePath}}" - + "k8s.io/client-go/discovery" "k8s.io/client-go/rest" "k8s.io/client-go/util/flowcontrol" @@ -91,7 +91,7 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { } {{range .groups}} -// {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}ClusterClient. +// {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}ClusterClient. func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { return c.{{.GroupGoNameLower}}{{.Version}} } @@ -106,7 +106,7 @@ func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Inter } // NewForConfig creates a new ClusterClientset for the given config. -// If config's RateLimiter is not set and QPS and Burst are acceptable, +// If config's RateLimiter is not set and QPS and Burst are acceptable, // NewForConfig will generate a rate-limiter in configShallowCopy. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/pkg/internal/informergen/factory.go b/pkg/internal/informergen/factory.go index 1764a4ca..deee23c9 100644 --- a/pkg/internal/informergen/factory.go +++ b/pkg/internal/informergen/factory.go @@ -82,7 +82,7 @@ import ( "k8s.io/client-go/tools/cache" clientset "{{.clientsetPackagePath}}" - {{if not .useUpstreamInterfaces -}} + {{if not .useUpstreamInterfaces -}} scopedclientset "{{.singleClusterClientPackagePath}}" {{end -}} {{if .useUpstreamInterfaces -}} @@ -265,7 +265,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal type ScopedDynamicSharedInformerFactory interface { // ForResource gives generic access to a shared informer of the matching type. ForResource(resource schema.GroupVersionResource) ({{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer, error) - + // Start initializes all requested informers. They are handled in goroutines // which run until the stop channel gets closed. Start(stopCh <-chan struct{}) @@ -353,7 +353,7 @@ func (f *scopedDynamicSharedInformerFactory) ForResource(resource schema.GroupVe if err != nil { return nil, err } - return clusterInformer.Cluster(f.clusterName), nil + return clusterInformer.Cluster(f.clusterName), nil } func (f *scopedDynamicSharedInformerFactory) Start(stopCh <-chan struct{}) { diff --git a/pkg/internal/informergen/generic.go b/pkg/internal/informergen/generic.go index af46d14b..3a9a3d0f 100644 --- a/pkg/internal/informergen/generic.go +++ b/pkg/internal/informergen/generic.go @@ -63,6 +63,7 @@ var genericInformer = ` package informers import ( + "context" "fmt" "k8s.io/apimachinery/pkg/runtime/schema" @@ -81,6 +82,7 @@ import ( type GenericClusterInformer interface { Cluster(logicalcluster.Name) {{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer + ClusterWithContext(context.Context, logicalcluster.Name) {{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() kcpcache.GenericClusterLister } @@ -115,6 +117,15 @@ func (f *genericClusterInformer) Cluster(clusterName logicalcluster.Name) {{if . } } +// ClusterWithContext scopes to a GenericInformer and unregisters all +// handles registered through it once the provided context is canceled. +func (f *genericClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer { + return &genericInformer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().ByCluster(clusterName), + } +} + type genericInformer struct { informer cache.SharedIndexInformer lister cache.GenericLister diff --git a/pkg/internal/informergen/informer.go b/pkg/internal/informergen/informer.go index 79604042..859d4de4 100644 --- a/pkg/internal/informergen/informer.go +++ b/pkg/internal/informergen/informer.go @@ -108,7 +108,7 @@ import ( {{end -}} clientset "{{.clientsetPackagePath}}" - {{if not .useUpstreamInterfaces -}} + {{if not .useUpstreamInterfaces -}} scopedclientset "{{.singleClusterClientPackagePath}}" {{end -}} @@ -119,6 +119,7 @@ import ( // {{.kind.Plural}}. type {{.kind}}ClusterInformer interface { Cluster(logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.GoPackageAlias}}informers.{{end}}{{.kind}}Informer + ClusterWithContext(context.Context, logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.GoPackageAlias}}informers.{{end}}{{.kind}}Informer Informer() kcpcache.ScopeableSharedIndexInformer Lister() {{.group.GoPackageAlias}}listers.{{.kind}}ClusterLister } @@ -164,7 +165,7 @@ func (f *{{.kind.String|lowerFirst}}ClusterInformer) defaultInformer(client clie return NewFiltered{{.kind}}ClusterInformer(client, resyncPeriod, cache.Indexers{ kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, {{if .kind.IsNamespaced}}kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc,{{end -}} - }, + }, f.tweakListOptions, ) } @@ -193,6 +194,13 @@ func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logical } } +func (f *{{.kind.String|lowerFirst}}ClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.GoPackageAlias}}informers.{{end}}{{.kind}}Informer { + return &{{.kind.String|lowerFirst}}Informer{ + informer: f.Informer().ClusterWithContext(ctx, clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + type {{.kind.String|lowerFirst}}Informer struct { informer cache.SharedIndexInformer lister {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.GoPackageAlias}}listers.{{.kind.String}}Lister diff --git a/pkg/internal/listergen/lister.go b/pkg/internal/listergen/lister.go index 864d5bad..621f289e 100644 --- a/pkg/internal/listergen/lister.go +++ b/pkg/internal/listergen/lister.go @@ -46,9 +46,9 @@ var lister = ` package {{.group.Version.PackageName}} import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" "github.com/kcp-dev/logicalcluster/v3" - + "k8s.io/client-go/tools/cache" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/api/errors"