kubernetes-fluent-client 1.10.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,5 +8,5 @@ import { Filters, K8sInit } from "./types";
8
8
  * @param filters - (optional) filter overrides, can also be chained
9
9
  * @returns a fluent API for the model
10
10
  */
11
- export declare function K8s<T extends GenericClass, K extends KubernetesObject = InstanceType<T>>(model: T, filters?: Filters): K8sInit<K>;
11
+ export declare function K8s<T extends GenericClass, K extends KubernetesObject = InstanceType<T>>(model: T, filters?: Filters): K8sInit<T, K>;
12
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fluent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAsB,MAAM,SAAS,CAAC;AAI/D;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,EACtF,KAAK,EAAE,CAAC,EACR,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,CAAC,CAAC,CAmKZ"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fluent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAsB,MAAM,SAAS,CAAC;AAI/D;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,EACtF,KAAK,EAAE,CAAC,EACR,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAmKf"}
@@ -135,8 +135,8 @@ function K8s(model, filters = {}) {
135
135
  * @inheritdoc
136
136
  * @see {@link K8sInit.Watch}
137
137
  */
138
- async function Watch(callback, watchCfg) {
139
- return (0, watch_1.ExecWatch)(model, filters, callback, watchCfg);
138
+ function Watch(callback, watchCfg) {
139
+ return new watch_1.Watcher(model, filters, callback, watchCfg);
140
140
  }
141
141
  /**
142
142
  * @inheritdoc
@@ -2,15 +2,17 @@ import { KubernetesListObject, KubernetesObject } from "@kubernetes/client-node"
2
2
  import { Operation } from "fast-json-patch";
3
3
  import type { PartialDeep } from "type-fest";
4
4
  import { GenericClass, GroupVersionKind } from "../types";
5
- import { WatchCfg, WatchController } from "./watch";
6
5
  import { ApplyCfg } from "./apply";
6
+ import { WatchCfg, Watcher } from "./watch";
7
7
  /**
8
8
  * The Phase matched when using the K8s Watch API.
9
9
  */
10
10
  export declare enum WatchPhase {
11
11
  Added = "ADDED",
12
12
  Modified = "MODIFIED",
13
- Deleted = "DELETED"
13
+ Deleted = "DELETED",
14
+ Bookmark = "BOOKMARK",
15
+ Error = "ERROR"
14
16
  }
15
17
  export type FetchMethods = "GET" | "APPLY" | "POST" | "PUT" | "DELETE" | "PATCH" | "WATCH";
16
18
  export interface Filters {
@@ -32,7 +34,7 @@ export type GetFunction<K extends KubernetesObject> = {
32
34
  (): Promise<KubernetesListObject<K>>;
33
35
  (name: string): Promise<K>;
34
36
  };
35
- export type K8sFilteredActions<K extends KubernetesObject> = {
37
+ export type K8sFilteredActions<T extends GenericClass, K extends KubernetesObject> = {
36
38
  /**
37
39
  * Get the resource or resources matching the filters.
38
40
  * If no filters are specified, all resources will be returned.
@@ -52,7 +54,7 @@ export type K8sFilteredActions<K extends KubernetesObject> = {
52
54
  * @param watchCfg - (optional) watch configuration
53
55
  * @returns a watch controller
54
56
  */
55
- Watch: (callback: (payload: K, phase: WatchPhase) => void, watchCfg?: WatchCfg) => Promise<WatchController>;
57
+ Watch: (callback: WatchAction<T>, watchCfg?: WatchCfg) => Watcher<T>;
56
58
  };
57
59
  export type K8sUnfilteredActions<K extends KubernetesObject> = {
58
60
  /**
@@ -98,7 +100,7 @@ export type K8sUnfilteredActions<K extends KubernetesObject> = {
98
100
  */
99
101
  Raw: (url: string) => Promise<K>;
100
102
  };
101
- export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> & {
103
+ export type K8sWithFilters<T extends GenericClass, K extends KubernetesObject> = K8sFilteredActions<T, K> & {
102
104
  /**
103
105
  * Filter the query by the given field.
104
106
  * Note multiple calls to this method will result in an AND condition. e.g.
@@ -118,7 +120,7 @@ export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> &
118
120
  * @param value - the field value
119
121
  * @returns the fluent API
120
122
  */
121
- WithField: <P extends Paths<K>>(key: P, value: string) => K8sWithFilters<K>;
123
+ WithField: <P extends Paths<K>>(key: P, value: string) => K8sWithFilters<T, K>;
122
124
  /**
123
125
  * Filter the query by the given label. If no value is specified, the label simply must exist.
124
126
  * Note multiple calls to this method will result in an AND condition. e.g.
@@ -137,16 +139,16 @@ export type K8sWithFilters<K extends KubernetesObject> = K8sFilteredActions<K> &
137
139
  * @param value - the label value
138
140
  * @returns the fluent API
139
141
  */
140
- WithLabel: (key: string, value?: string) => K8sWithFilters<K>;
142
+ WithLabel: (key: string, value?: string) => K8sWithFilters<T, K>;
141
143
  };
142
- export type K8sInit<K extends KubernetesObject> = K8sWithFilters<K> & K8sUnfilteredActions<K> & {
144
+ export type K8sInit<T extends GenericClass, K extends KubernetesObject> = K8sWithFilters<T, K> & K8sUnfilteredActions<K> & {
143
145
  /**
144
146
  * Set the namespace filter.
145
147
  *
146
148
  * @param namespace - the namespace to filter on
147
149
  * @returns the fluent API
148
150
  */
149
- InNamespace: (namespace: string) => K8sWithFilters<K>;
151
+ InNamespace: (namespace: string) => K8sWithFilters<T, K>;
150
152
  };
151
153
  export type WatchAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (update: K, phase: WatchPhase) => Promise<void> | void;
152
154
  type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${"" extends P ? "" : "."}${P}` : never : never;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fluent/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;GAEG;AACH,oBAAY,UAAU;IACpB,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,OAAO,YAAY;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3F,MAAM,WAAW,OAAO;IACtB,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,gBAAgB,IAAI;IACpD,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC,IAAI,EAAE,MAAM,GA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AAE,CAAC"}
@@ -11,4 +11,6 @@ var WatchPhase;
11
11
  WatchPhase["Added"] = "ADDED";
12
12
  WatchPhase["Modified"] = "MODIFIED";
13
13
  WatchPhase["Deleted"] = "DELETED";
14
+ WatchPhase["Bookmark"] = "BOOKMARK";
15
+ WatchPhase["Error"] = "ERROR";
14
16
  })(WatchPhase || (exports.WatchPhase = WatchPhase = {}));
@@ -1,52 +1,83 @@
1
1
  /// <reference types="node" />
2
- import { GenericClass, LogFn } from "../types";
2
+ /// <reference types="node" />
3
+ import { EventEmitter } from "events";
4
+ import { GenericClass } from "../types";
3
5
  import { Filters, WatchAction } from "./types";
4
- /**
5
- * Wrapper for the AbortController to allow the watch to be aborted externally.
6
- */
7
- export type WatchController = {
6
+ export declare enum WatchEvent {
7
+ /** Watch is connected successfully */
8
+ CONNECT = "connect",
9
+ /** Network error occurs */
10
+ NETWORK_ERROR = "network_error",
11
+ /** Error decoding data or running the callback */
12
+ DATA_ERROR = "data_error",
13
+ /** Reconnect is called */
14
+ RECONNECT = "reconnect",
15
+ /** Retry limit is exceeded */
16
+ GIVE_UP = "give_up",
17
+ /** Abort is called */
18
+ ABORT = "abort",
19
+ /** Resync is called */
20
+ RESYNC = "resync",
21
+ /** Data is received and decoded */
22
+ DATA = "data",
23
+ /** Bookmark is received */
24
+ BOOKMARK = "bookmark",
25
+ /** ResourceVersion is updated */
26
+ RESOURCE_VERSION = "resource_version",
27
+ /** 410 (old resource version) occurs */
28
+ OLD_RESOURCE_VERSION = "old_resource_version",
29
+ /** A reconnect is already pending */
30
+ RECONNECT_PENDING = "reconnect_pending"
31
+ }
32
+ /** Configuration for the watch function. */
33
+ export type WatchCfg = {
34
+ /** The resource version to start the watch at, this will be updated on each event. */
35
+ resourceVersion?: string;
36
+ /** The maximum number of times to retry the watch, the retry count is reset on success. Unlimited retries if not specified. */
37
+ retryMax?: number;
38
+ /** The delay between retries in seconds. Defaults to 10 seconds. */
39
+ retryDelaySec?: number;
40
+ /** Amount of seconds to wait before a forced-resyncing of the watch list. Defaults to 300 (5 minutes). */
41
+ resyncIntervalSec?: number;
42
+ };
43
+ /** A wrapper around the Kubernetes watch API. */
44
+ export declare class Watcher<T extends GenericClass> {
45
+ #private;
8
46
  /**
9
- * Abort the watch.
47
+ * Setup a Kubernetes watcher for the specified model and filters. The callback function will be called for each event received.
48
+ * The watch can be aborted by calling {@link Watcher.close} or by calling abort() on the AbortController returned by {@link Watcher.start}.
10
49
  *
11
- * @param reason optional reason for aborting the watch
12
- */
13
- abort: (reason?: string) => void;
14
- /**
15
- * Get the AbortSignal for the watch.
16
50
  *
17
- * @returns the AbortSignal
18
- */
19
- signal: () => AbortSignal;
20
- };
21
- /**
22
- * Configuration for the watch function.
23
- */
24
- export type WatchCfg = {
25
- /**
26
- * The maximum number of times to retry the watch, the retry count is reset on success.
51
+ * Kubernetes API docs: {@link https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes}
52
+ *
53
+ * @param model - the model to use for the API
54
+ * @param filters - (optional) filter overrides, can also be chained
55
+ * @param callback - the callback function to call when an event is received
56
+ * @param watchCfg - (optional) watch configuration
27
57
  */
28
- retryMax?: number;
58
+ constructor(model: T, filters: Filters, callback: WatchAction<T>, watchCfg?: WatchCfg);
29
59
  /**
30
- * The delay between retries in seconds.
60
+ * Start the watch.
61
+ *
62
+ * @returns The AbortController for the watch.
31
63
  */
32
- retryDelaySec?: number;
64
+ start(): Promise<AbortController>;
65
+ /** Close the watch. Also available on the AbortController returned by {@link Watcher.start}. */
66
+ close(): void;
33
67
  /**
34
- * A function to log errors.
68
+ * Get a unique ID for the watch based on the model and filters.
69
+ * This is useful for caching the watch data or resource versions.
70
+ *
71
+ * @returns the watch ID
35
72
  */
36
- logFn?: LogFn;
73
+ get id(): string;
37
74
  /**
38
- * A function to call when the watch fails after the maximum number of retries.
75
+ * Subscribe to watch events. This is an EventEmitter that emits the following events:
76
+ *
77
+ * Use {@link WatchEvent} for the event names.
78
+ *
79
+ * @returns an EventEmitter
39
80
  */
40
- retryFail?: (e: Error) => void;
41
- };
42
- /**
43
- * Execute a watch on the specified resource.
44
- *
45
- * @param model - the model to use for the API
46
- * @param filters - (optional) filter overrides, can also be chained
47
- * @param callback - the callback function to call when an event is received
48
- * @param watchCfg - (optional) watch configuration
49
- * @returns a WatchController to allow the watch to be aborted externally
50
- */
51
- export declare function ExecWatch<T extends GenericClass>(model: T, filters: Filters, callback: WatchAction<T>, watchCfg?: WatchCfg): Promise<WatchController>;
81
+ get events(): EventEmitter;
82
+ }
52
83
  //# sourceMappingURL=watch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/fluent/watch.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,SAAS,CAAC;AAG3D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;OAIG;IACH,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC;;;;OAIG;IACH,MAAM,EAAE,MAAM,WAAW,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IACd;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;CAChC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,CAAC,SAAS,YAAY,EACpD,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,EACxB,QAAQ,GAAE,QAAa,4BAmKxB"}
1
+ {"version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