1/* 2Copyright The Kubernetes Authors. 3 4Licensed under the Apache License, Version 2.0 (the "License"); 5you may not use this file except in compliance with the License. 6You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10Unless required by applicable law or agreed to in writing, software 11distributed under the License is distributed on an "AS IS" BASIS, 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13See the License for the specific language governing permissions and 14limitations under the License. 15*/ 16 17// Code generated by informer-gen. DO NOT EDIT. 18 19package externalversions 20 21import ( 22 reflect "reflect" 23 sync "sync" 24 time "time" 25 26 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 runtime "k8s.io/apimachinery/pkg/runtime" 28 schema "k8s.io/apimachinery/pkg/runtime/schema" 29 cache "k8s.io/client-go/tools/cache" 30 versioned "k8s.io/code-generator/examples/apiserver/clientset/versioned" 31 example "k8s.io/code-generator/examples/apiserver/informers/externalversions/example" 32 example2 "k8s.io/code-generator/examples/apiserver/informers/externalversions/example2" 33 example3io "k8s.io/code-generator/examples/apiserver/informers/externalversions/example3.io" 34 internalinterfaces "k8s.io/code-generator/examples/apiserver/informers/externalversions/internalinterfaces" 35) 36 37// SharedInformerOption defines the functional option type for SharedInformerFactory. 38type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory 39 40type sharedInformerFactory struct { 41 client versioned.Interface 42 namespace string 43 tweakListOptions internalinterfaces.TweakListOptionsFunc 44 lock sync.Mutex 45 defaultResync time.Duration 46 customResync map[reflect.Type]time.Duration 47 48 informers map[reflect.Type]cache.SharedIndexInformer 49 // startedInformers is used for tracking which informers have been started. 50 // This allows Start() to be called multiple times safely. 51 startedInformers map[reflect.Type]bool 52} 53 54// WithCustomResyncConfig sets a custom resync period for the specified informer types. 55func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { 56 return func(factory *sharedInformerFactory) *sharedInformerFactory { 57 for k, v := range resyncConfig { 58 factory.customResync[reflect.TypeOf(k)] = v 59 } 60 return factory 61 } 62} 63 64// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. 65func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { 66 return func(factory *sharedInformerFactory) *sharedInformerFactory { 67 factory.tweakListOptions = tweakListOptions 68 return factory 69 } 70} 71 72// WithNamespace limits the SharedInformerFactory to the specified namespace. 73func WithNamespace(namespace string) SharedInformerOption { 74 return func(factory *sharedInformerFactory) *sharedInformerFactory { 75 factory.namespace = namespace 76 return factory 77 } 78} 79 80// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. 81func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { 82 return NewSharedInformerFactoryWithOptions(client, defaultResync) 83} 84 85// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. 86// Listers obtained via this SharedInformerFactory will be subject to the same filters 87// as specified here. 88// Deprecated: Please use NewSharedInformerFactoryWithOptions instead 89func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { 90 return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) 91} 92 93// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. 94func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { 95 factory := &sharedInformerFactory{ 96 client: client, 97 namespace: v1.NamespaceAll, 98 defaultResync: defaultResync, 99 informers: make(map[reflect.Type]cache.SharedIndexInformer), 100 startedInformers: make(map[reflect.Type]bool), 101 customResync: make(map[reflect.Type]time.Duration), 102 } 103 104 // Apply all options 105 for _, opt := range options { 106 factory = opt(factory) 107 } 108 109 return factory 110} 111 112// Start initializes all requested informers. 113func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { 114 f.lock.Lock() 115 defer f.lock.Unlock() 116 117 for informerType, informer := range f.informers { 118 if !f.startedInformers[informerType] { 119 go informer.Run(stopCh) 120 f.startedInformers[informerType] = true 121 } 122 } 123} 124 125// WaitForCacheSync waits for all started informers' cache were synced. 126func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { 127 informers := func() map[reflect.Type]cache.SharedIndexInformer { 128 f.lock.Lock() 129 defer f.lock.Unlock() 130 131 informers := map[reflect.Type]cache.SharedIndexInformer{} 132 for informerType, informer := range f.informers { 133 if f.startedInformers[informerType] { 134 informers[informerType] = informer 135 } 136 } 137 return informers 138 }() 139 140 res := map[reflect.Type]bool{} 141 for informType, informer := range informers { 142 res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) 143 } 144 return res 145} 146 147// InternalInformerFor returns the SharedIndexInformer for obj using an internal 148// client. 149func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { 150 f.lock.Lock() 151 defer f.lock.Unlock() 152 153 informerType := reflect.TypeOf(obj) 154 informer, exists := f.informers[informerType] 155 if exists { 156 return informer 157 } 158 159 resyncPeriod, exists := f.customResync[informerType] 160 if !exists { 161 resyncPeriod = f.defaultResync 162 } 163 164 informer = newFunc(f.client, resyncPeriod) 165 f.informers[informerType] = informer 166 167 return informer 168} 169 170// SharedInformerFactory provides shared informers for resources in all known 171// API group versions. 172type SharedInformerFactory interface { 173 internalinterfaces.SharedInformerFactory 174 ForResource(resource schema.GroupVersionResource) (GenericInformer, error) 175 WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool 176 177 Example() example.Interface 178 SecondExample() example2.Interface 179 ThirdExample() example3io.Interface 180} 181 182func (f *sharedInformerFactory) Example() example.Interface { 183 return example.New(f, f.namespace, f.tweakListOptions) 184} 185 186func (f *sharedInformerFactory) SecondExample() example2.Interface { 187 return example2.New(f, f.namespace, f.tweakListOptions) 188} 189 190func (f *sharedInformerFactory) ThirdExample() example3io.Interface { 191 return example3io.New(f, f.namespace, f.tweakListOptions) 192} 193