...
1
16
17
18
19 package externalversions
20
21 import (
22 "fmt"
23
24 v1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
25 v1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
26 schema "k8s.io/apimachinery/pkg/runtime/schema"
27 cache "k8s.io/client-go/tools/cache"
28 )
29
30
31
32 type GenericInformer interface {
33 Informer() cache.SharedIndexInformer
34 Lister() cache.GenericLister
35 }
36
37 type genericInformer struct {
38 informer cache.SharedIndexInformer
39 resource schema.GroupResource
40 }
41
42
43 func (f *genericInformer) Informer() cache.SharedIndexInformer {
44 return f.informer
45 }
46
47
48 func (f *genericInformer) Lister() cache.GenericLister {
49 return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
50 }
51
52
53
54 func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
55 switch resource {
56
57 case v1.SchemeGroupVersion.WithResource("volumesnapshots"):
58 return &genericInformer{resource: resource.GroupResource(), informer: f.Snapshot().V1().VolumeSnapshots().Informer()}, nil
59 case v1.SchemeGroupVersion.WithResource("volumesnapshotclasses"):
60 return &genericInformer{resource: resource.GroupResource(), informer: f.Snapshot().V1().VolumeSnapshotClasses().Informer()}, nil
61 case v1.SchemeGroupVersion.WithResource("volumesnapshotcontents"):
62 return &genericInformer{resource: resource.GroupResource(), informer: f.Snapshot().V1().VolumeSnapshotContents().Informer()}, nil
63
64
65 case v1beta1.SchemeGroupVersion.WithResource("volumesnapshots"):
66 return &genericInformer{resource: resource.GroupResource(), informer: f.Snapshot().V1beta1().VolumeSnapshots().Informer()}, nil
67 case v1beta1.SchemeGroupVersion.WithResource("volumesnapshotclasses"):
68 return &genericInformer{resource: resource.GroupResource(), informer: f.Snapshot().V1beta1().VolumeSnapshotClasses().Informer()}, nil
69 case v1beta1.SchemeGroupVersion.WithResource("volumesnapshotcontents"):
70 return &genericInformer{resource: resource.GroupResource(), informer: f.Snapshot().V1beta1().VolumeSnapshotContents().Informer()}, nil
71
72 }
73
74 return nil, fmt.Errorf("no informer found for %v", resource)
75 }
76
View as plain text