Skip to main content

KubernetesInformer

@webda/kubernetes


Class: KubernetesInformer<T>

Defined in: kubernetes/src/utils/informer.ts:115

Keep an up-to-date cache of custom resources: list them, then watch their changes

Unlike the informer of @kubernetes/client-node, it restarts by itself after an error (failed list, lost watch, missing permission...) with an exponential backoff, keeping the last known objects meanwhile.

Events:

  • add, update, delete, change (any of the three): an object changed
  • synced: a list succeeded, with all the objects
  • connect: the informer (re)connects
  • watching: a watch request is accepted, the cache follows the changes again
  • error: a list or a watch failed, the informer restarts

Type Parameters​

T​

T extends k8s.KubernetesObject = k8s.KubernetesObject

Constructors​

Constructor​

new KubernetesInformer<T>(params, resource, options?): KubernetesInformer<T>

Defined in: kubernetes/src/utils/informer.ts:144

Parameters​

params​

KubernetesParameters

the kubernetes parameters, timeout applies to the list requests (not to the watch)

resource​

KubernetesInformerResource

the custom resources to watch

options?​

KubernetesInformerOptions = {}

restart policy

Returns​

KubernetesInformer<T>

Properties​

currentRestartDelay​

protected currentRestartDelay: number

Defined in: kubernetes/src/utils/informer.ts:131


informer​

protected informer: ListWatch<T>

Defined in: kubernetes/src/utils/informer.ts:116


listeners​

protected listeners: Listeners<T>

Defined in: kubernetes/src/utils/informer.ts:119


maxRestartDelay​

protected maxRestartDelay: number

Defined in: kubernetes/src/utils/informer.ts:133


pendingSync?​

protected optional pendingSync?: T[]

Defined in: kubernetes/src/utils/informer.ts:118

objects of the last successful list, until the cache is updated with them


restartDelay​

protected restartDelay: number

Defined in: kubernetes/src/utils/informer.ts:132


restartTimer?​

protected optional restartTimer?: Timeout

Defined in: kubernetes/src/utils/informer.ts:130


stopped​

protected stopped: boolean = true

Defined in: kubernetes/src/utils/informer.ts:129


synced​

synced: boolean = false

Defined in: kubernetes/src/utils/informer.ts:137

Whether a list succeeded since the creation of the informer

Methods​

emit()​

protected emit(event, ...args): void

Defined in: kubernetes/src/utils/informer.ts:244

Call the listeners of an event

Parameters​

event​

ObjectEvent | "error" | "connect" | "synced" | "watching"

the event

args​

...any[]

the arguments of the listeners

Returns​

void


flushSync()​

protected flushSync(): void

Defined in: kubernetes/src/utils/informer.ts:253

After a successful list, once the cache is updated: reset the restart backoff and emit synced

Returns​

void


get()​

get(name, namespace?): T | undefined

Defined in: kubernetes/src/utils/informer.ts:235

Parameters​

name​

string

name of the object

namespace?​

string

namespace of the object, for namespaced resources

Returns​

T | undefined

the object, undefined when unknown


list()​

list(namespace?): readonly T[]

Defined in: kubernetes/src/utils/informer.ts:226

Parameters​

namespace?​

string

only the objects of this namespace

Returns​

readonly T[]

the known objects


off()​

off<K>(event, listener): this

Defined in: kubernetes/src/utils/informer.ts:198

Stop listening to an event

Type Parameters​

K​

K extends ObjectEvent | "error" | "connect" | "synced" | "watching"

Parameters​

event​

K

the event

listener​

Listeners<T>[K][number]

the listener given to on

Returns​

this

this


on()​

on<K>(event, listener): this

Defined in: kubernetes/src/utils/informer.ts:187

Listen to an event

Type Parameters​

K​

K extends ObjectEvent | "error" | "connect" | "synced" | "watching"

Parameters​

event​

K

the event

listener​

Listeners<T>[K][number]

called with the object, the error or the objects depending on the event

Returns​

this

this


onError()​

protected onError(err): void

Defined in: kubernetes/src/utils/informer.ts:268

A list or a watch failed: emit the error and restart after the backoff delay, unless stopped

Parameters​

err​

any

the error

Returns​

void


start()​

start(): Promise<void>

Defined in: kubernetes/src/utils/informer.ts:207

Start listing and watching

Returns​

Promise<void>

once the first list is done, successful or not (check synced)


stop()​

stop(): Promise<void>

Defined in: kubernetes/src/utils/informer.ts:215

Stop watching, the cache keeps the last known objects

Returns​

Promise<void>