watchlist: wrap remaining LW with ToListWatcherWithWatchListSemantics

This commit is contained in:
Lukasz Szaszkiewicz
2025-10-10 22:44:45 +02:00
parent 71fa43e37f
commit 4fd41778b8
5 changed files with 13 additions and 13 deletions

View File

@@ -178,14 +178,14 @@ func WaitForCertificate(ctx context.Context, client clientset.Interface, reqName
fieldSelector := fields.OneTermEqualSelector("metadata.name", reqName).String()
logger := klog.FromContext(ctx)
var lw *cache.ListWatch
var lw cache.ListerWatcher
var obj runtime.Object
for {
// see if the v1 API is available
if _, err := client.CertificatesV1().CertificateSigningRequests().List(ctx, metav1.ListOptions{FieldSelector: fieldSelector}); err == nil {
// watch v1 objects
obj = &certificatesv1.CertificateSigningRequest{}
lw = &cache.ListWatch{
lw = cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = fieldSelector
return client.CertificatesV1().CertificateSigningRequests().List(ctx, options)
@@ -194,7 +194,7 @@ func WaitForCertificate(ctx context.Context, client clientset.Interface, reqName
options.FieldSelector = fieldSelector
return client.CertificatesV1().CertificateSigningRequests().Watch(ctx, options)
},
}
}, client)
break
} else {
logger.V(2).Info("Error fetching v1 certificate signing request", "err", err)
@@ -209,7 +209,7 @@ func WaitForCertificate(ctx context.Context, client clientset.Interface, reqName
if _, err := client.CertificatesV1beta1().CertificateSigningRequests().List(ctx, metav1.ListOptions{FieldSelector: fieldSelector}); err == nil {
// watch v1beta1 objects
obj = &certificatesv1beta1.CertificateSigningRequest{}
lw = &cache.ListWatch{
lw = cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = fieldSelector
return client.CertificatesV1beta1().CertificateSigningRequests().List(ctx, options)
@@ -218,7 +218,7 @@ func WaitForCertificate(ctx context.Context, client clientset.Interface, reqName
options.FieldSelector = fieldSelector
return client.CertificatesV1beta1().CertificateSigningRequests().Watch(ctx, options)
},
}
}, client)
break
} else {
logger.V(2).Info("Error fetching v1beta1 certificate signing request", "err", err)

View File

@@ -452,7 +452,7 @@ func (c *Controller) initInformer(ctx context.Context) error {
},
}
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) {
tweakListOptions(&options)
slices, err := c.resourceClient.ResourceSlices().List(ctx, options)
@@ -469,7 +469,7 @@ func (c *Controller) initInformer(ctx context.Context) error {
logger.V(5).Info("Started watching ResourceSlices", "resourceAPI", c.resourceClient.CurrentAPI(), "err", err)
return w, err
},
},
}, c.resourceClient),
&resourceapi.ResourceSlice{},
// No resync because all it would do is periodically trigger syncing pools
// again by reporting all slices as updated with the object as old/new.

View File

@@ -184,7 +184,7 @@ func (o *RolloutStatusOptions) Run() error {
}
fieldSelector := fields.OneTermEqualSelector("metadata.name", info.Name).String()
lw := &cache.ListWatch{
lw := cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = fieldSelector
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(context.TODO(), options)
@@ -193,7 +193,7 @@ func (o *RolloutStatusOptions) Run() error {
options.FieldSelector = fieldSelector
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(context.TODO(), options)
},
}
}, o.DynamicClient)
// if the rollout isn't done yet, keep watching deployment status
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)

View File

@@ -135,7 +135,7 @@ func getObjAndCheckCondition(ctx context.Context, info *resource.Info, o *WaitOp
mapping := info.ResourceMapping() // used to pass back meaningful errors if object disappears
fieldSelector := fields.OneTermEqualSelector("metadata.name", info.Name).String()
lw := &cache.ListWatch{
lw := cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = fieldSelector
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(context.TODO(), options)
@@ -144,7 +144,7 @@ func getObjAndCheckCondition(ctx context.Context, info *resource.Info, o *WaitOp
options.FieldSelector = fieldSelector
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(context.TODO(), options)
},
}
}, o.DynamicClient)
// this function is used to refresh the cache to prevent timeout waits on resources that have disappeared
preconditionFunc := func(store cache.Store) (bool, error) {

View File

@@ -77,7 +77,7 @@ func IsDeleted(ctx context.Context, info *resource.Info, o *WaitOptions) (runtim
}
fieldSelector := fields.OneTermEqualSelector("metadata.name", info.Name).String()
lw := &cache.ListWatch{
lw := cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = fieldSelector
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(ctx, options)
@@ -86,7 +86,7 @@ func IsDeleted(ctx context.Context, info *resource.Info, o *WaitOptions) (runtim
options.FieldSelector = fieldSelector
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(ctx, options)
},
}
}, o.DynamicClient)
// this function is used to refresh the cache to prevent timeout waits on resources that have disappeared
preconditionFunc := func(store cache.Store) (bool, error) {