@@ -19,6 +19,8 @@ package cacher
1919import (
2020 "context"
2121
22+ "google.golang.org/grpc/metadata"
23+
2224 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2325 "k8s.io/apimachinery/pkg/fields"
2426 "k8s.io/apimachinery/pkg/labels"
@@ -30,17 +32,19 @@ import (
3032
3133// listerWatcher opaques storage.Interface to expose cache.ListerWatcher.
3234type listerWatcher struct {
33- storage storage.Interface
34- resourcePrefix string
35- newListFunc func () runtime.Object
35+ storage storage.Interface
36+ resourcePrefix string
37+ newListFunc func () runtime.Object
38+ contextMetadata metadata.MD
3639}
3740
3841// NewListerWatcher returns a storage.Interface backed ListerWatcher.
39- func NewListerWatcher (storage storage.Interface , resourcePrefix string , newListFunc func () runtime.Object ) cache.ListerWatcher {
42+ func NewListerWatcher (storage storage.Interface , resourcePrefix string , newListFunc func () runtime.Object , contextMetadata metadata. MD ) cache.ListerWatcher {
4043 return & listerWatcher {
41- storage : storage ,
42- resourcePrefix : resourcePrefix ,
43- newListFunc : newListFunc ,
44+ storage : storage ,
45+ resourcePrefix : resourcePrefix ,
46+ newListFunc : newListFunc ,
47+ contextMetadata : contextMetadata ,
4448 }
4549}
4650
@@ -59,7 +63,11 @@ func (lw *listerWatcher) List(options metav1.ListOptions) (runtime.Object, error
5963 Predicate : pred ,
6064 Recursive : true ,
6165 }
62- if err := lw .storage .GetList (context .TODO (), lw .resourcePrefix , storageOpts , list ); err != nil {
66+ ctx := context .Background ()
67+ if lw .contextMetadata != nil {
68+ ctx = metadata .NewOutgoingContext (ctx , lw .contextMetadata )
69+ }
70+ if err := lw .storage .GetList (ctx , lw .resourcePrefix , storageOpts , list ); err != nil {
6371 return nil , err
6472 }
6573 return list , nil
@@ -73,5 +81,9 @@ func (lw *listerWatcher) Watch(options metav1.ListOptions) (watch.Interface, err
7381 Recursive : true ,
7482 ProgressNotify : true ,
7583 }
76- return lw .storage .Watch (context .TODO (), lw .resourcePrefix , opts )
84+ ctx := context .Background ()
85+ if lw .contextMetadata != nil {
86+ ctx = metadata .NewOutgoingContext (ctx , lw .contextMetadata )
87+ }
88+ return lw .storage .Watch (ctx , lw .resourcePrefix , opts )
7789}
0 commit comments