mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-13 22:01:43 +00:00
Merge pull request #118455 from linxiulei/managedFields
Trim managedFields in controller-manager Kubernetes-commit: 1acd489dca47a4be0301330cbfcf4e8f9d98f7c0
This commit is contained in:
@@ -60,6 +60,7 @@ type sharedInformerFactory struct {
|
|||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
defaultResync time.Duration
|
defaultResync time.Duration
|
||||||
customResync map[reflect.Type]time.Duration
|
customResync map[reflect.Type]time.Duration
|
||||||
|
transform cache.TransformFunc
|
||||||
|
|
||||||
informers map[reflect.Type]cache.SharedIndexInformer
|
informers map[reflect.Type]cache.SharedIndexInformer
|
||||||
// startedInformers is used for tracking which informers have been started.
|
// startedInformers is used for tracking which informers have been started.
|
||||||
@@ -98,6 +99,14 @@ func WithNamespace(namespace string) SharedInformerOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithTransform sets a transform on all informers.
|
||||||
|
func WithTransform(transform cache.TransformFunc) SharedInformerOption {
|
||||||
|
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
||||||
|
factory.transform = transform
|
||||||
|
return factory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
|
// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
|
||||||
func NewSharedInformerFactory(client kubernetes.Interface, defaultResync time.Duration) SharedInformerFactory {
|
func NewSharedInformerFactory(client kubernetes.Interface, defaultResync time.Duration) SharedInformerFactory {
|
||||||
return NewSharedInformerFactoryWithOptions(client, defaultResync)
|
return NewSharedInformerFactoryWithOptions(client, defaultResync)
|
||||||
@@ -202,6 +211,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
informer = newFunc(f.client, resyncPeriod)
|
informer = newFunc(f.client, resyncPeriod)
|
||||||
|
informer.SetTransform(f.transform)
|
||||||
f.informers[informerType] = informer
|
f.informers[informerType] = informer
|
||||||
|
|
||||||
return informer
|
return informer
|
||||||
|
@@ -21,6 +21,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
@@ -31,6 +32,17 @@ import (
|
|||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SharedInformerOption defines the functional option type for metadataSharedInformerFactory.
|
||||||
|
type SharedInformerOption func(*metadataSharedInformerFactory) *metadataSharedInformerFactory
|
||||||
|
|
||||||
|
// WithTransform sets a transform on all informers.
|
||||||
|
func WithTransform(transform cache.TransformFunc) SharedInformerOption {
|
||||||
|
return func(factory *metadataSharedInformerFactory) *metadataSharedInformerFactory {
|
||||||
|
factory.transform = transform
|
||||||
|
return factory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewSharedInformerFactory constructs a new instance of metadataSharedInformerFactory for all namespaces.
|
// NewSharedInformerFactory constructs a new instance of metadataSharedInformerFactory for all namespaces.
|
||||||
func NewSharedInformerFactory(client metadata.Interface, defaultResync time.Duration) SharedInformerFactory {
|
func NewSharedInformerFactory(client metadata.Interface, defaultResync time.Duration) SharedInformerFactory {
|
||||||
return NewFilteredSharedInformerFactory(client, defaultResync, metav1.NamespaceAll, nil)
|
return NewFilteredSharedInformerFactory(client, defaultResync, metav1.NamespaceAll, nil)
|
||||||
@@ -49,10 +61,29 @@ func NewFilteredSharedInformerFactory(client metadata.Interface, defaultResync t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSharedInformerFactoryWithOptions constructs a new instance of metadataSharedInformerFactory with additional options.
|
||||||
|
func NewSharedInformerFactoryWithOptions(client metadata.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory {
|
||||||
|
factory := &metadataSharedInformerFactory{
|
||||||
|
client: client,
|
||||||
|
namespace: v1.NamespaceAll,
|
||||||
|
defaultResync: defaultResync,
|
||||||
|
informers: map[schema.GroupVersionResource]informers.GenericInformer{},
|
||||||
|
startedInformers: make(map[schema.GroupVersionResource]bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply all options
|
||||||
|
for _, opt := range options {
|
||||||
|
factory = opt(factory)
|
||||||
|
}
|
||||||
|
|
||||||
|
return factory
|
||||||
|
}
|
||||||
|
|
||||||
type metadataSharedInformerFactory struct {
|
type metadataSharedInformerFactory struct {
|
||||||
client metadata.Interface
|
client metadata.Interface
|
||||||
defaultResync time.Duration
|
defaultResync time.Duration
|
||||||
namespace string
|
namespace string
|
||||||
|
transform cache.TransformFunc
|
||||||
|
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
informers map[schema.GroupVersionResource]informers.GenericInformer
|
informers map[schema.GroupVersionResource]informers.GenericInformer
|
||||||
@@ -80,6 +111,7 @@ func (f *metadataSharedInformerFactory) ForResource(gvr schema.GroupVersionResou
|
|||||||
}
|
}
|
||||||
|
|
||||||
informer = NewFilteredMetadataInformer(f.client, gvr, f.namespace, f.defaultResync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
|
informer = NewFilteredMetadataInformer(f.client, gvr, f.namespace, f.defaultResync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
|
||||||
|
informer.Informer().SetTransform(f.transform)
|
||||||
f.informers[key] = informer
|
f.informers[key] = informer
|
||||||
|
|
||||||
return informer
|
return informer
|
||||||
|
Reference in New Issue
Block a user