@@ -25,21 +25,26 @@ import (
25
25
"sync"
26
26
"time"
27
27
28
+ "github.com/go-logr/logr"
28
29
apierrors "k8s.io/apimachinery/pkg/api/errors"
29
30
"k8s.io/apimachinery/pkg/api/meta"
30
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
32
"k8s.io/apimachinery/pkg/runtime"
32
33
"k8s.io/apimachinery/pkg/runtime/schema"
33
34
"k8s.io/apimachinery/pkg/runtime/serializer"
35
+ "k8s.io/apimachinery/pkg/util/wait"
34
36
"k8s.io/apimachinery/pkg/watch"
35
37
"k8s.io/client-go/dynamic"
36
38
"k8s.io/client-go/metadata"
37
39
"k8s.io/client-go/rest"
38
40
"k8s.io/client-go/tools/cache"
39
41
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
42
+ logf "sigs.k8s.io/controller-runtime/pkg/internal/log"
40
43
"sigs.k8s.io/controller-runtime/pkg/internal/syncs"
41
44
)
42
45
46
+ var log = logf .RuntimeLog .WithName ("cache" )
47
+
43
48
// InformersOpts configures an InformerMap.
44
49
type InformersOpts struct {
45
50
HTTPClient * http.Client
@@ -52,7 +57,7 @@ type InformersOpts struct {
52
57
Transform cache.TransformFunc
53
58
UnsafeDisableDeepCopy bool
54
59
EnableWatchBookmarks bool
55
- WatchErrorHandler cache.WatchErrorHandler
60
+ WatchErrorHandler cache.WatchErrorHandlerWithContext
56
61
}
57
62
58
63
// NewInformers creates a new InformersMap that can create informers under the hood.
@@ -105,7 +110,8 @@ func (c *Cache) Start(stop <-chan struct{}) {
105
110
// Stop on either the whole map stopping or just this informer being removed.
106
111
internalStop , cancel := syncs .MergeChans (stop , c .stop )
107
112
defer cancel ()
108
- c .Informer .Run (internalStop )
113
+ // Convert the stop channel to a context and then add the logger.
114
+ c .Informer .RunWithContext (logr .NewContext (wait .ContextForChannel (internalStop ), log ))
109
115
}
110
116
111
117
type tracker struct {
@@ -181,10 +187,10 @@ type Informers struct {
181
187
// NewInformer allows overriding of the shared index informer constructor for testing.
182
188
newInformer func (cache.ListerWatcher , runtime.Object , time.Duration , cache.Indexers ) cache.SharedIndexInformer
183
189
184
- // WatchErrorHandler allows the shared index informer's
190
+ // watchErrorHandler allows the shared index informer's
185
191
// watchErrorHandler to be set by overriding the options
186
192
// or to use the default watchErrorHandler
187
- watchErrorHandler cache.WatchErrorHandler
193
+ watchErrorHandler cache.WatchErrorHandlerWithContext
188
194
}
189
195
190
196
// Start calls Run on each of the informers and sets started to true. Blocks on the context.
@@ -376,7 +382,7 @@ func (ip *Informers) addInformerToMap(gvk schema.GroupVersionKind, obj runtime.O
376
382
377
383
// Set WatchErrorHandler on SharedIndexInformer if set
378
384
if ip .watchErrorHandler != nil {
379
- if err := sharedIndexInformer .SetWatchErrorHandler (ip .watchErrorHandler ); err != nil {
385
+ if err := sharedIndexInformer .SetWatchErrorHandlerWithContext (ip .watchErrorHandler ); err != nil {
380
386
return nil , false , err
381
387
}
382
388
}
0 commit comments