Skip to content

refactor: Replace ListerWatcher with ListerWatcherWithContext #2724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions internal/store/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@
func (b *Builder) buildStores(
metricFamilies []generator.FamilyGenerator,
expectedType interface{},
listWatchFunc func(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher,
listWatchWithContextFunc func(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext,
useAPIServerCache bool, objectLimit int64,
) []cache.Store {
metricFamilies = generator.FilterFamilyGenerators(b.familyGeneratorFilter, metricFamilies)
Expand All @@ -531,8 +531,8 @@
if b.fieldSelectorFilter != "" {
klog.InfoS("FieldSelector is used", "fieldSelector", b.fieldSelectorFilter)
}
listWatcher := listWatchFunc(b.kubeClient, v1.NamespaceAll, b.fieldSelectorFilter)
b.startReflector(expectedType, store, listWatcher, useAPIServerCache, objectLimit)
listWatcherWithContext := listWatchWithContextFunc(b.kubeClient, v1.NamespaceAll, b.fieldSelectorFilter)
b.startReflector(expectedType, store, listWatcherWithContext, useAPIServerCache, objectLimit)
return []cache.Store{store}
}

Expand All @@ -545,8 +545,8 @@
if b.fieldSelectorFilter != "" {
klog.InfoS("FieldSelector is used", "fieldSelector", b.fieldSelectorFilter)
}
listWatcher := listWatchFunc(b.kubeClient, ns, b.fieldSelectorFilter)
b.startReflector(expectedType, store, listWatcher, useAPIServerCache, objectLimit)
listWatcherWithContext := listWatchWithContextFunc(b.kubeClient, ns, b.fieldSelectorFilter)
b.startReflector(expectedType, store, listWatcherWithContext, useAPIServerCache, objectLimit)
stores = append(stores, store)
}

Expand All @@ -557,7 +557,7 @@
func (b *Builder) buildCustomResourceStores(resourceName string,
metricFamilies []generator.FamilyGenerator,
expectedType interface{},
listWatchFunc func(customResourceClient interface{}, ns string, fieldSelector string) cache.ListerWatcher,
listWatchWithContextFunc func(customResourceClient interface{}, ns string, fieldSelector string) cache.ListerWatcherWithContext,
useAPIServerCache bool, objectLimit int64,
) []cache.Store {
metricFamilies = generator.FilterFamilyGenerators(b.familyGeneratorFilter, metricFamilies)
Expand Down Expand Up @@ -589,8 +589,8 @@
if b.fieldSelectorFilter != "" {
klog.InfoS("FieldSelector is used", "fieldSelector", b.fieldSelectorFilter)
}
listWatcher := listWatchFunc(customResourceClient, v1.NamespaceAll, b.fieldSelectorFilter)
b.startReflector(expectedType, store, listWatcher, useAPIServerCache, objectLimit)
listWatcherWithContext := listWatchWithContextFunc(customResourceClient, v1.NamespaceAll, b.fieldSelectorFilter)
b.startReflector(expectedType, store, listWatcherWithContext, useAPIServerCache, objectLimit)
return []cache.Store{store}
}

Expand All @@ -601,8 +601,8 @@
composedMetricGenFuncs,
)
klog.InfoS("FieldSelector is used", "fieldSelector", b.fieldSelectorFilter)
listWatcher := listWatchFunc(customResourceClient, ns, b.fieldSelectorFilter)
b.startReflector(expectedType, store, listWatcher, useAPIServerCache, objectLimit)
listWatcherWithContext := listWatchWithContextFunc(customResourceClient, ns, b.fieldSelectorFilter)
b.startReflector(expectedType, store, listWatcherWithContext, useAPIServerCache, objectLimit)
stores = append(stores, store)
}

Expand All @@ -614,12 +614,12 @@
func (b *Builder) startReflector(
expectedType interface{},
store cache.Store,
listWatcher cache.ListerWatcher,
listWatcherWithContext cache.ListerWatcherWithContext,
useAPIServerCache bool,
objectLimit int64,
) {
instrumentedListWatch := watch.NewInstrumentedListerWatcher(listWatcher, b.listWatchMetrics, reflect.TypeOf(expectedType).String(), useAPIServerCache, objectLimit)
reflector := cache.NewReflectorWithOptions(sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatch), expectedType, store, cache.ReflectorOptions{ResyncPeriod: 0})
instrumentedListWatchWithContext := watch.NewInstrumentedListerWatcher(listWatcherWithContext, b.listWatchMetrics, reflect.TypeOf(expectedType).String(), useAPIServerCache, objectLimit)
reflector := cache.NewReflectorWithOptions(sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext), expectedType, store, cache.ReflectorOptions{ResyncPeriod: 0})

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-go-lint

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List)) (typecheck)

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-go-lint

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List)) (typecheck)

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-go-lint

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List)) (typecheck)

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-go-lint

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List) (typecheck)

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-go-lint

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List)) (typecheck)

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-unit-tests

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List)

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-benchmark-tests

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List)

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-build-kube-state-metrics

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List)

Check failure on line 622 in internal/store/builder.go

View workflow job for this annotation

GitHub Actions / ci-validate-docs

cannot use sharding.NewShardedListWatch(b.shard, b.totalShards, instrumentedListWatchWithContext) (value of interface type "k8s.io/client-go/tools/cache".ListerWatcherWithContext) as "k8s.io/client-go/tools/cache".ListerWatcher value in argument to cache.NewReflectorWithOptions: "k8s.io/client-go/tools/cache".ListerWatcherWithContext does not implement "k8s.io/client-go/tools/cache".ListerWatcher (missing method List)
Copy link
Author

@onasser1 onasser1 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue:
newReflectorWithOptions which is used from client-go is taking a ListerWatcher as an argument and inside its logic converts it to ListerWatcherWithContext
https://github.com/kubernetes/client-go/blob/v0.33.3/tools/cache/reflector.go#L259

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch. Do you want to work with client-go folks to update the implementation to support ListerWatcherWithContext as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely Yes! but my question is should we update the parameter list to receive ListerWatcherWithContext but wouldn't this make a dependency conflict? Or we should support another version of the function with different parameter list as we would do an override.
or Let's move this question to a new issue at client-go repo? WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since lister watcher without context is deprecated, I think we need a new NewReflector function in client-go. Yeah please open up an issue with client-go

if cr, ok := expectedType.(*unstructured.Unstructured); ok {
go reflector.Run((*b.GVKToReflectorStopChanMap)[cr.GroupVersionKind().String()])
} else {
Expand Down
10 changes: 5 additions & 5 deletions internal/store/certificatesigningrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ func wrapCSRFunc(f func(*certv1.CertificateSigningRequest) *metric.Family) func(
}
}

func createCSRListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcher {
func createCSRListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.CertificatesV1().CertificateSigningRequests().List(context.TODO(), opts)
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.CertificatesV1().CertificateSigningRequests().List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.CertificatesV1().CertificateSigningRequests().Watch(context.TODO(), opts)
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.CertificatesV1().CertificateSigningRequests().Watch(ctx, opts)
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/store/clusterrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ func clusterRoleMetricFamilies(allowAnnotationsList, allowLabelsList []string) [
}
}

func createClusterRoleListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcher {
func createClusterRoleListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.RbacV1().ClusterRoles().List(context.TODO(), opts)
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.RbacV1().ClusterRoles().List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.RbacV1().ClusterRoles().Watch(context.TODO(), opts)
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.RbacV1().ClusterRoles().Watch(ctx, opts)
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/store/clusterrolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ func clusterRoleBindingMetricFamilies(allowAnnotationsList, allowLabelsList []st
}
}

func createClusterRoleBindingListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcher {
func createClusterRoleBindingListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.RbacV1().ClusterRoleBindings().List(context.TODO(), opts)
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.RbacV1().ClusterRoleBindings().List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.RbacV1().ClusterRoleBindings().Watch(context.TODO(), opts)
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.RbacV1().ClusterRoleBindings().Watch(ctx, opts)
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/store/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ func configMapMetricFamilies(allowAnnotationsList, allowLabelsList []string) []g
}
}

func createConfigMapListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createConfigMapListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.CoreV1().ConfigMaps(ns).List(context.TODO(), opts)
return kubeClient.CoreV1().ConfigMaps(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.CoreV1().ConfigMaps(ns).Watch(context.TODO(), opts)
return kubeClient.CoreV1().ConfigMaps(ns).Watch(ctx, opts)
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/store/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,15 @@ func wrapCronJobFunc(f func(*batchv1.CronJob) *metric.Family) func(interface{})
}
}

func createCronJobListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createCronJobListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.BatchV1().CronJobs(ns).List(context.TODO(), opts)
return kubeClient.BatchV1().CronJobs(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.BatchV1().CronJobs(ns).Watch(context.TODO(), opts)
return kubeClient.BatchV1().CronJobs(ns).Watch(ctx, opts)
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/store/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ func wrapDaemonSetFunc(f func(*v1.DaemonSet) *metric.Family) func(interface{}) *
}
}

func createDaemonSetListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createDaemonSetListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AppsV1().DaemonSets(ns).List(context.TODO(), opts)
return kubeClient.AppsV1().DaemonSets(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AppsV1().DaemonSets(ns).Watch(context.TODO(), opts)
return kubeClient.AppsV1().DaemonSets(ns).Watch(ctx, opts)
},
}
}
10 changes: 5 additions & 5 deletions internal/store/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@ func wrapDeploymentFunc(f func(*v1.Deployment) *metric.Family) func(interface{})
}
}

func createDeploymentListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createDeploymentListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AppsV1().Deployments(ns).List(context.TODO(), opts)
return kubeClient.AppsV1().Deployments(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AppsV1().Deployments(ns).Watch(context.TODO(), opts)
return kubeClient.AppsV1().Deployments(ns).Watch(ctx, opts)
},
}
}
10 changes: 5 additions & 5 deletions internal/store/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ func wrapEndpointFunc(f func(*v1.Endpoints) *metric.Family) func(interface{}) *m
}
}

func createEndpointsListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createEndpointsListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.CoreV1().Endpoints(ns).List(context.TODO(), opts)
return kubeClient.CoreV1().Endpoints(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.CoreV1().Endpoints(ns).Watch(context.TODO(), opts)
return kubeClient.CoreV1().Endpoints(ns).Watch(ctx, opts)
},
}
}
10 changes: 5 additions & 5 deletions internal/store/endpointslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ func wrapEndpointSliceFunc(f func(*discoveryv1.EndpointSlice) *metric.Family) fu
}
}

func createEndpointSliceListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createEndpointSliceListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.DiscoveryV1().EndpointSlices(ns).List(context.TODO(), opts)
return kubeClient.DiscoveryV1().EndpointSlices(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.DiscoveryV1().EndpointSlices(ns).Watch(context.TODO(), opts)
return kubeClient.DiscoveryV1().EndpointSlices(ns).Watch(ctx, opts)
},
}
}
10 changes: 5 additions & 5 deletions internal/store/horizontalpodautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ func wrapHPAFunc(f func(*autoscaling.HorizontalPodAutoscaler) *metric.Family) fu
}
}

func createHPAListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createHPAListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AutoscalingV2().HorizontalPodAutoscalers(ns).List(context.TODO(), opts)
return kubeClient.AutoscalingV2().HorizontalPodAutoscalers(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AutoscalingV2().HorizontalPodAutoscalers(ns).Watch(context.TODO(), opts)
return kubeClient.AutoscalingV2().HorizontalPodAutoscalers(ns).Watch(ctx, opts)
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/store/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@ func wrapIngressFunc(f func(*networkingv1.Ingress) *metric.Family) func(interfac
}
}

func createIngressListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createIngressListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.NetworkingV1().Ingresses(ns).List(context.TODO(), opts)
return kubeClient.NetworkingV1().Ingresses(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.NetworkingV1().Ingresses(ns).Watch(context.TODO(), opts)
return kubeClient.NetworkingV1().Ingresses(ns).Watch(ctx, opts)
},
}
}
10 changes: 5 additions & 5 deletions internal/store/ingressclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func wrapIngressClassFunc(f func(*networkingv1.IngressClass) *metric.Family) fun
}
}

func createIngressClassListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcher {
func createIngressClassListWatch(kubeClient clientset.Interface, _ string, _ string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.NetworkingV1().IngressClasses().List(context.TODO(), opts)
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.NetworkingV1().IngressClasses().List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.NetworkingV1().IngressClasses().Watch(context.TODO(), opts)
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.NetworkingV1().IngressClasses().Watch(ctx, opts)
},
}
}
10 changes: 5 additions & 5 deletions internal/store/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,15 @@ func wrapJobFunc(f func(*v1batch.Job) *metric.Family) func(interface{}) *metric.
}
}

func createJobListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createJobListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.BatchV1().Jobs(ns).List(context.TODO(), opts)
return kubeClient.BatchV1().Jobs(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.BatchV1().Jobs(ns).Watch(context.TODO(), opts)
return kubeClient.BatchV1().Jobs(ns).Watch(ctx, opts)
},
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/store/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ func wrapLeaseFunc(f func(*coordinationv1.Lease) *metric.Family) func(interface{
}
}

func createLeaseListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
func createLeaseListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcherWithContext {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
ListWithContextFunc: func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.CoordinationV1().Leases(ns).List(context.TODO(), opts)
return kubeClient.CoordinationV1().Leases(ns).List(ctx, opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
WatchFuncWithContext: func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.CoordinationV1().Leases(ns).Watch(context.TODO(), opts)
return kubeClient.CoordinationV1().Leases(ns).Watch(ctx, opts)
},
}
}
Loading
Loading