-
Notifications
You must be signed in to change notification settings - Fork 209
/
core_getters.go
127 lines (107 loc) · 3.61 KB
/
core_getters.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package v1helpers
import (
"context"
"fmt"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
corev1listers "k8s.io/client-go/listers/core/v1"
)
var (
emptyGetOptions = metav1.GetOptions{}
emptyListOptions = metav1.ListOptions{}
)
type combinedConfigMapGetter struct {
client corev1client.ConfigMapsGetter
listers KubeInformersForNamespaces
}
func CachedConfigMapGetter(client corev1client.ConfigMapsGetter, listers KubeInformersForNamespaces) corev1client.ConfigMapsGetter {
return &combinedConfigMapGetter{
client: client,
listers: listers,
}
}
type combinedConfigMapInterface struct {
corev1client.ConfigMapInterface
lister corev1listers.ConfigMapNamespaceLister
namespace string
}
func (g combinedConfigMapGetter) ConfigMaps(namespace string) corev1client.ConfigMapInterface {
return combinedConfigMapInterface{
ConfigMapInterface: g.client.ConfigMaps(namespace),
lister: g.listers.InformersFor(namespace).Core().V1().ConfigMaps().Lister().ConfigMaps(namespace),
namespace: namespace,
}
}
func (g combinedConfigMapInterface) Get(_ context.Context, name string, options metav1.GetOptions) (*corev1.ConfigMap, error) {
if !equality.Semantic.DeepEqual(options, emptyGetOptions) {
return nil, fmt.Errorf("GetOptions are not honored by cached client: %#v", options)
}
ret, err := g.lister.Get(name)
if err != nil {
return nil, err
}
return ret.DeepCopy(), nil
}
func (g combinedConfigMapInterface) List(_ context.Context, options metav1.ListOptions) (*corev1.ConfigMapList, error) {
if !equality.Semantic.DeepEqual(options, emptyListOptions) {
return nil, fmt.Errorf("ListOptions are not honored by cached client: %#v", options)
}
list, err := g.lister.List(labels.Everything())
if err != nil {
return nil, err
}
ret := &corev1.ConfigMapList{}
for i := range list {
ret.Items = append(ret.Items, *(list[i].DeepCopy()))
}
return ret, nil
}
type combinedSecretGetter struct {
client corev1client.SecretsGetter
listers KubeInformersForNamespaces
}
func CachedSecretGetter(client corev1client.SecretsGetter, listers KubeInformersForNamespaces) corev1client.SecretsGetter {
return &combinedSecretGetter{
client: client,
listers: listers,
}
}
type combinedSecretInterface struct {
corev1client.SecretInterface
lister corev1listers.SecretNamespaceLister
namespace string
}
func (g combinedSecretGetter) Secrets(namespace string) corev1client.SecretInterface {
return combinedSecretInterface{
SecretInterface: g.client.Secrets(namespace),
lister: g.listers.InformersFor(namespace).Core().V1().Secrets().Lister().Secrets(namespace),
namespace: namespace,
}
}
func (g combinedSecretInterface) Get(_ context.Context, name string, options metav1.GetOptions) (*corev1.Secret, error) {
if !equality.Semantic.DeepEqual(options, emptyGetOptions) {
return nil, fmt.Errorf("GetOptions are not honored by cached client: %#v", options)
}
ret, err := g.lister.Get(name)
if err != nil {
return nil, err
}
return ret.DeepCopy(), nil
}
func (g combinedSecretInterface) List(_ context.Context, options metav1.ListOptions) (*corev1.SecretList, error) {
if !equality.Semantic.DeepEqual(options, emptyListOptions) {
return nil, fmt.Errorf("ListOptions are not honored by cached client: %#v", options)
}
list, err := g.lister.List(labels.Everything())
if err != nil {
return nil, err
}
ret := &corev1.SecretList{}
for i := range list {
ret.Items = append(ret.Items, *(list[i].DeepCopy()))
}
return ret, nil
}