@@ -47,10 +47,10 @@ var (
4747// to receive events for Kubernetes objects (at a low-level),
4848// and add indices to fields on the objects stored in the cache.
4949type 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.
5151 client.Reader
5252
53- // Cache loads informers and adds field indices.
53+ // Informers loads informers and adds field indices.
5454 Informers
5555}
5656
@@ -70,39 +70,43 @@ type Informers interface {
7070 // It blocks.
7171 Start (ctx context.Context ) error
7272
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.
7474 WaitForCacheSync (ctx context.Context ) bool
7575
76- // Informers knows how to add indices to the caches ( informers) that it manages .
76+ // FieldIndexer adds indices to the managed informers.
7777 client.FieldIndexer
7878}
7979
80- // Informer - informer allows you interact with the underlying informer.
80+ // Informer allows you to interact with the underlying informer.
8181type Informer interface {
8282 // 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
8484 // between different handlers.
8585 // 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 .
8787 AddEventHandler (handler toolscache.ResourceEventHandler ) (toolscache.ResourceEventHandlerRegistration , error )
88+
8889 // 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
9091 // no coordination between different handlers.
9192 // It returns a registration handle for the handler that can be used to remove
9293 // the handler again and an error if the handler cannot be added.
9394 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
9597 // 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.
9799 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
99102 // in the store, the results are undefined.
100103 AddIndexers (indexers toolscache.Indexers ) error
104+
101105 // HasSynced return true if the informers underlying store has synced.
102106 HasSynced () bool
103107}
104108
105- // Options are the optional arguments for creating a new InformersMap object.
109+ // Options are the optional arguments for creating a new Cache object.
106110type Options struct {
107111 // HTTPClient is the http client to use for the REST client
108112 HTTPClient * http.Client
@@ -141,31 +145,31 @@ type Options struct {
141145 SyncPeriod * time.Duration
142146
143147 // Namespaces restricts the cache's ListWatch to the desired namespaces
144- // Default watches all namespaces
148+ // Per default ListWatch watches all namespaces
145149 Namespaces []string
146150
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
148152 // unless they have a more specific selector set in ByObject.
149153 DefaultLabelSelector labels.Selector
150154
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
152156 // unless they have a more specific selector set in ByObject.
153157 DefaultFieldSelector fields.Selector
154158
155159 // DefaultTransform will be used as transform for all object types
156160 // unless they have a more specific transform set in ByObject.
157161 DefaultTransform toolscache.TransformFunc
158162
159- // ByObject restricts the cache's ListWatch to the desired fields per GVK at the specified object.
160- ByObject map [client.Object ]ByObject
161-
162163 // UnsafeDisableDeepCopy indicates not to deep copy objects during get or
163164 // list objects for EVERY object.
164165 // Be very careful with this, when enabled you must DeepCopy any object before mutating it,
165166 // otherwise you will mutate the object in the cache.
166167 //
167168 // This is a global setting for all objects, and can be overridden by the ByObject setting.
168169 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
169173}
170174
171175// ByObject offers more fine-grained control over the cache's ListWatch by object.
@@ -176,9 +180,8 @@ type ByObject struct {
176180 // Field represents a field selector for the object.
177181 Field fields.Selector
178182
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.
182185 //
183186 // This function is called both for new objects to enter the cache,
184187 // and for updated objects.
@@ -236,15 +239,12 @@ func New(config *rest.Config, opts Options) (Cache, error) {
236239}
237240
238241func defaultOpts (config * rest.Config , opts Options ) (Options , error ) {
239- logger := log .WithName ("setup" )
240-
241242 // Use the rest HTTP client for the provided config if unset
242243 if opts .HTTPClient == nil {
243244 var err error
244245 opts .HTTPClient , err = rest .HTTPClientFor (config )
245246 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 )
248248 }
249249 }
250250
@@ -258,8 +258,7 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
258258 var err error
259259 opts .Mapper , err = apiutil .NewDiscoveryRESTMapper (config , opts .HTTPClient )
260260 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 )
263262 }
264263 }
265264
0 commit comments