forked from gocrane/api
/
generic.go
87 lines (72 loc) · 4.67 KB
/
generic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Code generated by informer-gen. DO NOT EDIT.
package externalversions
import (
"fmt"
v1alpha1 "github.com/erikwoo/gocrane-api/analysis/v1alpha1"
autoscalingv1alpha1 "github.com/erikwoo/gocrane-api/autoscaling/v1alpha1"
co2ev1alpha1 "github.com/erikwoo/gocrane-api/co2e/v1alpha1"
ensurancev1alpha1 "github.com/erikwoo/gocrane-api/ensurance/v1alpha1"
predictionv1alpha1 "github.com/erikwoo/gocrane-api/prediction/v1alpha1"
topologyv1alpha1 "github.com/erikwoo/gocrane-api/topology/v1alpha1"
schema "k8s.io/apimachinery/pkg/runtime/schema"
cache "k8s.io/client-go/tools/cache"
)
// GenericInformer is type of SharedIndexInformer which will locate and delegate to other
// sharedInformers based on type
type GenericInformer interface {
Informer() cache.SharedIndexInformer
Lister() cache.GenericLister
}
type genericInformer struct {
informer cache.SharedIndexInformer
resource schema.GroupResource
}
// Informer returns the SharedIndexInformer.
func (f *genericInformer) Informer() cache.SharedIndexInformer {
return f.informer
}
// Lister returns the GenericLister.
func (f *genericInformer) Lister() cache.GenericLister {
return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
}
// ForResource gives generic access to a shared informer of the matching type
// TODO extend this to unknown resources with a client pool
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
switch resource {
// Group=analysis.crane.io, Version=v1alpha1
case v1alpha1.SchemeGroupVersion.WithResource("analytics"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Analysis().V1alpha1().Analytics().Informer()}, nil
case v1alpha1.SchemeGroupVersion.WithResource("configsets"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Analysis().V1alpha1().ConfigSets().Informer()}, nil
case v1alpha1.SchemeGroupVersion.WithResource("recommendations"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Analysis().V1alpha1().Recommendations().Informer()}, nil
case v1alpha1.SchemeGroupVersion.WithResource("recommendationrules"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Analysis().V1alpha1().RecommendationRules().Informer()}, nil
// Group=autoscaling.crane.io, Version=v1alpha1
case autoscalingv1alpha1.SchemeGroupVersion.WithResource("effectivehorizontalpodautoscalers"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Autoscaling().V1alpha1().EffectiveHorizontalPodAutoscalers().Informer()}, nil
case autoscalingv1alpha1.SchemeGroupVersion.WithResource("effectiveverticalpodautoscalers"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Autoscaling().V1alpha1().EffectiveVerticalPodAutoscalers().Informer()}, nil
case autoscalingv1alpha1.SchemeGroupVersion.WithResource("substitutes"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Autoscaling().V1alpha1().Substitutes().Informer()}, nil
// Group=co2e.crane.io, Version=v1alpha1
case co2ev1alpha1.SchemeGroupVersion.WithResource("cloudcarbonfootprints"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Co2e().V1alpha1().CloudCarbonFootprints().Informer()}, nil
// Group=ensurance.crane.io, Version=v1alpha1
case ensurancev1alpha1.SchemeGroupVersion.WithResource("avoidanceactions"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Ensurance().V1alpha1().AvoidanceActions().Informer()}, nil
case ensurancev1alpha1.SchemeGroupVersion.WithResource("nodeqoss"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Ensurance().V1alpha1().NodeQOSs().Informer()}, nil
case ensurancev1alpha1.SchemeGroupVersion.WithResource("podqoss"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Ensurance().V1alpha1().PodQOSs().Informer()}, nil
// Group=prediction.crane.io, Version=v1alpha1
case predictionv1alpha1.SchemeGroupVersion.WithResource("clusternodepredictions"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Prediction().V1alpha1().ClusterNodePredictions().Informer()}, nil
case predictionv1alpha1.SchemeGroupVersion.WithResource("timeseriespredictions"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Prediction().V1alpha1().TimeSeriesPredictions().Informer()}, nil
// Group=topology.crane.io, Version=v1alpha1
case topologyv1alpha1.SchemeGroupVersion.WithResource("noderesourcetopologies"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Topology().V1alpha1().NodeResourceTopologies().Informer()}, nil
}
return nil, fmt.Errorf("no informer found for %v", resource)
}