Skip to content

Commit bd510e1

Browse files
committed
Remove default, return timeout error
Punt on what a sensible default value should be for the cache sync. Return a `NewTimeoutError` when we timeout for cache sync.
1 parent d3b15d3 commit bd510e1

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed

pkg/cache/informer_cache.go

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ func (ip *informerCache) Get(ctx context.Context, key client.ObjectKey, out runt
5858
return err
5959
}
6060

61-
ctx, cancelFunc := addTimeout(ctx)
62-
if cancelFunc != nil {
63-
defer cancelFunc()
64-
}
65-
cache, err := ip.InformersMap.Get(ctx, gvk, out)
6661
started, cache, err := ip.InformersMap.Get(ctx, gvk, out)
6762
if err != nil {
6863
return err
@@ -107,10 +102,6 @@ func (ip *informerCache) List(ctx context.Context, out runtime.Object, opts ...c
107102
}
108103
}
109104

110-
ctx, cancelFunc := addTimeout(ctx)
111-
if cancelFunc != nil {
112-
defer cancelFunc()
113-
}
114105
started, cache, err := ip.InformersMap.Get(ctx, gvk, cacheTypeObj)
115106
if err != nil {
116107
return err
@@ -123,47 +114,29 @@ func (ip *informerCache) List(ctx context.Context, out runtime.Object, opts ...c
123114
return cache.Reader.List(ctx, out, opts...)
124115
}
125116

126-
// addTimeout adds a default 30 second timeout to a child contxt
127-
// if one does not exist.
128-
func addTimeout(ctx context.Context) (context.Context, context.CancelFunc) {
129-
var cancelFunc context.CancelFunc
130-
if _, ok := ctx.Deadline(); !ok {
131-
ctx, cancelFunc = context.WithTimeout(ctx, 30*time.Second)
132-
}
133-
return ctx, cancelFunc
134-
}
135-
136117
// GetInformerForKind returns the informer for the GroupVersionKind
137-
// Will timeout after 30 seconds if the informer is new and can not be
138-
// synced.
139118
func (ip *informerCache) GetInformerForKind(gvk schema.GroupVersionKind) (Informer, error) {
140119
// Map the gvk to an object
141120
obj, err := ip.Scheme.New(gvk)
142121
if err != nil {
143122
return nil, err
144123
}
145-
ctx, cancelFunc := addTimeout(context.TODO())
146-
// There will never be a nil cancelFunc
147-
defer cancelFunc()
148-
_, i, err := ip.InformersMap.Get(ctx, gvk, obj)
124+
125+
_, i, err := ip.InformersMap.Get(context.TODO(), gvk, obj)
149126
if err != nil {
150127
return nil, err
151128
}
152129
return i.Informer, err
153130
}
154131

155132
// GetInformer returns the informer for the obj
156-
// Will timeout after 30 seconds if the informer is new and can not be
157-
// synced.
158133
func (ip *informerCache) GetInformer(obj runtime.Object) (Informer, error) {
159134
gvk, err := apiutil.GVKForObject(obj, ip.Scheme)
160135
if err != nil {
161136
return nil, err
162137
}
163-
ctx, cancelFunc := addTimeout(context.TODO())
164-
// There will never be a nil cancelFunc
165-
defer cancelFunc()
166-
_, i, err := ip.InformersMap.Get(ctx, gvk, obj)
138+
139+
_, i, err := ip.InformersMap.Get(context.TODO(), gvk, obj)
167140
if err != nil {
168141
return nil, err
169142
}

pkg/cache/internal/informers_map.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"sync"
2323
"time"
2424

25+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2526
"k8s.io/apimachinery/pkg/api/meta"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/runtime"
@@ -174,7 +175,7 @@ func (ip *specificInformersMap) Get(ctx context.Context, gvk schema.GroupVersion
174175
case <-ctx.Done():
175176
//end the polling for cache to sync
176177
done <- struct{}{}
177-
return started, nil, fmt.Errorf("timeout waiting for %T Informer to sync", obj)
178+
return started, nil, apierrors.NewTimeoutError(fmt.Sprintf("timeout waiting for %T Informer to sync", obj), 0)
178179
case syncSuccess := <-syncReturn:
179180
if !syncSuccess {
180181
return started, nil, fmt.Errorf("failed waiting for %T Informer to sync", obj)

0 commit comments

Comments
 (0)