diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher.go index 9c7839e57ad..c6c7af9aa7b 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher.go @@ -369,6 +369,12 @@ func (c *Cacher) Get(ctx context.Context, key string, resourceVersion string, ob return err } + if getRV == 0 && !c.ready.check() { + // If Cacher is not yet initialized and we don't require any specific + // minimal resource version, simply forward the request to storage. + return c.storage.Get(ctx, key, resourceVersion, objPtr, ignoreNotFound) + } + // Do not create a trace - it's not for free and there are tons // of Get requests. We can add it if it will be really needed. c.ready.wait() @@ -414,6 +420,12 @@ func (c *Cacher) GetToList(ctx context.Context, key string, resourceVersion stri return err } + if listRV == 0 && !c.ready.check() { + // If Cacher is not yet initialized and we don't require any specific + // minimal resource version, simply forward the request to storage. + return c.storage.GetToList(ctx, key, resourceVersion, pred, listObj) + } + trace := utiltrace.New(fmt.Sprintf("cacher %v: List", c.objectType.String())) defer trace.LogIfLong(500 * time.Millisecond) @@ -470,6 +482,12 @@ func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, p return err } + if listRV == 0 && !c.ready.check() { + // If Cacher is not yet initialized and we don't require any specific + // minimal resource version, simply forward the request to storage. + return c.storage.List(ctx, key, resourceVersion, pred, listObj) + } + trace := utiltrace.New(fmt.Sprintf("cacher %v: List", c.objectType.String())) defer trace.LogIfLong(500 * time.Millisecond) @@ -966,6 +984,14 @@ func (r *ready) wait() { r.c.L.Unlock() } +// TODO: Make check() function more sophisticated, in particular +// allow it to behave as "waitWithTimeout". +func (r *ready) check() bool { + r.c.L.Lock() + defer r.c.L.Unlock() + return r.ok +} + func (r *ready) set(ok bool) { r.c.L.Lock() defer r.c.L.Unlock()