k8c.io/api/v3@v3.0.0-20230904060738-b0a93889c0b6/pkg/generated/informers/externalversions/factory.go (about) 1 // Code generated by informer-gen. DO NOT EDIT. 2 3 package externalversions 4 5 import ( 6 reflect "reflect" 7 sync "sync" 8 time "time" 9 10 versioned "k8c.io/api/v3/pkg/generated/clientset/versioned" 11 appskubermatic "k8c.io/api/v3/pkg/generated/informers/externalversions/apps.kubermatic" 12 eeappskubermatic "k8c.io/api/v3/pkg/generated/informers/externalversions/ee.apps.kubermatic" 13 eekubermatic "k8c.io/api/v3/pkg/generated/informers/externalversions/ee.kubermatic" 14 internalinterfaces "k8c.io/api/v3/pkg/generated/informers/externalversions/internalinterfaces" 15 kubermatic "k8c.io/api/v3/pkg/generated/informers/externalversions/kubermatic" 16 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 17 runtime "k8s.io/apimachinery/pkg/runtime" 18 schema "k8s.io/apimachinery/pkg/runtime/schema" 19 cache "k8s.io/client-go/tools/cache" 20 ) 21 22 // SharedInformerOption defines the functional option type for SharedInformerFactory. 23 type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory 24 25 type sharedInformerFactory struct { 26 client versioned.Interface 27 namespace string 28 tweakListOptions internalinterfaces.TweakListOptionsFunc 29 lock sync.Mutex 30 defaultResync time.Duration 31 customResync map[reflect.Type]time.Duration 32 33 informers map[reflect.Type]cache.SharedIndexInformer 34 // startedInformers is used for tracking which informers have been started. 35 // This allows Start() to be called multiple times safely. 36 startedInformers map[reflect.Type]bool 37 // wg tracks how many goroutines were started. 38 wg sync.WaitGroup 39 // shuttingDown is true when Shutdown has been called. It may still be running 40 // because it needs to wait for goroutines. 41 shuttingDown bool 42 } 43 44 // WithCustomResyncConfig sets a custom resync period for the specified informer types. 45 func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { 46 return func(factory *sharedInformerFactory) *sharedInformerFactory { 47 for k, v := range resyncConfig { 48 factory.customResync[reflect.TypeOf(k)] = v 49 } 50 return factory 51 } 52 } 53 54 // WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. 55 func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { 56 return func(factory *sharedInformerFactory) *sharedInformerFactory { 57 factory.tweakListOptions = tweakListOptions 58 return factory 59 } 60 } 61 62 // WithNamespace limits the SharedInformerFactory to the specified namespace. 63 func WithNamespace(namespace string) SharedInformerOption { 64 return func(factory *sharedInformerFactory) *sharedInformerFactory { 65 factory.namespace = namespace 66 return factory 67 } 68 } 69 70 // NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. 71 func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { 72 return NewSharedInformerFactoryWithOptions(client, defaultResync) 73 } 74 75 // NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. 76 // Listers obtained via this SharedInformerFactory will be subject to the same filters 77 // as specified here. 78 // Deprecated: Please use NewSharedInformerFactoryWithOptions instead 79 func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { 80 return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) 81 } 82 83 // NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. 84 func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { 85 factory := &sharedInformerFactory{ 86 client: client, 87 namespace: v1.NamespaceAll, 88 defaultResync: defaultResync, 89 informers: make(map[reflect.Type]cache.SharedIndexInformer), 90 startedInformers: make(map[reflect.Type]bool), 91 customResync: make(map[reflect.Type]time.Duration), 92 } 93 94 // Apply all options 95 for _, opt := range options { 96 factory = opt(factory) 97 } 98 99 return factory 100 } 101 102 func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { 103 f.lock.Lock() 104 defer f.lock.Unlock() 105 106 if f.shuttingDown { 107 return 108 } 109 110 for informerType, informer := range f.informers { 111 if !f.startedInformers[informerType] { 112 f.wg.Add(1) 113 // We need a new variable in each loop iteration, 114 // otherwise the goroutine would use the loop variable 115 // and that keeps changing. 116 informer := informer 117 go func() { 118 defer f.wg.Done() 119 informer.Run(stopCh) 120 }() 121 f.startedInformers[informerType] = true 122 } 123 } 124 } 125 126 func (f *sharedInformerFactory) Shutdown() { 127 f.lock.Lock() 128 f.shuttingDown = true 129 f.lock.Unlock() 130 131 // Will return immediately if there is nothing to wait for. 132 f.wg.Wait() 133 } 134 135 func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { 136 informers := func() map[reflect.Type]cache.SharedIndexInformer { 137 f.lock.Lock() 138 defer f.lock.Unlock() 139 140 informers := map[reflect.Type]cache.SharedIndexInformer{} 141 for informerType, informer := range f.informers { 142 if f.startedInformers[informerType] { 143 informers[informerType] = informer 144 } 145 } 146 return informers 147 }() 148 149 res := map[reflect.Type]bool{} 150 for informType, informer := range informers { 151 res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) 152 } 153 return res 154 } 155 156 // InternalInformerFor returns the SharedIndexInformer for obj using an internal 157 // client. 158 func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { 159 f.lock.Lock() 160 defer f.lock.Unlock() 161 162 informerType := reflect.TypeOf(obj) 163 informer, exists := f.informers[informerType] 164 if exists { 165 return informer 166 } 167 168 resyncPeriod, exists := f.customResync[informerType] 169 if !exists { 170 resyncPeriod = f.defaultResync 171 } 172 173 informer = newFunc(f.client, resyncPeriod) 174 f.informers[informerType] = informer 175 176 return informer 177 } 178 179 // SharedInformerFactory provides shared informers for resources in all known 180 // API group versions. 181 // 182 // It is typically used like this: 183 // 184 // ctx, cancel := context.Background() 185 // defer cancel() 186 // factory := NewSharedInformerFactory(client, resyncPeriod) 187 // defer factory.WaitForStop() // Returns immediately if nothing was started. 188 // genericInformer := factory.ForResource(resource) 189 // typedInformer := factory.SomeAPIGroup().V1().SomeType() 190 // factory.Start(ctx.Done()) // Start processing these informers. 191 // synced := factory.WaitForCacheSync(ctx.Done()) 192 // for v, ok := range synced { 193 // if !ok { 194 // fmt.Fprintf(os.Stderr, "caches failed to sync: %v", v) 195 // return 196 // } 197 // } 198 // 199 // // Creating informers can also be created after Start, but then 200 // // Start must be called again: 201 // anotherGenericInformer := factory.ForResource(resource) 202 // factory.Start(ctx.Done()) 203 type SharedInformerFactory interface { 204 internalinterfaces.SharedInformerFactory 205 206 // Start initializes all requested informers. They are handled in goroutines 207 // which run until the stop channel gets closed. 208 Start(stopCh <-chan struct{}) 209 210 // Shutdown marks a factory as shutting down. At that point no new 211 // informers can be started anymore and Start will return without 212 // doing anything. 213 // 214 // In addition, Shutdown blocks until all goroutines have terminated. For that 215 // to happen, the close channel(s) that they were started with must be closed, 216 // either before Shutdown gets called or while it is waiting. 217 // 218 // Shutdown may be called multiple times, even concurrently. All such calls will 219 // block until all goroutines have terminated. 220 Shutdown() 221 222 // WaitForCacheSync blocks until all started informers' caches were synced 223 // or the stop channel gets closed. 224 WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool 225 226 // ForResource gives generic access to a shared informer of the matching type. 227 ForResource(resource schema.GroupVersionResource) (GenericInformer, error) 228 229 // InternalInformerFor returns the SharedIndexInformer for obj using an internal 230 // client. 231 InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer 232 233 KubermaticApps() appskubermatic.Interface 234 KubermaticEnterpriseApps() eeappskubermatic.Interface 235 KubermaticEnterprise() eekubermatic.Interface 236 Kubermatic() kubermatic.Interface 237 } 238 239 func (f *sharedInformerFactory) KubermaticApps() appskubermatic.Interface { 240 return appskubermatic.New(f, f.namespace, f.tweakListOptions) 241 } 242 243 func (f *sharedInformerFactory) KubermaticEnterpriseApps() eeappskubermatic.Interface { 244 return eeappskubermatic.New(f, f.namespace, f.tweakListOptions) 245 } 246 247 func (f *sharedInformerFactory) KubermaticEnterprise() eekubermatic.Interface { 248 return eekubermatic.New(f, f.namespace, f.tweakListOptions) 249 } 250 251 func (f *sharedInformerFactory) Kubermatic() kubermatic.Interface { 252 return kubermatic.New(f, f.namespace, f.tweakListOptions) 253 }