From 5e00c1be097aac36bd92d2dc19a1e9658575a4a9 Mon Sep 17 00:00:00 2001 From: James Munnelly Date: Wed, 1 Nov 2017 14:32:22 +0000 Subject: [PATCH 1/2] run hack/update-codegen.sh Kubernetes-commit: 6a4b80fcabc5e950af997d97f447354b83fcdcc4 --- .../informers/externalversions/factory.go | 20 ++++++++++++---- .../internalinterfaces/factory_interfaces.go | 3 +++ .../samplecontroller/interface.go | 10 ++++---- .../samplecontroller/v1alpha1/foo.go | 23 +++++++++++++++---- .../samplecontroller/v1alpha1/interface.go | 10 ++++---- 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 50f8326f5..64cb97935 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -19,6 +19,7 @@ limitations under the License. package externalversions import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" @@ -31,9 +32,11 @@ import ( ) type sharedInformerFactory struct { - client versioned.Interface - lock sync.Mutex - defaultResync time.Duration + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration informers map[reflect.Type]cache.SharedIndexInformer // startedInformers is used for tracking which informers have been started. @@ -43,8 +46,17 @@ type sharedInformerFactory struct { // NewSharedInformerFactory constructs a new instance of sharedInformerFactory func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewFilteredSharedInformerFactory(client, defaultResync, v1.NamespaceAll, nil) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { return &sharedInformerFactory{ client: client, + namespace: namespace, + tweakListOptions: tweakListOptions, defaultResync: defaultResync, informers: make(map[reflect.Type]cache.SharedIndexInformer), startedInformers: make(map[reflect.Type]bool), @@ -114,5 +126,5 @@ type SharedInformerFactory interface { } func (f *sharedInformerFactory) Samplecontroller() samplecontroller.Interface { - return samplecontroller.New(f) + return samplecontroller.New(f, f.namespace, f.tweakListOptions) } diff --git a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go index e246b3f5c..294c902a3 100644 --- a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -19,6 +19,7 @@ limitations under the License. package internalinterfaces import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" cache "k8s.io/client-go/tools/cache" versioned "k8s.io/sample-controller/pkg/client/clientset/versioned" @@ -32,3 +33,5 @@ type SharedInformerFactory interface { Start(stopCh <-chan struct{}) InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer } + +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/client/informers/externalversions/samplecontroller/interface.go b/pkg/client/informers/externalversions/samplecontroller/interface.go index a9d41a3e7..e5e7d464a 100644 --- a/pkg/client/informers/externalversions/samplecontroller/interface.go +++ b/pkg/client/informers/externalversions/samplecontroller/interface.go @@ -30,15 +30,17 @@ type Interface interface { } type group struct { - internalinterfaces.SharedInformerFactory + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc } // New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory) Interface { - return &group{f} +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } // V1alpha1 returns a new v1alpha1.Interface. func (g *group) V1alpha1() v1alpha1.Interface { - return v1alpha1.New(g.SharedInformerFactory) + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) } diff --git a/pkg/client/informers/externalversions/samplecontroller/v1alpha1/foo.go b/pkg/client/informers/externalversions/samplecontroller/v1alpha1/foo.go index 97207c879..90bd8ff4a 100644 --- a/pkg/client/informers/externalversions/samplecontroller/v1alpha1/foo.go +++ b/pkg/client/informers/externalversions/samplecontroller/v1alpha1/foo.go @@ -38,19 +38,34 @@ type FooInformer interface { } type fooInformer struct { - factory internalinterfaces.SharedInformerFactory + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string } // NewFooInformer constructs a new informer for Foo type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. func NewFooInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredFooInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredFooInformer constructs a new informer for Foo type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredFooInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } return client.SamplecontrollerV1alpha1().Foos(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } return client.SamplecontrollerV1alpha1().Foos(namespace).Watch(options) }, }, @@ -60,12 +75,12 @@ func NewFooInformer(client versioned.Interface, namespace string, resyncPeriod t ) } -func defaultFooInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFooInformer(client, v1.NamespaceAll, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}) +func (f *fooInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredFooInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) } func (f *fooInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&samplecontroller_v1alpha1.Foo{}, defaultFooInformer) + return f.factory.InformerFor(&samplecontroller_v1alpha1.Foo{}, f.defaultInformer) } func (f *fooInformer) Lister() v1alpha1.FooLister { diff --git a/pkg/client/informers/externalversions/samplecontroller/v1alpha1/interface.go b/pkg/client/informers/externalversions/samplecontroller/v1alpha1/interface.go index 1d159b5df..cea72010a 100644 --- a/pkg/client/informers/externalversions/samplecontroller/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/samplecontroller/v1alpha1/interface.go @@ -29,15 +29,17 @@ type Interface interface { } type version struct { - internalinterfaces.SharedInformerFactory + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc } // New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory) Interface { - return &version{f} +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } // Foos returns a FooInformer. func (v *version) Foos() FooInformer { - return &fooInformer{factory: v.SharedInformerFactory} + return &fooInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } From f106efb4c322b66b28171f8ae747d14d7761456f Mon Sep 17 00:00:00 2001 From: James Munnelly Date: Wed, 1 Nov 2017 15:10:35 +0000 Subject: [PATCH 2/2] run hack/update-bazel.sh Kubernetes-commit: 9b1a1231dae9c720b3c0837e42e3c8f680868df1 --- pkg/client/informers/externalversions/BUILD | 1 + pkg/client/informers/externalversions/internalinterfaces/BUILD | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/client/informers/externalversions/BUILD b/pkg/client/informers/externalversions/BUILD index d87ae00e2..2fd617e38 100644 --- a/pkg/client/informers/externalversions/BUILD +++ b/pkg/client/informers/externalversions/BUILD @@ -9,6 +9,7 @@ go_library( importpath = "k8s.io/sample-controller/pkg/client/informers/externalversions", visibility = ["//visibility:public"], deps = [ + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/client-go/tools/cache:go_default_library", diff --git a/pkg/client/informers/externalversions/internalinterfaces/BUILD b/pkg/client/informers/externalversions/internalinterfaces/BUILD index 41b1ecae7..e923a07f9 100644 --- a/pkg/client/informers/externalversions/internalinterfaces/BUILD +++ b/pkg/client/informers/externalversions/internalinterfaces/BUILD @@ -6,6 +6,7 @@ go_library( importpath = "k8s.io/sample-controller/pkg/client/informers/externalversions/internalinterfaces", visibility = ["//visibility:public"], deps = [ + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/client-go/tools/cache:go_default_library", "//vendor/k8s.io/sample-controller/pkg/client/clientset/versioned:go_default_library",