Skip to content

Commit

Permalink
Merge pull request #7727 from omerap12/dep-NewInformerWithOptions
Browse files Browse the repository at this point in the history
chore: replace deprecated NewIndexerInformer
  • Loading branch information
k8s-ci-robot authored Jan 31, 2025
2 parents bd15f93 + 9e9f365 commit 3392d4f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
22 changes: 15 additions & 7 deletions vertical-pod-autoscaler/pkg/recommender/input/cluster_feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package input
import (
"context"
"fmt"
"os"
"slices"
"time"

Expand Down Expand Up @@ -162,13 +163,20 @@ func newPodClients(kubeClient kube_client.Interface, resourceEventHandler cache.
// don't necessarily want to immediately delete them.
selector := fields.ParseSelectorOrDie("status.phase!=" + string(apiv1.PodPending))
podListWatch := cache.NewListWatchFromClient(kubeClient.CoreV1().RESTClient(), "pods", namespace, selector)
indexer, controller := cache.NewIndexerInformer(
podListWatch,
&apiv1.Pod{},
time.Hour,
resourceEventHandler,
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
)
informerOptions := cache.InformerOptions{
ObjectType: &apiv1.Pod{},
ListerWatcher: podListWatch,
Handler: resourceEventHandler,
ResyncPeriod: time.Hour,
Indexers: cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
}

store, controller := cache.NewInformerWithOptions(informerOptions)
indexer, ok := store.(cache.Indexer)
if !ok {
klog.ErrorS(nil, "Expected Indexer, but got a Store that does not implement Indexer")
os.Exit(255)
}
podLister := v1lister.NewPodLister(indexer)
go controller.Run(stopCh)
if !cache.WaitForCacheSync(stopCh, controller.HasSynced) {
Expand Down
19 changes: 14 additions & 5 deletions vertical-pod-autoscaler/pkg/utils/vpa/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,20 @@ func UpdateVpaStatusIfNeeded(vpaClient vpa_api.VerticalPodAutoscalerInterface, v
// The method blocks until vpaLister is initially populated.
func NewVpasLister(vpaClient *vpa_clientset.Clientset, stopChannel <-chan struct{}, namespace string) vpa_lister.VerticalPodAutoscalerLister {
vpaListWatch := cache.NewListWatchFromClient(vpaClient.AutoscalingV1().RESTClient(), "verticalpodautoscalers", namespace, fields.Everything())
indexer, controller := cache.NewIndexerInformer(vpaListWatch,
&vpa_types.VerticalPodAutoscaler{},
1*time.Hour,
&cache.ResourceEventHandlerFuncs{},
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
informerOptions := cache.InformerOptions{
ObjectType: &vpa_types.VerticalPodAutoscaler{},
ListerWatcher: vpaListWatch,
Handler: &cache.ResourceEventHandlerFuncs{},
ResyncPeriod: 1 * time.Hour,
Indexers: cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
}

store, controller := cache.NewInformerWithOptions(informerOptions)
indexer, ok := store.(cache.Indexer)
if !ok {
klog.ErrorS(nil, "Expected Indexer, but got a Store that does not implement Indexer")
os.Exit(255)
}
vpaLister := vpa_lister.NewVerticalPodAutoscalerLister(indexer)
go controller.Run(stopChannel)
if !cache.WaitForCacheSync(stopChannel, controller.HasSynced) {
Expand Down

0 comments on commit 3392d4f

Please sign in to comment.