github.com/imran-kn/cilium-fork@v1.6.9/pkg/k8s/client/informers/externalversions/generic.go (about) 1 // Copyright 2017-2019 Authors of Cilium 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 v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2" 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=cilium.io, Version=v2 54 case v2.SchemeGroupVersion.WithResource("ciliumendpoints"): 55 return &genericInformer{resource: resource.GroupResource(), informer: f.Cilium().V2().CiliumEndpoints().Informer()}, nil 56 case v2.SchemeGroupVersion.WithResource("ciliumidentities"): 57 return &genericInformer{resource: resource.GroupResource(), informer: f.Cilium().V2().CiliumIdentities().Informer()}, nil 58 case v2.SchemeGroupVersion.WithResource("ciliumnetworkpolicies"): 59 return &genericInformer{resource: resource.GroupResource(), informer: f.Cilium().V2().CiliumNetworkPolicies().Informer()}, nil 60 case v2.SchemeGroupVersion.WithResource("ciliumnodes"): 61 return &genericInformer{resource: resource.GroupResource(), informer: f.Cilium().V2().CiliumNodes().Informer()}, nil 62 63 } 64 65 return nil, fmt.Errorf("no informer found for %v", resource) 66 }