diff --git a/cmd/cluster-informer-gen/generators/generic.go b/cmd/cluster-informer-gen/generators/generic.go index d479a16c..9ff7af7e 100644 --- a/cmd/cluster-informer-gen/generators/generic.go +++ b/cmd/cluster-informer-gen/generators/generic.go @@ -132,6 +132,7 @@ func (g *genericGenerator) GenerateType(c *generator.Context, t *types.Type, w i "cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer), "scopeableCacheSharedIndexInformer": c.Universe.Type(scopeableCacheSharedIndexInformer), "fmtErrorf": c.Universe.Type(fmtErrorfFunc), + "contextContext": c.Universe.Type(contextContext), "groups": groups, "schemeGVs": schemeGVs, "schemaGroupResource": c.Universe.Type(schemaGroupResource), @@ -155,6 +156,7 @@ func (g *genericGenerator) GenerateType(c *generator.Context, t *types.Type, w i var genericClusterInformer = ` type GenericClusterInformer interface { Cluster({{.logicalclusterName|raw}}) {{.genericInformer|raw}} + ClusterWithContext({{.contextContext|raw}}, {{.logicalclusterName|raw}}) {{.genericInformer|raw}} Informer() {{.scopeableCacheSharedIndexInformer|raw}} Lister() {{.kcpcacheGenericClusterLister|raw}} } @@ -188,6 +190,15 @@ func (i *genericClusterInformer) Cluster(clusterName {{.logicalclusterName|raw}} lister: i.Lister().ByCluster(clusterName), } } + +// ClusterWithContext scopes to a GenericInformer and unregisters all +// handles registered through it once the provided context is canceled. +func (i *genericClusterInformer) ClusterWithContext(ctx {{.contextContext|raw}}, clusterName {{.logicalclusterName|raw}}) {{.genericInformer|raw}} { + return &genericInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().ByCluster(clusterName), + } +} ` var genericInformer = ` diff --git a/cmd/cluster-informer-gen/generators/informer.go b/cmd/cluster-informer-gen/generators/informer.go index 45fb30b7..4a8ef752 100644 --- a/cmd/cluster-informer-gen/generators/informer.go +++ b/cmd/cluster-informer-gen/generators/informer.go @@ -107,6 +107,7 @@ func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w "clientSetInterface": clientSetInterface, "clientSetClusterInterface": clientSetClusterInterface, "contextBackground": c.Universe.Function(contextBackgroundFunc), + "contextContext": c.Universe.Type(contextContext), "group": namer.IC(g.groupGoName), "interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}), "interfacesSharedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}), @@ -151,6 +152,7 @@ var typeClusterInformerInterface = ` // $.type|publicPlural$. type $.type|public$ClusterInformer interface { Cluster($.logicalclusterName|raw$) $.informerInterface|raw$ + ClusterWithContext($.contextContext|raw$, $.logicalclusterName|raw$) $.informerInterface|raw$ Informer() $.scopeableCacheSharedIndexInformer|raw$ Lister() $.clusterLister|raw$ } @@ -227,6 +229,13 @@ func (i *$.type|private$ClusterInformer) Cluster(clusterName $.logicalclusterNam lister: i.Lister().Cluster(clusterName), } } + +func (i *$.type|private$ClusterInformer) ClusterWithContext(ctx $.contextContext|raw$, clusterName $.logicalclusterName|raw$) $.informerInterface|raw$ { + return &$.type|private$Informer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} ` var typeInformer = ` diff --git a/cmd/cluster-informer-gen/generators/types.go b/cmd/cluster-informer-gen/generators/types.go index 1dfd3c61..c40e654f 100644 --- a/cmd/cluster-informer-gen/generators/types.go +++ b/cmd/cluster-informer-gen/generators/types.go @@ -33,6 +33,7 @@ var ( kcpcacheNewGenericClusterLister = types.Name{Package: "github.com/kcp-dev/apimachinery/v2/pkg/cache", Name: "NewGenericClusterLister"} kcpinformersNewSharedIndexInformer = types.Name{Package: "github.com/kcp-dev/apimachinery/v2/third_party/informers", Name: "NewSharedIndexInformer"} cacheTransformFunc = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "TransformFunc"} + contextContext = types.Name{Package: "context", Name: "Context"} contextBackgroundFunc = types.Name{Package: "context", Name: "Background"} fmtErrorfFunc = types.Name{Package: "fmt", Name: "Errorf"} reflectType = types.Name{Package: "reflect", Name: "Type"} diff --git a/examples/go.mod b/examples/go.mod index 66edd67e..80233b5b 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -7,7 +7,7 @@ toolchain go1.23.7 replace acme.corp/pkg => ./pkg require ( - github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250425065633-635c2a0fbaba + github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077 github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98 github.com/kcp-dev/logicalcluster/v3 v3.0.5 k8s.io/apimachinery v0.32.3 diff --git a/examples/go.sum b/examples/go.sum index dfccb81e..17515814 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -36,8 +36,8 @@ 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.20250425065633-635c2a0fbaba h1:Ar/8wsCQWrZgRiBF2B5xCqCXEA/oiiuDI0yEsUtrxRs= -github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250425065633-635c2a0fbaba/go.mod h1:pYqnaSG3NlF/pVwfnYCAdGvrA7FpALFmd5S9X4XXf1Q= +github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077 h1:lDi9nZ75ypmRJwDFXUN70Cdu8+HxAjPU1kcnn+l4MvI= +github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250512171935-ebb573a40077/go.mod h1:jnMZxVnCuKlkIXc4J1Qtmy1Lyo171CDF/RQhNAo0tvA= github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98 h1:A1Hc2zVGd9LRSQqlGGqfzin+4skWJVcsNXw2+MjU6z4= github.com/kcp-dev/client-go v0.0.0-20250512170835-5457a0f4bd98/go.mod h1:79pmlxmvE/hohqD/qvhKaaoXmNDF/uhKnnAO6Vf5hZk= github.com/kcp-dev/logicalcluster/v3 v3.0.5 h1:JbYakokb+5Uinz09oTXomSUJVQsqfxEvU4RyHUYxHOU= @@ -72,8 +72,8 @@ github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 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 bc237500..d39fabba 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() examplev1.ClusterTestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister examplev1.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 07e8c420..5896b82f 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() examplev1.TestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister examplev1.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 2cdbc3d1..6ffc3eb5 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() examplev1alpha1.ClusterTestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister examplev1alpha1.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 57a1fb24..2a0ffd0d 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() examplev1alpha1.TestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister examplev1alpha1.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 cb03b8cd..a593d755 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() examplev1beta1.ClusterTestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister examplev1beta1.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 31c7e2ff..bdfb6132 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() examplev1beta1.TestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister examplev1beta1.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 e3274f36..5ef67625 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() examplev2.ClusterTestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister examplev2.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 acad02cc..a15181b3 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() examplev2.TestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister examplev2.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 4d76e89e..c5ecc345 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() example3v1.ClusterTestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister example3v1.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 e491d0c0..59b3f7d1 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() example3v1.TestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister example3v1.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 b668e69b..032b39f5 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() exampledashedv1.ClusterTestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister exampledashedv1.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 4775c858..a2d793c8 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() exampledashedv1.TestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister exampledashedv1.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 198b0ddd..2190b0ca 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() existinginterfacesv1.ClusterTestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister existinginterfacesv1.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 07269239..93af98a8 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() existinginterfacesv1.TestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister existinginterfacesv1.TestTypeLister diff --git a/examples/pkg/kcp/clients/informers/externalversions/generic.go b/examples/pkg/kcp/clients/informers/externalversions/generic.go index d206d0bd..54a5c0a2 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 externalversions import ( + context "context" fmt "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 (i *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 (i *genericClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) GenericInformer { + return &genericInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.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 4eba4501..ee0f6a65 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() secondexamplev1.ClusterTestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister secondexamplev1.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 605a2eb8..0b7a0f3d 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() secondexamplev1.TestTypeClusterLister } @@ -105,6 +106,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestT } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister secondexamplev1.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 2e3a76ed..bc6a570e 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) examplev1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexamplev1.ClusterTestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexamplev1.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 a1e52d7e..c1446bb5 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) examplev1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexamplev1.TestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examp } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexamplev1.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 dd3cd4f2..98f25a10 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) examplev1alpha1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1alpha1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexamplev1alpha1.ClusterTestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1alpha1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexamplev1alpha1.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 ed03573f..b3db7d34 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) examplev1alpha1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1alpha1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexamplev1alpha1.TestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examp } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1alpha1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexamplev1alpha1.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 9c33c1fd..fa174662 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) examplev1beta1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1beta1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexamplev1beta1.ClusterTestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1beta1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexamplev1beta1.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 d39f5035..673a5970 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) examplev1beta1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev1beta1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexamplev1beta1.TestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examp } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev1beta1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexamplev1beta1.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 46f2016a..75c2f392 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) examplev2.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev2.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexamplev2.ClusterTestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev2.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexamplev2.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 355b2c5f..5c179753 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) examplev2.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) examplev2.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexamplev2.TestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examp } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) examplev2.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexamplev2.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 45d07021..47eff472 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) example3v1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) example3v1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexample3v1.ClusterTestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) example3v1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexample3v1.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 b9ef9334..03997695 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) example3v1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) example3v1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexample3v1.TestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examp } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) example3v1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexample3v1.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 6de4b8ae..d842d693 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) exampledashedv1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) exampledashedv1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexampledashedv1.ClusterTestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) exampledashedv1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexampledashedv1.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 38bc8305..0755b1fc 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) exampledashedv1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) exampledashedv1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexampledashedv1.TestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) examp } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) exampledashedv1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexampledashedv1.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 9c505960..c352eda7 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) existinginterfacesv1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) existinginterfacesv1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexistinginterfacesv1.ClusterTestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) existinginterfacesv1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexistinginterfacesv1.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 4e5717c6..e43184d9 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) existinginterfacesv1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) existinginterfacesv1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listersexistinginterfacesv1.TestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) exist } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) existinginterfacesv1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister generatedlistersexistinginterfacesv1.TestTypeLister diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go index 79f7f849..f565c857 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 externalversions import ( + context "context" fmt "fmt" kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" @@ -40,6 +41,7 @@ import ( type GenericClusterInformer interface { Cluster(logicalcluster.Name) informersexternalversions.GenericInformer + ClusterWithContext(context.Context, logicalcluster.Name) informersexternalversions.GenericInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() kcpcache.GenericClusterLister } @@ -67,6 +69,15 @@ func (i *genericClusterInformer) Cluster(clusterName logicalcluster.Name) inform } } +// ClusterWithContext scopes to a GenericInformer and unregisters all +// handles registered through it once the provided context is canceled. +func (i *genericClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) informersexternalversions.GenericInformer { + return &genericInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.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 3512edd6..0e4668f2 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) secondexamplev1.ClusterTestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) secondexamplev1.ClusterTestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listerssecondexamplev1.ClusterTestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name } } +func (i *clusterTestTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) secondexamplev1.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type clusterTestTypeInformer struct { informer cache.SharedIndexInformer lister generatedlisterssecondexamplev1.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 2989de31..d96c3ac6 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) secondexamplev1.TestTypeInformer + ClusterWithContext(context.Context, logicalcluster.Name) secondexamplev1.TestTypeInformer Informer() kcpcache.ScopeableSharedIndexInformer Lister() listerssecondexamplev1.TestTypeClusterLister } @@ -106,6 +107,13 @@ func (i *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) secon } } +func (i *testTypeClusterInformer) ClusterWithContext(ctx context.Context, clusterName logicalcluster.Name) secondexamplev1.TestTypeInformer { + return &testTypeInformer{ + informer: i.Informer().ClusterWithContext(ctx, clusterName), + lister: i.Lister().Cluster(clusterName), + } +} + type testTypeInformer struct { informer cache.SharedIndexInformer lister generatedlisterssecondexamplev1.TestTypeLister