pepr 0.45.0-nightly.1 → 0.45.0-nightly.11
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.
- package/README.md +7 -7
- package/dist/cli.js +1 -1
- package/dist/controller.js +1 -1
- package/dist/lib/processors/watch-processor.d.ts +22 -1
- package/dist/lib/processors/watch-processor.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts +2 -3
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib.js +28 -28
- package/dist/lib.js.map +3 -3
- package/dist/sdk/sdk.d.ts +6 -1
- package/dist/sdk/sdk.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/lib/processors/watch-processor.ts +58 -33
- package/src/lib/telemetry/metrics.ts +3 -3
- package/src/sdk/sdk.ts +8 -4
package/dist/sdk/sdk.d.ts
CHANGED
|
@@ -19,7 +19,12 @@ export declare function containers(request: PeprValidateRequest<kind.Pod> | Pepr
|
|
|
19
19
|
* @param reportingComponent The component that is reporting the event, for example "uds.dev/operator"
|
|
20
20
|
* @param reportingInstance The instance of the component that is reporting the event, for example process.env.HOSTNAME
|
|
21
21
|
*/
|
|
22
|
-
export declare function writeEvent(cr: GenericKind, event: Partial<kind.CoreEvent>,
|
|
22
|
+
export declare function writeEvent(cr: GenericKind, event: Partial<kind.CoreEvent>, options: {
|
|
23
|
+
eventType: string;
|
|
24
|
+
eventReason: string;
|
|
25
|
+
reportingComponent: string;
|
|
26
|
+
reportingInstance: string;
|
|
27
|
+
}): Promise<void>;
|
|
23
28
|
/**
|
|
24
29
|
* Get the owner reference for a custom resource
|
|
25
30
|
* @param customResource the custom resource to get the owner reference for
|
package/dist/sdk/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk/sdk.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC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E,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;CAC3B,GACA,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,cAAc,EAAE,WAAW,EAC3B,kBAAkB,CAAC,EAAE,OAAO,EAC5B,UAAU,CAAC,EAAE,OAAO,GACnB,gBAAgB,EAAE,CAcpB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYzD"}
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"!src/**/*.test.ts",
|
|
16
16
|
"!dist/**/*.test.d.ts*"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.45.0-nightly.
|
|
18
|
+
"version": "0.45.0-nightly.11",
|
|
19
19
|
"main": "dist/lib.js",
|
|
20
20
|
"types": "dist/lib.d.ts",
|
|
21
21
|
"scripts": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "tsc && node build.mjs && npm pack",
|
|
26
26
|
"build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .",
|
|
27
27
|
"set:version": "node scripts/set-version.js",
|
|
28
|
-
"test": "npm run test:unit && npm run test:journey",
|
|
28
|
+
"test": "npm run test:unit && npm run test:journey && npm run test:journey-wasm",
|
|
29
29
|
"test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns='cosign.e2e.test.ts'",
|
|
30
30
|
"test:integration": "npm run test:integration:prep && npm run test:integration:run",
|
|
31
31
|
"test:integration:prep": "./integration/prep.sh",
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"follow-redirects": "1.15.9",
|
|
49
49
|
"http-status-codes": "^2.3.0",
|
|
50
50
|
"json-pointer": "^0.6.2",
|
|
51
|
-
"kubernetes-fluent-client": "3.
|
|
51
|
+
"kubernetes-fluent-client": "3.4.0",
|
|
52
52
|
"pino": "9.6.0",
|
|
53
53
|
"pino-pretty": "13.0.0",
|
|
54
54
|
"prom-client": "15.1.3",
|
|
55
55
|
"ramda": "0.30.1",
|
|
56
|
-
"sigstore": "3.
|
|
56
|
+
"sigstore": "3.1.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@commitlint/cli": "19.7.1",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"@typescript-eslint/eslint-plugin": "8.23.0",
|
|
84
84
|
"@typescript-eslint/parser": "8.23.0",
|
|
85
85
|
"commander": "13.1.0",
|
|
86
|
-
"esbuild": "0.
|
|
86
|
+
"esbuild": "0.25.0",
|
|
87
87
|
"eslint": "8.57.0",
|
|
88
88
|
"node-forge": "1.3.1",
|
|
89
89
|
"prettier": "3.4.2",
|
|
@@ -4,11 +4,12 @@ import Log from "../telemetry/logger";
|
|
|
4
4
|
import { Binding } from "../types";
|
|
5
5
|
import { Capability } from "../core/capability";
|
|
6
6
|
import { Event } from "../enums";
|
|
7
|
-
import { K8s, KubernetesObject, WatchCfg, WatchEvent } from "kubernetes-fluent-client";
|
|
7
|
+
import { K8s, KubernetesObject, WatchCfg, WatchEvent, GenericClass } from "kubernetes-fluent-client";
|
|
8
8
|
import { Queue } from "../core/queue";
|
|
9
|
-
import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";
|
|
9
|
+
import { WatchPhase, WatcherType } from "kubernetes-fluent-client/dist/fluent/types";
|
|
10
|
+
import { KubernetesListObject } from "kubernetes-fluent-client/dist/types";
|
|
10
11
|
import { filterNoMatchReason } from "../filter/filter";
|
|
11
|
-
import { metricsCollector } from "../telemetry/metrics";
|
|
12
|
+
import { metricsCollector, MetricsCollectorInstance } from "../telemetry/metrics";
|
|
12
13
|
import { removeFinalizer } from "../finalizer";
|
|
13
14
|
|
|
14
15
|
// stores Queue instances
|
|
@@ -157,36 +158,8 @@ async function runBinding(
|
|
|
157
158
|
}
|
|
158
159
|
}, watchCfg);
|
|
159
160
|
|
|
160
|
-
//
|
|
161
|
-
watcher
|
|
162
|
-
Log.error(err, "Watch failed after 5 attempts, giving up");
|
|
163
|
-
process.exit(1);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
watcher.events.on(WatchEvent.CONNECT, url => logEvent(WatchEvent.CONNECT, url));
|
|
167
|
-
|
|
168
|
-
watcher.events.on(WatchEvent.DATA_ERROR, err => logEvent(WatchEvent.DATA_ERROR, err.message));
|
|
169
|
-
watcher.events.on(WatchEvent.RECONNECT, retryCount =>
|
|
170
|
-
logEvent(WatchEvent.RECONNECT, `Reconnecting after ${retryCount} attempt${retryCount === 1 ? "" : "s"}`),
|
|
171
|
-
);
|
|
172
|
-
watcher.events.on(WatchEvent.RECONNECT_PENDING, () => logEvent(WatchEvent.RECONNECT_PENDING));
|
|
173
|
-
watcher.events.on(WatchEvent.GIVE_UP, err => logEvent(WatchEvent.GIVE_UP, err.message));
|
|
174
|
-
watcher.events.on(WatchEvent.ABORT, err => logEvent(WatchEvent.ABORT, err.message));
|
|
175
|
-
watcher.events.on(WatchEvent.OLD_RESOURCE_VERSION, err => logEvent(WatchEvent.OLD_RESOURCE_VERSION, err));
|
|
176
|
-
watcher.events.on(WatchEvent.NETWORK_ERROR, err => logEvent(WatchEvent.NETWORK_ERROR, err.message));
|
|
177
|
-
watcher.events.on(WatchEvent.LIST_ERROR, err => logEvent(WatchEvent.LIST_ERROR, err.message));
|
|
178
|
-
watcher.events.on(WatchEvent.LIST, list => logEvent(WatchEvent.LIST, JSON.stringify(list, undefined, 2)));
|
|
179
|
-
watcher.events.on(WatchEvent.CACHE_MISS, windowName => {
|
|
180
|
-
metricsCollector.incCacheMiss(windowName);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
watcher.events.on(WatchEvent.INIT_CACHE_MISS, windowName => {
|
|
184
|
-
metricsCollector.initCacheMissWindow(windowName);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
watcher.events.on(WatchEvent.INC_RESYNC_FAILURE_COUNT, retryCount => {
|
|
188
|
-
metricsCollector.incRetryCount(retryCount);
|
|
189
|
-
});
|
|
161
|
+
// Register event handlers
|
|
162
|
+
registerWatchEventHandlers(watcher, logEvent, metricsCollector);
|
|
190
163
|
|
|
191
164
|
// Start the watch
|
|
192
165
|
try {
|
|
@@ -205,3 +178,55 @@ export function logEvent(event: WatchEvent, message: string = "", obj?: Kubernet
|
|
|
205
178
|
Log.debug(logMessage);
|
|
206
179
|
}
|
|
207
180
|
}
|
|
181
|
+
|
|
182
|
+
export type WatchEventArgs<K extends WatchEvent, T extends GenericClass> = {
|
|
183
|
+
[WatchEvent.LIST]: KubernetesListObject<InstanceType<T>>;
|
|
184
|
+
[WatchEvent.RECONNECT]: number;
|
|
185
|
+
[WatchEvent.CACHE_MISS]: string;
|
|
186
|
+
[WatchEvent.INIT_CACHE_MISS]: string;
|
|
187
|
+
[WatchEvent.GIVE_UP]: Error;
|
|
188
|
+
[WatchEvent.ABORT]: Error;
|
|
189
|
+
[WatchEvent.OLD_RESOURCE_VERSION]: string;
|
|
190
|
+
[WatchEvent.NETWORK_ERROR]: Error;
|
|
191
|
+
[WatchEvent.LIST_ERROR]: Error;
|
|
192
|
+
[WatchEvent.DATA_ERROR]: Error;
|
|
193
|
+
[WatchEvent.CONNECT]: string;
|
|
194
|
+
[WatchEvent.RECONNECT_PENDING]: undefined;
|
|
195
|
+
[WatchEvent.DATA]: undefined;
|
|
196
|
+
[WatchEvent.INC_RESYNC_FAILURE_COUNT]: number;
|
|
197
|
+
}[K];
|
|
198
|
+
|
|
199
|
+
export type LogEventFunction = (event: WatchEvent, message?: string) => void;
|
|
200
|
+
export function registerWatchEventHandlers(
|
|
201
|
+
watcher: WatcherType<GenericClass>,
|
|
202
|
+
logEvent: LogEventFunction,
|
|
203
|
+
metricsCollector: MetricsCollectorInstance,
|
|
204
|
+
): void {
|
|
205
|
+
const eventHandlers: {
|
|
206
|
+
[K in WatchEvent]?: (arg: WatchEventArgs<K, GenericClass>) => void;
|
|
207
|
+
} = {
|
|
208
|
+
[WatchEvent.DATA]: () => null,
|
|
209
|
+
[WatchEvent.GIVE_UP]: err => {
|
|
210
|
+
// If failure continues, log and exit
|
|
211
|
+
logEvent(WatchEvent.GIVE_UP, err.message);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
},
|
|
214
|
+
[WatchEvent.CONNECT]: url => logEvent(WatchEvent.CONNECT, url),
|
|
215
|
+
[WatchEvent.DATA_ERROR]: err => logEvent(WatchEvent.DATA_ERROR, err.message),
|
|
216
|
+
[WatchEvent.RECONNECT]: retryCount =>
|
|
217
|
+
logEvent(WatchEvent.RECONNECT, `Reconnecting after ${retryCount} attempt${retryCount === 1 ? "" : "s"}`),
|
|
218
|
+
[WatchEvent.RECONNECT_PENDING]: () => logEvent(WatchEvent.RECONNECT_PENDING),
|
|
219
|
+
[WatchEvent.ABORT]: err => logEvent(WatchEvent.ABORT, err.message),
|
|
220
|
+
[WatchEvent.OLD_RESOURCE_VERSION]: errMessage => logEvent(WatchEvent.OLD_RESOURCE_VERSION, errMessage),
|
|
221
|
+
[WatchEvent.NETWORK_ERROR]: err => logEvent(WatchEvent.NETWORK_ERROR, err.message),
|
|
222
|
+
[WatchEvent.LIST_ERROR]: err => logEvent(WatchEvent.LIST_ERROR, err.message),
|
|
223
|
+
[WatchEvent.LIST]: list => logEvent(WatchEvent.LIST, JSON.stringify(list, undefined, 2)),
|
|
224
|
+
[WatchEvent.CACHE_MISS]: windowName => metricsCollector.incCacheMiss(windowName),
|
|
225
|
+
[WatchEvent.INIT_CACHE_MISS]: windowName => metricsCollector.initCacheMissWindow(windowName),
|
|
226
|
+
[WatchEvent.INC_RESYNC_FAILURE_COUNT]: retryCount => metricsCollector.incRetryCount(retryCount),
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
Object.entries(eventHandlers).forEach(([event, handler]) => {
|
|
230
|
+
watcher.events.on(event, handler);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
@@ -9,7 +9,7 @@ import Log from "./logger";
|
|
|
9
9
|
|
|
10
10
|
const loggingPrefix = "MetricsCollector";
|
|
11
11
|
|
|
12
|
-
type MetricsCollectorInstance = InstanceType<typeof MetricsCollector>;
|
|
12
|
+
export type MetricsCollectorInstance = InstanceType<typeof MetricsCollector>;
|
|
13
13
|
interface MetricNames {
|
|
14
14
|
errors: string;
|
|
15
15
|
alerts: string;
|
|
@@ -148,8 +148,8 @@ export class MetricsCollector {
|
|
|
148
148
|
* Increments the retry count gauge.
|
|
149
149
|
* @param count - The count to increment by.
|
|
150
150
|
*/
|
|
151
|
-
incRetryCount = (count:
|
|
152
|
-
this.incGauge(this.#metricNames.resyncFailureCount, { count });
|
|
151
|
+
incRetryCount = (count: number): void => {
|
|
152
|
+
this.incGauge(this.#metricNames.resyncFailureCount, { count: count.toString() });
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
/**
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -46,11 +46,15 @@ export function containers(
|
|
|
46
46
|
export async function writeEvent(
|
|
47
47
|
cr: GenericKind,
|
|
48
48
|
event: Partial<kind.CoreEvent>,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
options: {
|
|
50
|
+
eventType: string;
|
|
51
|
+
eventReason: string;
|
|
52
|
+
reportingComponent: string;
|
|
53
|
+
reportingInstance: string;
|
|
54
|
+
},
|
|
53
55
|
): Promise<void> {
|
|
56
|
+
const { eventType, eventReason, reportingComponent, reportingInstance } = options;
|
|
57
|
+
|
|
54
58
|
await K8s(kind.CoreEvent).Create({
|
|
55
59
|
type: eventType,
|
|
56
60
|
reason: eventReason,
|