Interface SharedInformer<ApiType extends KubernetesObject>
- Type Parameters:
ApiType
- kubernetes api type
- All Known Subinterfaces:
SharedIndexInformer<ApiType>
public interface SharedInformer<ApiType extends KubernetesObject>
Defines basic methods of an informer.
The code has been copied from the official client and modified: SharedInformer
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addEventHandler
(@NonNull ResourceEventHandler<ApiType> handler) Adds event handler.void
addEventHandlerWithResyncPeriod
(@NonNull ResourceEventHandler<ApiType> handler, long resyncPeriod) Adds an event handler to the shared informer using the specified resync period.boolean
Returns true if the shared informer's store has been synced after informer started.@Nullable String
Returns the last sync resource version.void
run()
Starts the shared informer, which won't be stopped until the stop method is called.void
setTransform
(@NonNull TransformFunc transformFunc) The TransformFunc is called for each object which is about to be stored.void
stop()
Stops the shared informer.
-
Method Details
-
addEventHandler
Adds event handler.- Parameters:
handler
- the handler
-
addEventHandlerWithResyncPeriod
void addEventHandlerWithResyncPeriod(@NonNull @NonNull ResourceEventHandler<ApiType> handler, long resyncPeriod) Adds an event handler to the shared informer using the specified resync period. Events to a single handler are delivered sequentially, but there is no coordination between different handlers.- Parameters:
handler
- the event handlerresyncPeriod
- the specific resync period
-
run
void run()Starts the shared informer, which won't be stopped until the stop method is called. -
stop
void stop()Stops the shared informer. -
hasSynced
boolean hasSynced()Returns true if the shared informer's store has been synced after informer started.- Returns:
- true if the shared informer's store has been synced after informer started
-
lastSyncResourceVersion
Returns the last sync resource version.The last sync resource version is the resource version observed when last synced with the underlying store. The value returned is not synchronized with access to the underlying store and is not thread-safe.
- Returns:
- the last sync resource version
-
setTransform
The TransformFunc is called for each object which is about to be stored. This function is intended for you to take the opportunity to remove, transform, or normalize fields. One use case is to strip unused metadata fields out of objects to save on RAM cost.Must be set before starting the informer.
Note: Since the object given to the handler may be already shared with other goroutines, it is advisable to copy the object being transform before mutating it at all and returning the copy to prevent data races.
- Parameters:
transformFunc
- the transform function
-