38
38
_ Cache = & informerCache {}
39
39
)
40
40
41
+ // ErrCacheNotStarted is returned when trying to read from the cache that wasn't started.
42
+ type ErrCacheNotStarted struct {}
43
+
44
+ func (* ErrCacheNotStarted ) Error () string {
45
+ return "the cache is not started, can not read objects"
46
+ }
47
+
41
48
// informerCache is a Kubernetes Object cache populated from InformersMap. informerCache wraps an InformersMap.
42
49
type informerCache struct {
43
50
* internal.InformersMap
@@ -50,10 +57,14 @@ func (ip *informerCache) Get(ctx context.Context, key client.ObjectKey, out runt
50
57
return err
51
58
}
52
59
53
- cache , err := ip .InformersMap .Get (gvk , out )
60
+ started , cache , err := ip .InformersMap .Get (gvk , out )
54
61
if err != nil {
55
62
return err
56
63
}
64
+
65
+ if ! started {
66
+ return & ErrCacheNotStarted {}
67
+ }
57
68
return cache .Reader .Get (ctx , key , out )
58
69
}
59
70
@@ -90,11 +101,15 @@ func (ip *informerCache) List(ctx context.Context, out runtime.Object, opts ...c
90
101
}
91
102
}
92
103
93
- cache , err := ip .InformersMap .Get (gvk , cacheTypeObj )
104
+ started , cache , err := ip .InformersMap .Get (gvk , cacheTypeObj )
94
105
if err != nil {
95
106
return err
96
107
}
97
108
109
+ if ! started {
110
+ return & ErrCacheNotStarted {}
111
+ }
112
+
98
113
return cache .Reader .List (ctx , out , opts ... )
99
114
}
100
115
@@ -105,7 +120,7 @@ func (ip *informerCache) GetInformerForKind(gvk schema.GroupVersionKind) (Inform
105
120
if err != nil {
106
121
return nil , err
107
122
}
108
- i , err := ip .InformersMap .Get (gvk , obj )
123
+ _ , i , err := ip .InformersMap .Get (gvk , obj )
109
124
if err != nil {
110
125
return nil , err
111
126
}
@@ -118,7 +133,7 @@ func (ip *informerCache) GetInformer(obj runtime.Object) (Informer, error) {
118
133
if err != nil {
119
134
return nil , err
120
135
}
121
- i , err := ip .InformersMap .Get (gvk , obj )
136
+ _ , i , err := ip .InformersMap .Get (gvk , obj )
122
137
if err != nil {
123
138
return nil , err
124
139
}
0 commit comments