mirror of
https://github.com/kubernetes/client-go.git
synced 2025-12-25 14:12:27 +00:00
Add RealFIFOOptions struct to provide structured configuration for RealFIFO
Signed-off-by: xigang <wangxigang2014@gmail.com> Kubernetes-commit: 26bbea8c07131080f763c4ccc1eda5daa66803a6
This commit is contained in:
committed by
Kubernetes Publisher
parent
f49b36f94e
commit
00a491e0ce
8
tools/cache/controller.go
vendored
8
tools/cache/controller.go
vendored
@@ -19,13 +19,13 @@ package cache
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
clientgofeaturegate "k8s.io/client-go/features"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
clientgofeaturegate "k8s.io/client-go/features"
|
||||
"k8s.io/utils/clock"
|
||||
)
|
||||
|
||||
@@ -598,7 +598,11 @@ func newInformer(clientState Store, options InformerOptions) Controller {
|
||||
|
||||
var fifo Queue
|
||||
if clientgofeaturegate.FeatureGates().Enabled(clientgofeaturegate.InOrderInformers) {
|
||||
fifo = NewRealFIFO(MetaNamespaceKeyFunc, clientState, options.Transform)
|
||||
fifo = NewRealFIFOWithOptions(RealFIFOOptions{
|
||||
KeyFunction: MetaNamespaceKeyFunc,
|
||||
KnownObjects: clientState,
|
||||
Transformer: options.Transform,
|
||||
})
|
||||
} else {
|
||||
fifo = NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||
KnownObjects: clientState,
|
||||
|
||||
6
tools/cache/shared_informer.go
vendored
6
tools/cache/shared_informer.go
vendored
@@ -541,7 +541,11 @@ func (s *sharedIndexInformer) RunWithContext(ctx context.Context) {
|
||||
|
||||
var fifo Queue
|
||||
if clientgofeaturegate.FeatureGates().Enabled(clientgofeaturegate.InOrderInformers) {
|
||||
fifo = NewRealFIFO(MetaNamespaceKeyFunc, s.indexer, s.transform)
|
||||
fifo = NewRealFIFOWithOptions(RealFIFOOptions{
|
||||
KeyFunction: MetaNamespaceKeyFunc,
|
||||
KnownObjects: s.indexer,
|
||||
Transformer: s.transform,
|
||||
})
|
||||
} else {
|
||||
fifo = NewDeltaFIFOWithOptions(DeltaFIFOOptions{
|
||||
KnownObjects: s.indexer,
|
||||
|
||||
42
tools/cache/the_real_fifo.go
vendored
42
tools/cache/the_real_fifo.go
vendored
@@ -26,6 +26,25 @@ import (
|
||||
utiltrace "k8s.io/utils/trace"
|
||||
)
|
||||
|
||||
// RealFIFOOptions is the configuration parameters for RealFIFO.
|
||||
type RealFIFOOptions struct {
|
||||
// KeyFunction is used to figure out what key an object should have. (It's
|
||||
// exposed in the returned RealFIFO's keyOf() method, with additional
|
||||
// handling around deleted objects and queue state).
|
||||
// Optional, the default is MetaNamespaceKeyFunc.
|
||||
KeyFunction KeyFunc
|
||||
|
||||
// KnownObjects is expected to return a list of keys that the consumer of
|
||||
// this queue "knows about". It is used to decide which items are missing
|
||||
// when Replace() is called; 'Deleted' deltas are produced for the missing items.
|
||||
// KnownObjects is required.
|
||||
KnownObjects KeyListerGetter
|
||||
|
||||
// If set, will be called for objects before enqueueing them. Please
|
||||
// see the comment on TransformFunc for details.
|
||||
Transformer TransformFunc
|
||||
}
|
||||
|
||||
// RealFIFO is a Queue in which every notification from the Reflector is passed
|
||||
// in order to the Queue via Pop.
|
||||
// This means that it
|
||||
@@ -398,16 +417,31 @@ func (f *RealFIFO) Transformer() TransformFunc {
|
||||
// NewRealFIFO returns a Store which can be used to queue up items to
|
||||
// process.
|
||||
func NewRealFIFO(keyFunc KeyFunc, knownObjects KeyListerGetter, transformer TransformFunc) *RealFIFO {
|
||||
if knownObjects == nil {
|
||||
return NewRealFIFOWithOptions(RealFIFOOptions{
|
||||
KeyFunction: keyFunc,
|
||||
KnownObjects: knownObjects,
|
||||
Transformer: transformer,
|
||||
})
|
||||
}
|
||||
|
||||
// NewRealFIFOWithOptions returns a Queue which can be used to process changes to
|
||||
// items. See also the comment on RealFIFO.
|
||||
func NewRealFIFOWithOptions(opts RealFIFOOptions) *RealFIFO {
|
||||
if opts.KeyFunction == nil {
|
||||
opts.KeyFunction = MetaNamespaceKeyFunc
|
||||
}
|
||||
|
||||
if opts.KnownObjects == nil {
|
||||
panic("coding error: knownObjects must be provided")
|
||||
}
|
||||
|
||||
f := &RealFIFO{
|
||||
items: make([]Delta, 0, 10),
|
||||
keyFunc: keyFunc,
|
||||
knownObjects: knownObjects,
|
||||
transformer: transformer,
|
||||
keyFunc: opts.KeyFunction,
|
||||
knownObjects: opts.KnownObjects,
|
||||
transformer: opts.Transformer,
|
||||
}
|
||||
|
||||
f.cond.L = &f.lock
|
||||
return f
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user