From 75e4230bbce3246a26dbd875f616dd3612322878 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 19 Oct 2023 10:48:02 +0200 Subject: [PATCH 1/2] Add label selector also when watching The watcher was not respecting its label selector when watching, only when listing. Fixes: a5b617d47 ("Improve CoreDNS affinity check in basic inttest") Signed-off-by: Tom Wieczorek --- pkg/kubernetes/watch/watcher.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/kubernetes/watch/watcher.go b/pkg/kubernetes/watch/watcher.go index 17f8a705d9e8..85b80ce56a82 100644 --- a/pkg/kubernetes/watch/watcher.go +++ b/pkg/kubernetes/watch/watcher.go @@ -288,6 +288,7 @@ func (w *Watcher[T]) watch(ctx context.Context, resourceVersion string, conditio ResourceVersion: resourceVersion, AllowWatchBookmarks: true, FieldSelector: w.fieldSelector, + LabelSelector: w.labelSelector, TimeoutSeconds: pointer.Int64(maxWatchDurationSecs), }) if err != nil { From 0c54d3925b1b8d2862b2ec8e1e3a5a75a2c30027 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Thu, 19 Oct 2023 11:11:10 +0200 Subject: [PATCH 2/2] Update source link in docs for field selectors Apparently the link format has changed a little bit and needs to be fully percent encoded. Signed-off-by: Tom Wieczorek --- pkg/kubernetes/watch/watcher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kubernetes/watch/watcher.go b/pkg/kubernetes/watch/watcher.go index 85b80ce56a82..f5463dffb672 100644 --- a/pkg/kubernetes/watch/watcher.go +++ b/pkg/kubernetes/watch/watcher.go @@ -154,7 +154,7 @@ func (w *Watcher[T]) WithObjectName(name string) *Watcher[T] { // [Kubernetes codebase]. // // [concept]: https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/ -// [Kubernetes codebase]: https://sourcegraph.com/search?q=lang:go+AddFieldLabelConversionFunc(...)+repo:^github\.com/kubernetes/kubernetes%24+-file:_test\.go%24+select:content&patternType=structural +// [Kubernetes codebase]: https://sourcegraph.com/search?q=lang:go+AddFieldLabelConversionFunc%28...%29+repo:%5Egithub%5C.com/kubernetes/kubernetes%24+-file:_test%5C.go%24+select:content&patternType=structural func (w *Watcher[T]) WithFieldSelector(selector fields.Selector) *Watcher[T] { w.fieldSelector = selector.String() return w