@@ -47,10 +47,10 @@ var (
47
47
// to receive events for Kubernetes objects (at a low-level),
48
48
// and add indices to fields on the objects stored in the cache.
49
49
type Cache interface {
50
- // Cache acts as a client to objects stored in the cache.
50
+ // Reader acts as a client to objects stored in the cache.
51
51
client.Reader
52
52
53
- // Cache loads informers and adds field indices.
53
+ // Informers loads informers and adds field indices.
54
54
Informers
55
55
}
56
56
@@ -70,39 +70,43 @@ type Informers interface {
70
70
// It blocks.
71
71
Start (ctx context.Context ) error
72
72
73
- // WaitForCacheSync waits for all the caches to sync. Returns false if it could not sync a cache.
73
+ // WaitForCacheSync waits for all the caches to sync. Returns false if it could not sync a cache.
74
74
WaitForCacheSync (ctx context.Context ) bool
75
75
76
- // Informers knows how to add indices to the caches ( informers) that it manages .
76
+ // FieldIndexer adds indices to the managed informers.
77
77
client.FieldIndexer
78
78
}
79
79
80
- // Informer - informer allows you interact with the underlying informer.
80
+ // Informer allows you to interact with the underlying informer.
81
81
type Informer interface {
82
82
// AddEventHandler adds an event handler to the shared informer using the shared informer's resync
83
- // period. Events to a single handler are delivered sequentially, but there is no coordination
83
+ // period. Events to a single handler are delivered sequentially, but there is no coordination
84
84
// between different handlers.
85
85
// It returns a registration handle for the handler that can be used to remove
86
- // the handler again.
86
+ // the handler again and an error if the handler cannot be added .
87
87
AddEventHandler (handler toolscache.ResourceEventHandler ) (toolscache.ResourceEventHandlerRegistration , error )
88
+
88
89
// AddEventHandlerWithResyncPeriod adds an event handler to the shared informer using the
89
- // specified resync period. Events to a single handler are delivered sequentially, but there is
90
+ // specified resync period. Events to a single handler are delivered sequentially, but there is
90
91
// no coordination between different handlers.
91
92
// It returns a registration handle for the handler that can be used to remove
92
93
// the handler again and an error if the handler cannot be added.
93
94
AddEventHandlerWithResyncPeriod (handler toolscache.ResourceEventHandler , resyncPeriod time.Duration ) (toolscache.ResourceEventHandlerRegistration , error )
94
- // RemoveEventHandler removes a formerly added event handler given by
95
+
96
+ // RemoveEventHandler removes a previously added event handler given by
95
97
// its registration handle.
96
- // This function is guaranteed to be idempotent, and thread-safe.
98
+ // This function is guaranteed to be idempotent and thread-safe.
97
99
RemoveEventHandler (handle toolscache.ResourceEventHandlerRegistration ) error
98
- // AddIndexers adds more indexers to this store. If you call this after you already have data
100
+
101
+ // AddIndexers adds indexers to this store. If this is called after there is already data
99
102
// in the store, the results are undefined.
100
103
AddIndexers (indexers toolscache.Indexers ) error
104
+
101
105
// HasSynced return true if the informers underlying store has synced.
102
106
HasSynced () bool
103
107
}
104
108
105
- // Options are the optional arguments for creating a new InformersMap object.
109
+ // Options are the optional arguments for creating a new Cache object.
106
110
type Options struct {
107
111
// HTTPClient is the http client to use for the REST client
108
112
HTTPClient * http.Client
@@ -141,31 +145,31 @@ type Options struct {
141
145
SyncPeriod * time.Duration
142
146
143
147
// Namespaces restricts the cache's ListWatch to the desired namespaces
144
- // Default watches all namespaces
148
+ // Per default ListWatch watches all namespaces
145
149
Namespaces []string
146
150
147
- // DefaultLabelSelector will be used as a label selectors for all object types
151
+ // DefaultLabelSelector will be used as a label selector for all object types
148
152
// unless they have a more specific selector set in ByObject.
149
153
DefaultLabelSelector labels.Selector
150
154
151
- // DefaultFieldSelector will be used as a field selectors for all object types
155
+ // DefaultFieldSelector will be used as a field selector for all object types
152
156
// unless they have a more specific selector set in ByObject.
153
157
DefaultFieldSelector fields.Selector
154
158
155
159
// DefaultTransform will be used as transform for all object types
156
160
// unless they have a more specific transform set in ByObject.
157
161
DefaultTransform toolscache.TransformFunc
158
162
159
- // ByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
160
- ByObject map [client.Object ]ByObject
161
-
162
163
// UnsafeDisableDeepCopy indicates not to deep copy objects during get or
163
164
// list objects for EVERY object.
164
165
// Be very careful with this, when enabled you must DeepCopy any object before mutating it,
165
166
// otherwise you will mutate the object in the cache.
166
167
//
167
168
// This is a global setting for all objects, and can be overridden by the ByObject setting.
168
169
UnsafeDisableDeepCopy * bool
170
+
171
+ // ByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
172
+ ByObject map [client.Object ]ByObject
169
173
}
170
174
171
175
// ByObject offers more fine-grained control over the cache's ListWatch by object.
@@ -176,9 +180,8 @@ type ByObject struct {
176
180
// Field represents a field selector for the object.
177
181
Field fields.Selector
178
182
179
- // Transform is a map from objects to transformer functions which
180
- // get applied when objects of the transformation are about to be committed
181
- // to cache.
183
+ // Transform is a transformer function for the object which gets applied
184
+ // when objects of the transformation are about to be committed to the cache.
182
185
//
183
186
// This function is called both for new objects to enter the cache,
184
187
// and for updated objects.
@@ -236,15 +239,12 @@ func New(config *rest.Config, opts Options) (Cache, error) {
236
239
}
237
240
238
241
func defaultOpts (config * rest.Config , opts Options ) (Options , error ) {
239
- logger := log .WithName ("setup" )
240
-
241
242
// Use the rest HTTP client for the provided config if unset
242
243
if opts .HTTPClient == nil {
243
244
var err error
244
245
opts .HTTPClient , err = rest .HTTPClientFor (config )
245
246
if err != nil {
246
- logger .Error (err , "Failed to get HTTP client" )
247
- return opts , fmt .Errorf ("could not create HTTP client from config: %w" , err )
247
+ return Options {}, fmt .Errorf ("could not create HTTP client from config: %w" , err )
248
248
}
249
249
}
250
250
@@ -258,8 +258,7 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
258
258
var err error
259
259
opts .Mapper , err = apiutil .NewDiscoveryRESTMapper (config , opts .HTTPClient )
260
260
if err != nil {
261
- logger .Error (err , "Failed to get API Group-Resources" )
262
- return opts , fmt .Errorf ("could not create RESTMapper from config: %w" , err )
261
+ return Options {}, fmt .Errorf ("could not create RESTMapper from config: %w" , err )
263
262
}
264
263
}
265
264
0 commit comments