Update godeps
This commit is contained in:
parent
8b25cc67a5
commit
a736fba0e1
769 changed files with 15495 additions and 7996 deletions
106
vendor/k8s.io/kubernetes/pkg/storage/cacher.go
generated
vendored
106
vendor/k8s.io/kubernetes/pkg/storage/cacher.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
@ -28,7 +28,6 @@ import (
|
|||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/client/cache"
|
||||
"k8s.io/kubernetes/pkg/conversion"
|
||||
|
|
@ -73,19 +72,13 @@ type CacherConfig struct {
|
|||
type Cacher struct {
|
||||
sync.RWMutex
|
||||
|
||||
// Each user-facing method that is not simply redirected to the underlying
|
||||
// storage has to read-lock on this mutex before starting any processing.
|
||||
// Before accessing the cacher's cache, wait for the ready to be ok.
|
||||
// This is necessary to prevent users from accessing structures that are
|
||||
// uninitialized or are being repopulated right now.
|
||||
// NOTE: We cannot easily reuse the main mutex for it due to multi-threaded
|
||||
// interactions of Cacher with the underlying WatchCache. Since Cacher is
|
||||
// caling WatchCache directly and WatchCache is calling Cacher methods
|
||||
// via its OnEvent and OnReplace hooks, we explicitly assume that if mutexes
|
||||
// of both structures are held, the one from WatchCache is acquired first
|
||||
// to avoid deadlocks. Unfortunately, forcing this rule in startCaching
|
||||
// would be very difficult and introducing one more mutex seems to be much
|
||||
// easier.
|
||||
usable sync.RWMutex
|
||||
// ready needs to be set to false when the cacher is paused or stopped.
|
||||
// ready needs to be set to true when the cacher is ready to use after
|
||||
// initialization.
|
||||
ready *ready
|
||||
|
||||
// Underlying storage.Interface.
|
||||
storage Interface
|
||||
|
|
@ -111,37 +104,6 @@ type Cacher struct {
|
|||
stopWg sync.WaitGroup
|
||||
}
|
||||
|
||||
// Create a new Cacher responsible from service WATCH and LIST requests from its
|
||||
// internal cache and updating its cache in the background based on the given
|
||||
// configuration.
|
||||
func NewCacher(
|
||||
storage Interface,
|
||||
capacity int,
|
||||
versioner Versioner,
|
||||
objectType runtime.Object,
|
||||
resourcePrefix string,
|
||||
scopeStrategy rest.NamespaceScopedStrategy,
|
||||
newListFunc func() runtime.Object) Interface {
|
||||
config := CacherConfig{
|
||||
CacheCapacity: capacity,
|
||||
Storage: storage,
|
||||
Versioner: versioner,
|
||||
Type: objectType,
|
||||
ResourcePrefix: resourcePrefix,
|
||||
NewListFunc: newListFunc,
|
||||
}
|
||||
if scopeStrategy.NamespaceScoped() {
|
||||
config.KeyFunc = func(obj runtime.Object) (string, error) {
|
||||
return NamespaceKeyFunc(resourcePrefix, obj)
|
||||
}
|
||||
} else {
|
||||
config.KeyFunc = func(obj runtime.Object) (string, error) {
|
||||
return NoNamespaceKeyFunc(resourcePrefix, obj)
|
||||
}
|
||||
}
|
||||
return NewCacherFromConfig(config)
|
||||
}
|
||||
|
||||
// Create a new Cacher responsible from service WATCH and LIST requests from its
|
||||
// internal cache and updating its cache in the background based on the given
|
||||
// configuration.
|
||||
|
|
@ -158,25 +120,20 @@ func NewCacherFromConfig(config CacherConfig) *Cacher {
|
|||
}
|
||||
|
||||
cacher := &Cacher{
|
||||
usable: sync.RWMutex{},
|
||||
ready: newReady(),
|
||||
storage: config.Storage,
|
||||
watchCache: watchCache,
|
||||
reflector: cache.NewReflector(listerWatcher, config.Type, watchCache, 0),
|
||||
watcherIdx: 0,
|
||||
watchers: make(map[int]*cacheWatcher),
|
||||
versioner: config.Versioner,
|
||||
keyFunc: config.KeyFunc,
|
||||
stopped: false,
|
||||
// We need to (potentially) stop both:
|
||||
// - wait.Until go-routine
|
||||
// - reflector.ListAndWatch
|
||||
// and there are no guarantees on the order that they will stop.
|
||||
// So we will be simply closing the channel, and synchronizing on the WaitGroup.
|
||||
stopCh: make(chan struct{}),
|
||||
stopWg: sync.WaitGroup{},
|
||||
}
|
||||
// See startCaching method for explanation and where this is unlocked.
|
||||
cacher.usable.Lock()
|
||||
watchCache.SetOnEvent(cacher.processEvent)
|
||||
|
||||
stopCh := cacher.stopCh
|
||||
|
|
@ -204,11 +161,11 @@ func (c *Cacher) startCaching(stopChannel <-chan struct{}) {
|
|||
successfulList := false
|
||||
c.watchCache.SetOnReplace(func() {
|
||||
successfulList = true
|
||||
c.usable.Unlock()
|
||||
c.ready.set(true)
|
||||
})
|
||||
defer func() {
|
||||
if successfulList {
|
||||
c.usable.Lock()
|
||||
c.ready.set(false)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -249,9 +206,7 @@ func (c *Cacher) Watch(ctx context.Context, key string, resourceVersion string,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Do NOT allow Watch to start when the underlying structures are not propagated.
|
||||
c.usable.RLock()
|
||||
defer c.usable.RUnlock()
|
||||
c.ready.wait()
|
||||
|
||||
// We explicitly use thread unsafe version and do locking ourself to ensure that
|
||||
// no new events will be processed in the meantime. The watchCache will be unlocked
|
||||
|
|
@ -308,13 +263,7 @@ func (c *Cacher) List(ctx context.Context, key string, resourceVersion string, f
|
|||
return err
|
||||
}
|
||||
|
||||
// To avoid situation when List is processed before the underlying
|
||||
// watchCache is propagated for the first time, we acquire and immediately
|
||||
// release the 'usable' lock.
|
||||
// We don't need to hold it all the time, because watchCache is thread-safe
|
||||
// and it would complicate already very difficult locking pattern.
|
||||
c.usable.RLock()
|
||||
c.usable.RUnlock()
|
||||
c.ready.wait()
|
||||
|
||||
// List elements from cache, with at least 'listRV'.
|
||||
listPtr, err := meta.GetItemsPtr(listObj)
|
||||
|
|
@ -417,18 +366,13 @@ func filterFunction(key string, keyFunc func(runtime.Object) (string, error), fi
|
|||
|
||||
// Returns resource version to which the underlying cache is synced.
|
||||
func (c *Cacher) LastSyncResourceVersion() (uint64, error) {
|
||||
// To avoid situation when LastSyncResourceVersion is processed before the
|
||||
// underlying watchCache is propagated, we acquire 'usable' lock.
|
||||
c.usable.RLock()
|
||||
defer c.usable.RUnlock()
|
||||
|
||||
c.RLock()
|
||||
defer c.RUnlock()
|
||||
c.ready.wait()
|
||||
|
||||
resourceVersion := c.reflector.LastSyncResourceVersion()
|
||||
if resourceVersion == "" {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return strconv.ParseUint(resourceVersion, 10, 64)
|
||||
}
|
||||
|
||||
|
|
@ -627,3 +571,27 @@ func (c *cacheWatcher) process(initEvents []watchCacheEvent, resourceVersion uin
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ready struct {
|
||||
ok bool
|
||||
c *sync.Cond
|
||||
}
|
||||
|
||||
func newReady() *ready {
|
||||
return &ready{c: sync.NewCond(&sync.Mutex{})}
|
||||
}
|
||||
|
||||
func (r *ready) wait() {
|
||||
r.c.L.Lock()
|
||||
for !r.ok {
|
||||
r.c.Wait()
|
||||
}
|
||||
r.c.L.Unlock()
|
||||
}
|
||||
|
||||
func (r *ready) set(ok bool) {
|
||||
r.c.L.Lock()
|
||||
defer r.c.L.Unlock()
|
||||
r.ok = ok
|
||||
r.c.Broadcast()
|
||||
}
|
||||
|
|
|
|||
2
vendor/k8s.io/kubernetes/pkg/storage/doc.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/storage/doc.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
|||
2
vendor/k8s.io/kubernetes/pkg/storage/errors.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/storage/errors.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
|||
2
vendor/k8s.io/kubernetes/pkg/storage/interfaces.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/storage/interfaces.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
|||
2
vendor/k8s.io/kubernetes/pkg/storage/util.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/storage/util.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
|||
2
vendor/k8s.io/kubernetes/pkg/storage/watch_cache.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/storage/watch_cache.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue