mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-26 07:02:01 +00:00
Merge pull request #70803 from Adirio/controller-cleanup
Remove duplicate code in client-go/tools/cache/controller.go Kubernetes-commit: fba3c54b9e565b276ae495f189155335c297b6ec
This commit is contained in:
commit
508753d179
104
Godeps/Godeps.json
generated
104
Godeps/Godeps.json
generated
@ -1,7 +1,7 @@
|
||||
{
|
||||
"ImportPath": "k8s.io/client-go",
|
||||
"GoVersion": "go1.11",
|
||||
"GodepVersion": "v80",
|
||||
"GodepVersion": "v80-k8s-r1",
|
||||
"Packages": [
|
||||
"./..."
|
||||
],
|
||||
@ -408,207 +408,207 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/fuzzer",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/roundtrip",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/api/equality",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/api/errors",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/api/meta",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/api/resource",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/conversion",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/fields",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/labels",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/runtime",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/selection",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/types",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/cache",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/clock",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/diff",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/errors",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/framer",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/json",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/naming",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/net",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/runtime",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/sets",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/validation",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/validation/field",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/wait",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/version",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/pkg/watch",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect",
|
||||
"Rev": "450d01ad5771972f60ff23d8f7c6df3211cffbcf"
|
||||
"Rev": "a4bb047fdb92ce239f4bf0c3402b6ec14bb242de"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/klog",
|
||||
|
66
tools/cache/controller.go
vendored
66
tools/cache/controller.go
vendored
@ -285,45 +285,7 @@ func NewInformer(
|
||||
// This will hold the client state, as we know it.
|
||||
clientState := NewStore(DeletionHandlingMetaNamespaceKeyFunc)
|
||||
|
||||
// This will hold incoming changes. Note how we pass clientState in as a
|
||||
// KeyLister, that way resync operations will result in the correct set
|
||||
// of update/delete deltas.
|
||||
fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, clientState)
|
||||
|
||||
cfg := &Config{
|
||||
Queue: fifo,
|
||||
ListerWatcher: lw,
|
||||
ObjectType: objType,
|
||||
FullResyncPeriod: resyncPeriod,
|
||||
RetryOnError: false,
|
||||
|
||||
Process: func(obj interface{}) error {
|
||||
// from oldest to newest
|
||||
for _, d := range obj.(Deltas) {
|
||||
switch d.Type {
|
||||
case Sync, Added, Updated:
|
||||
if old, exists, err := clientState.Get(d.Object); err == nil && exists {
|
||||
if err := clientState.Update(d.Object); err != nil {
|
||||
return err
|
||||
}
|
||||
h.OnUpdate(old, d.Object)
|
||||
} else {
|
||||
if err := clientState.Add(d.Object); err != nil {
|
||||
return err
|
||||
}
|
||||
h.OnAdd(d.Object)
|
||||
}
|
||||
case Deleted:
|
||||
if err := clientState.Delete(d.Object); err != nil {
|
||||
return err
|
||||
}
|
||||
h.OnDelete(d.Object)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return clientState, New(cfg)
|
||||
return clientState, newInformer(lw, objType, resyncPeriod, h, clientState)
|
||||
}
|
||||
|
||||
// NewIndexerInformer returns a Indexer and a controller for populating the index
|
||||
@ -352,6 +314,30 @@ func NewIndexerInformer(
|
||||
// This will hold the client state, as we know it.
|
||||
clientState := NewIndexer(DeletionHandlingMetaNamespaceKeyFunc, indexers)
|
||||
|
||||
return clientState, newInformer(lw, objType, resyncPeriod, h, clientState)
|
||||
}
|
||||
|
||||
// newInformer returns a controller for populating the store while also
|
||||
// providing event notifications.
|
||||
//
|
||||
// Parameters
|
||||
// * lw is list and watch functions for the source of the resource you want to
|
||||
// be informed of.
|
||||
// * objType is an object of the type that you expect to receive.
|
||||
// * resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate
|
||||
// calls, even if nothing changed). Otherwise, re-list will be delayed as
|
||||
// long as possible (until the upstream source closes the watch or times out,
|
||||
// or you stop the controller).
|
||||
// * h is the object you want notifications sent to.
|
||||
// * clientState is the store you want to populate
|
||||
//
|
||||
func newInformer(
|
||||
lw ListerWatcher,
|
||||
objType runtime.Object,
|
||||
resyncPeriod time.Duration,
|
||||
h ResourceEventHandler,
|
||||
clientState Store,
|
||||
) Controller {
|
||||
// This will hold incoming changes. Note how we pass clientState in as a
|
||||
// KeyLister, that way resync operations will result in the correct set
|
||||
// of update/delete deltas.
|
||||
@ -390,5 +376,5 @@ func NewIndexerInformer(
|
||||
return nil
|
||||
},
|
||||
}
|
||||
return clientState, New(cfg)
|
||||
return New(cfg)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user