github.com/GoogleContainerTools/kpt/porch/api@v0.0.0-20240427025202-5cbd3cbd9237/generated/informers/externalversions/generic.go (about) 1 // Copyright 2023 The kpt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Code generated by informer-gen. DO NOT EDIT. 16 17 package externalversions 18 19 import ( 20 "fmt" 21 22 v1alpha1 "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1" 23 schema "k8s.io/apimachinery/pkg/runtime/schema" 24 cache "k8s.io/client-go/tools/cache" 25 ) 26 27 // GenericInformer is type of SharedIndexInformer which will locate and delegate to other 28 // sharedInformers based on type 29 type GenericInformer interface { 30 Informer() cache.SharedIndexInformer 31 Lister() cache.GenericLister 32 } 33 34 type genericInformer struct { 35 informer cache.SharedIndexInformer 36 resource schema.GroupResource 37 } 38 39 // Informer returns the SharedIndexInformer. 40 func (f *genericInformer) Informer() cache.SharedIndexInformer { 41 return f.informer 42 } 43 44 // Lister returns the GenericLister. 45 func (f *genericInformer) Lister() cache.GenericLister { 46 return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) 47 } 48 49 // ForResource gives generic access to a shared informer of the matching type 50 // TODO extend this to unknown resources with a client pool 51 func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { 52 switch resource { 53 // Group=porch.kpt.dev, Version=v1alpha1 54 case v1alpha1.SchemeGroupVersion.WithResource("functions"): 55 return &genericInformer{resource: resource.GroupResource(), informer: f.Porch().V1alpha1().Functions().Informer()}, nil 56 case v1alpha1.SchemeGroupVersion.WithResource("packages"): 57 return &genericInformer{resource: resource.GroupResource(), informer: f.Porch().V1alpha1().Packages().Informer()}, nil 58 case v1alpha1.SchemeGroupVersion.WithResource("packagerevisions"): 59 return &genericInformer{resource: resource.GroupResource(), informer: f.Porch().V1alpha1().PackageRevisions().Informer()}, nil 60 case v1alpha1.SchemeGroupVersion.WithResource("packagerevisionresources"): 61 return &genericInformer{resource: resource.GroupResource(), informer: f.Porch().V1alpha1().PackageRevisionResources().Informer()}, nil 62 63 } 64 65 return nil, fmt.Errorf("no informer found for %v", resource) 66 }