pepr 0.40.1 → 0.42.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.
- package/README.md +11 -5
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +2 -2
- package/dist/cli.js +228 -179
- package/dist/controller.js +52 -27
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/capability.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/index.util.d.ts +10 -0
- package/dist/lib/controller/index.util.d.ts.map +1 -0
- package/dist/lib/controller/store.d.ts +1 -1
- package/dist/lib/deploymentChecks.d.ts +3 -0
- package/dist/lib/deploymentChecks.d.ts.map +1 -0
- package/dist/lib/enums.d.ts +5 -5
- package/dist/lib/enums.d.ts.map +1 -1
- package/dist/lib/filesystemService.d.ts +2 -0
- package/dist/lib/filesystemService.d.ts.map +1 -0
- package/dist/lib/filter/adjudicators/adjudicators.d.ts +73 -0
- package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -0
- package/dist/lib/filter/adjudicators/defaultTestObjects.d.ts +7 -0
- package/dist/lib/filter/adjudicators/defaultTestObjects.d.ts.map +1 -0
- package/dist/lib/helpers.d.ts +1 -4
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/schedule.d.ts.map +1 -1
- package/dist/lib/storage.d.ts +1 -1
- package/dist/lib/storage.d.ts.map +1 -1
- package/dist/lib/{logger.d.ts → telemetry/logger.d.ts} +1 -1
- package/dist/lib/telemetry/logger.d.ts.map +1 -0
- package/dist/lib/{metrics.d.ts → telemetry/metrics.d.ts} +3 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -0
- package/dist/lib/types.d.ts +10 -9
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib.d.ts +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +151 -126
- package/dist/lib.js.map +4 -4
- package/dist/sdk/sdk.d.ts +3 -4
- package/dist/sdk/sdk.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/cli/build.ts +2 -1
- package/src/cli/deploy.ts +2 -1
- package/src/cli/init/templates.ts +1 -1
- package/src/lib/assets/deploy.ts +1 -1
- package/src/lib/assets/destroy.ts +1 -1
- package/src/lib/assets/index.ts +102 -81
- package/src/lib/assets/webhooks.ts +2 -2
- package/src/lib/capability.ts +8 -9
- package/src/lib/controller/index.ts +32 -62
- package/src/lib/controller/index.util.ts +47 -0
- package/src/lib/controller/store.ts +2 -2
- package/src/lib/controller/storeCache.ts +1 -1
- package/src/lib/deploymentChecks.ts +43 -0
- package/src/lib/enums.ts +5 -5
- package/src/lib/filesystemService.ts +16 -0
- package/src/lib/filter/{adjudicators.ts → adjudicators/adjudicators.ts} +67 -35
- package/src/lib/filter/adjudicators/defaultTestObjects.ts +46 -0
- package/src/lib/filter/filter.ts +1 -1
- package/src/lib/finalizer.ts +1 -1
- package/src/lib/helpers.ts +31 -88
- package/src/lib/mutate-processor.ts +1 -1
- package/src/lib/queue.ts +1 -1
- package/src/lib/schedule.ts +8 -8
- package/src/lib/storage.ts +17 -17
- package/src/lib/{logger.ts → telemetry/logger.ts} +1 -1
- package/src/lib/{metrics.ts → telemetry/metrics.ts} +18 -17
- package/src/lib/types.ts +12 -9
- package/src/lib/utils.ts +1 -1
- package/src/lib/validate-processor.ts +1 -1
- package/src/lib/watch-processor.ts +8 -8
- package/src/lib.ts +1 -1
- package/src/runtime/controller.ts +1 -1
- package/src/sdk/sdk.ts +6 -9
- package/src/templates/capabilities/hello-pepr.ts +19 -9
- package/dist/lib/filter/adjudicators.d.ts +0 -69
- package/dist/lib/filter/adjudicators.d.ts.map +0 -1
- package/dist/lib/logger.d.ts.map +0 -1
- package/dist/lib/metrics.d.ts.map +0 -1
package/src/lib/storage.ts
CHANGED
|
@@ -12,15 +12,15 @@ export type Unsubscribe = () => void;
|
|
|
12
12
|
const MAX_WAIT_TIME = 15000;
|
|
13
13
|
const STORE_VERSION_PREFIX = "v2";
|
|
14
14
|
|
|
15
|
-
export function v2StoreKey(key: string) {
|
|
15
|
+
export function v2StoreKey(key: string): string {
|
|
16
16
|
return `${STORE_VERSION_PREFIX}-${pointer.escape(key)}`;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function v2UnescapedStoreKey(key: string) {
|
|
19
|
+
export function v2UnescapedStoreKey(key: string): string {
|
|
20
20
|
return `${STORE_VERSION_PREFIX}-${key}`;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function stripV2Prefix(key: string) {
|
|
23
|
+
export function stripV2Prefix(key: string): string {
|
|
24
24
|
return key.replace(/^v2-/, "");
|
|
25
25
|
}
|
|
26
26
|
export interface PeprStore {
|
|
@@ -80,11 +80,11 @@ export class Storage implements PeprStore {
|
|
|
80
80
|
#subscriberId = 0;
|
|
81
81
|
#readyHandlers: DataReceiver[] = [];
|
|
82
82
|
|
|
83
|
-
registerSender = (send: DataSender) => {
|
|
83
|
+
registerSender = (send: DataSender): void => {
|
|
84
84
|
this.#send = send;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
receive = (data: DataStore) => {
|
|
87
|
+
receive = (data: DataStore): void => {
|
|
88
88
|
this.#store = data || {};
|
|
89
89
|
|
|
90
90
|
this.#onReady();
|
|
@@ -96,7 +96,7 @@ export class Storage implements PeprStore {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
getItem = (key: string) => {
|
|
99
|
+
getItem = (key: string): string | null => {
|
|
100
100
|
const result = this.#store[v2UnescapedStoreKey(key)] || null;
|
|
101
101
|
if (result !== null && typeof result !== "function" && typeof result !== "object") {
|
|
102
102
|
return result;
|
|
@@ -104,7 +104,7 @@ export class Storage implements PeprStore {
|
|
|
104
104
|
return null;
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
clear = () => {
|
|
107
|
+
clear = (): void => {
|
|
108
108
|
Object.keys(this.#store).length > 0 &&
|
|
109
109
|
this.#dispatchUpdate(
|
|
110
110
|
"remove",
|
|
@@ -112,11 +112,11 @@ export class Storage implements PeprStore {
|
|
|
112
112
|
);
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
-
removeItem = (key: string) => {
|
|
115
|
+
removeItem = (key: string): void => {
|
|
116
116
|
this.#dispatchUpdate("remove", [v2StoreKey(key)]);
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
setItem = (key: string, value: string) => {
|
|
119
|
+
setItem = (key: string, value: string): void => {
|
|
120
120
|
this.#dispatchUpdate("add", [v2StoreKey(key)], value);
|
|
121
121
|
};
|
|
122
122
|
|
|
@@ -128,7 +128,7 @@ export class Storage implements PeprStore {
|
|
|
128
128
|
* @param value - The value of the key
|
|
129
129
|
* @returns
|
|
130
130
|
*/
|
|
131
|
-
setItemAndWait = (key: string, value: string) => {
|
|
131
|
+
setItemAndWait = (key: string, value: string): Promise<void> => {
|
|
132
132
|
this.#dispatchUpdate("add", [v2StoreKey(key)], value);
|
|
133
133
|
|
|
134
134
|
return new Promise<void>((resolve, reject) => {
|
|
@@ -154,7 +154,7 @@ export class Storage implements PeprStore {
|
|
|
154
154
|
* @param key - The key to add into the store
|
|
155
155
|
* @returns
|
|
156
156
|
*/
|
|
157
|
-
removeItemAndWait = (key: string) => {
|
|
157
|
+
removeItemAndWait = (key: string): Promise<void> => {
|
|
158
158
|
this.#dispatchUpdate("remove", [v2StoreKey(key)]);
|
|
159
159
|
return new Promise<void>((resolve, reject) => {
|
|
160
160
|
const unsubscribe = this.subscribe(data => {
|
|
@@ -172,13 +172,13 @@ export class Storage implements PeprStore {
|
|
|
172
172
|
});
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
-
subscribe = (subscriber: DataReceiver) => {
|
|
175
|
+
subscribe = (subscriber: DataReceiver): (() => void) => {
|
|
176
176
|
const idx = this.#subscriberId++;
|
|
177
177
|
this.#subscribers[idx] = subscriber;
|
|
178
178
|
return () => this.unsubscribe(idx);
|
|
179
179
|
};
|
|
180
180
|
|
|
181
|
-
onReady = (callback: DataReceiver) => {
|
|
181
|
+
onReady = (callback: DataReceiver): void => {
|
|
182
182
|
this.#readyHandlers.push(callback);
|
|
183
183
|
};
|
|
184
184
|
|
|
@@ -186,18 +186,18 @@ export class Storage implements PeprStore {
|
|
|
186
186
|
* Remove a subscriber from the list of subscribers.
|
|
187
187
|
* @param idx - The index of the subscriber to remove.
|
|
188
188
|
*/
|
|
189
|
-
unsubscribe = (idx: number) => {
|
|
189
|
+
unsubscribe = (idx: number): void => {
|
|
190
190
|
delete this.#subscribers[idx];
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
#onReady = () => {
|
|
193
|
+
#onReady = (): void => {
|
|
194
194
|
// Notify all ready handlers with a clone of the store
|
|
195
195
|
for (const handler of this.#readyHandlers) {
|
|
196
196
|
handler(clone(this.#store));
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
// Make this a noop so that it can't be called again
|
|
200
|
-
this.#onReady = () => {};
|
|
200
|
+
this.#onReady = (): void => {};
|
|
201
201
|
};
|
|
202
202
|
|
|
203
203
|
/**
|
|
@@ -206,7 +206,7 @@ export class Storage implements PeprStore {
|
|
|
206
206
|
* @param keys - The keys to update.
|
|
207
207
|
* @param [value] - The new value.
|
|
208
208
|
*/
|
|
209
|
-
#dispatchUpdate = (op: DataOp, keys: string[], value?: string) => {
|
|
209
|
+
#dispatchUpdate = (op: DataOp, keys: string[], value?: string): void => {
|
|
210
210
|
this.#send(op, keys, value);
|
|
211
211
|
};
|
|
212
212
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { Operation } from "fast-json-patch";
|
|
5
5
|
import { pino, stdTimeFunctions } from "pino";
|
|
6
|
-
import { Store } from "
|
|
6
|
+
import { Store } from "../k8s";
|
|
7
7
|
|
|
8
8
|
const isPrettyLog = process.env.PEPR_PRETTY_LOGS === "true";
|
|
9
9
|
const redactedValue = "**redacted**";
|
|
@@ -9,6 +9,7 @@ import Log from "./logger";
|
|
|
9
9
|
|
|
10
10
|
const loggingPrefix = "MetricsCollector";
|
|
11
11
|
|
|
12
|
+
type MetricsCollectorInstance = InstanceType<typeof MetricsCollector>;
|
|
12
13
|
interface MetricNames {
|
|
13
14
|
errors: string;
|
|
14
15
|
alerts: string;
|
|
@@ -60,7 +61,7 @@ export class MetricsCollector {
|
|
|
60
61
|
this.addGauge(this.#metricNames.resyncFailureCount, "Number of failures per resync operation", ["count"]);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
#getMetricName = (name: string) => `${this.#prefix}_${name}`;
|
|
64
|
+
#getMetricName = (name: string): string => `${this.#prefix}_${name}`;
|
|
64
65
|
|
|
65
66
|
#addMetric = <T extends Counter<string> | Gauge<string> | Summary<string>>(
|
|
66
67
|
collection: Map<string, T>,
|
|
@@ -68,7 +69,7 @@ export class MetricsCollector {
|
|
|
68
69
|
name: string,
|
|
69
70
|
help: string,
|
|
70
71
|
labelNames?: string[],
|
|
71
|
-
) => {
|
|
72
|
+
): void => {
|
|
72
73
|
if (collection.has(this.#getMetricName(name))) {
|
|
73
74
|
Log.debug(`Metric for ${name} already exists`, loggingPrefix);
|
|
74
75
|
return;
|
|
@@ -84,42 +85,42 @@ export class MetricsCollector {
|
|
|
84
85
|
collection.set(this.#getMetricName(name), metric);
|
|
85
86
|
};
|
|
86
87
|
|
|
87
|
-
addCounter = (name: string, help: string) => {
|
|
88
|
+
addCounter = (name: string, help: string): void => {
|
|
88
89
|
this.#addMetric(this.#counters, promClient.Counter, name, help, []);
|
|
89
90
|
};
|
|
90
91
|
|
|
91
|
-
addSummary = (name: string, help: string) => {
|
|
92
|
+
addSummary = (name: string, help: string): void => {
|
|
92
93
|
this.#addMetric(this.#summaries, promClient.Summary, name, help, []);
|
|
93
94
|
};
|
|
94
95
|
|
|
95
|
-
addGauge = (name: string, help: string, labelNames?: string[]) => {
|
|
96
|
+
addGauge = (name: string, help: string, labelNames?: string[]): void => {
|
|
96
97
|
this.#addMetric(this.#gauges, promClient.Gauge, name, help, labelNames);
|
|
97
98
|
};
|
|
98
99
|
|
|
99
|
-
incCounter = (name: string) => {
|
|
100
|
+
incCounter = (name: string): void => {
|
|
100
101
|
this.#counters.get(this.#getMetricName(name))?.inc();
|
|
101
102
|
};
|
|
102
103
|
|
|
103
|
-
incGauge = (name: string, labels?: Record<string, string>, value: number = 1) => {
|
|
104
|
+
incGauge = (name: string, labels?: Record<string, string>, value: number = 1): void => {
|
|
104
105
|
this.#gauges.get(this.#getMetricName(name))?.inc(labels || {}, value);
|
|
105
106
|
};
|
|
106
107
|
|
|
107
108
|
/**
|
|
108
109
|
* Increments the error counter.
|
|
109
110
|
*/
|
|
110
|
-
error = () => this.incCounter(this.#metricNames.errors);
|
|
111
|
+
error = (): void => this.incCounter(this.#metricNames.errors);
|
|
111
112
|
|
|
112
113
|
/**
|
|
113
114
|
* Increments the alerts counter.
|
|
114
115
|
*/
|
|
115
|
-
alert = () => this.incCounter(this.#metricNames.alerts);
|
|
116
|
+
alert = (): void => this.incCounter(this.#metricNames.alerts);
|
|
116
117
|
|
|
117
118
|
/**
|
|
118
119
|
* Observes the duration since the provided start time and updates the summary.
|
|
119
120
|
* @param startTime - The start time.
|
|
120
121
|
* @param name - The metrics summary to increment.
|
|
121
122
|
*/
|
|
122
|
-
observeEnd = (startTime: number, name: string = this.#metricNames.mutate) => {
|
|
123
|
+
observeEnd = (startTime: number, name: string = this.#metricNames.mutate): void => {
|
|
123
124
|
this.#summaries.get(this.#getMetricName(name))?.observe(performance.now() - startTime);
|
|
124
125
|
};
|
|
125
126
|
|
|
@@ -127,13 +128,13 @@ export class MetricsCollector {
|
|
|
127
128
|
* Fetches the current metrics from the registry.
|
|
128
129
|
* @returns The metrics.
|
|
129
130
|
*/
|
|
130
|
-
getMetrics = () => this.#registry.metrics();
|
|
131
|
+
getMetrics = (): Promise<string> => this.#registry.metrics();
|
|
131
132
|
|
|
132
133
|
/**
|
|
133
134
|
* Returns the current timestamp from performance.now() method. Useful for start timing an operation.
|
|
134
135
|
* @returns The timestamp.
|
|
135
136
|
*/
|
|
136
|
-
static observeStart() {
|
|
137
|
+
static observeStart(): number {
|
|
137
138
|
return performance.now();
|
|
138
139
|
}
|
|
139
140
|
|
|
@@ -141,7 +142,7 @@ export class MetricsCollector {
|
|
|
141
142
|
* Increments the cache miss gauge for a given label.
|
|
142
143
|
* @param label - The label for the cache miss.
|
|
143
144
|
*/
|
|
144
|
-
incCacheMiss = (window: string) => {
|
|
145
|
+
incCacheMiss = (window: string): void => {
|
|
145
146
|
this.incGauge(this.#metricNames.cacheMiss, { window });
|
|
146
147
|
};
|
|
147
148
|
|
|
@@ -149,7 +150,7 @@ export class MetricsCollector {
|
|
|
149
150
|
* Increments the retry count gauge.
|
|
150
151
|
* @param count - The count to increment by.
|
|
151
152
|
*/
|
|
152
|
-
incRetryCount = (count: string) => {
|
|
153
|
+
incRetryCount = (count: string): void => {
|
|
153
154
|
this.incGauge(this.#metricNames.resyncFailureCount, { count });
|
|
154
155
|
};
|
|
155
156
|
|
|
@@ -157,7 +158,7 @@ export class MetricsCollector {
|
|
|
157
158
|
* Initializes the cache miss gauge for a given label.
|
|
158
159
|
* @param label - The label for the cache miss.
|
|
159
160
|
*/
|
|
160
|
-
initCacheMissWindow = (window: string) => {
|
|
161
|
+
initCacheMissWindow = (window: string): void => {
|
|
161
162
|
this.#rollCacheMissWindows();
|
|
162
163
|
this.#gauges.get(this.#getMetricName(this.#metricNames.cacheMiss))?.set({ window }, 0);
|
|
163
164
|
this.#cacheMissWindows.set(window, 0);
|
|
@@ -166,7 +167,7 @@ export class MetricsCollector {
|
|
|
166
167
|
/**
|
|
167
168
|
* Manages the size of the cache miss gauge map.
|
|
168
169
|
*/
|
|
169
|
-
#rollCacheMissWindows = () => {
|
|
170
|
+
#rollCacheMissWindows = (): void => {
|
|
170
171
|
const maxCacheMissWindows = process.env.PEPR_MAX_CACHE_MISS_WINDOWS
|
|
171
172
|
? parseInt(process.env.PEPR_MAX_CACHE_MISS_WINDOWS, 10)
|
|
172
173
|
: undefined;
|
|
@@ -181,4 +182,4 @@ export class MetricsCollector {
|
|
|
181
182
|
};
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
export const metricsCollector = new MetricsCollector("pepr");
|
|
185
|
+
export const metricsCollector: MetricsCollectorInstance = new MetricsCollector("pepr");
|
package/src/lib/types.ts
CHANGED
|
@@ -70,6 +70,17 @@ export interface RegExpFilter {
|
|
|
70
70
|
obj: RegExp;
|
|
71
71
|
source: string;
|
|
72
72
|
}
|
|
73
|
+
|
|
74
|
+
export type Filters = {
|
|
75
|
+
annotations: Record<string, string>;
|
|
76
|
+
deletionTimestamp: boolean;
|
|
77
|
+
labels: Record<string, string>;
|
|
78
|
+
name: string;
|
|
79
|
+
namespaces: string[];
|
|
80
|
+
regexName: string;
|
|
81
|
+
regexNamespaces: string[];
|
|
82
|
+
};
|
|
83
|
+
|
|
73
84
|
export type Binding = {
|
|
74
85
|
event: Event;
|
|
75
86
|
isMutate?: boolean;
|
|
@@ -79,15 +90,7 @@ export type Binding = {
|
|
|
79
90
|
isFinalize?: boolean;
|
|
80
91
|
readonly model: GenericClass;
|
|
81
92
|
readonly kind: GroupVersionKind;
|
|
82
|
-
readonly filters:
|
|
83
|
-
name: string;
|
|
84
|
-
regexName: string;
|
|
85
|
-
namespaces: string[];
|
|
86
|
-
regexNamespaces: string[];
|
|
87
|
-
labels: Record<string, string>;
|
|
88
|
-
annotations: Record<string, string>;
|
|
89
|
-
deletionTimestamp: boolean;
|
|
90
|
-
};
|
|
93
|
+
readonly filters: Filters;
|
|
91
94
|
alias?: string;
|
|
92
95
|
readonly mutateCallback?: MutateAction<GenericClass, InstanceType<GenericClass>>;
|
|
93
96
|
readonly validateCallback?: ValidateAction<GenericClass, InstanceType<GenericClass>>;
|
package/src/lib/utils.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { Capability } from "./capability";
|
|
|
7
7
|
import { shouldSkipRequest } from "./filter/filter";
|
|
8
8
|
import { ValidateResponse } from "./k8s";
|
|
9
9
|
import { AdmissionRequest } from "./types";
|
|
10
|
-
import Log from "./logger";
|
|
10
|
+
import Log from "./telemetry/logger";
|
|
11
11
|
import { convertFromBase64Map } from "./utils";
|
|
12
12
|
import { PeprValidateRequest } from "./validate-request";
|
|
13
13
|
import { ModuleConfig } from "./module";
|
|
@@ -5,11 +5,11 @@ import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";
|
|
|
5
5
|
import { Capability } from "./capability";
|
|
6
6
|
import { filterNoMatchReason } from "./helpers";
|
|
7
7
|
import { removeFinalizer } from "./finalizer";
|
|
8
|
-
import Log from "./logger";
|
|
8
|
+
import Log from "./telemetry/logger";
|
|
9
9
|
import { Queue } from "./queue";
|
|
10
10
|
import { Binding } from "./types";
|
|
11
11
|
import { Event } from "./enums";
|
|
12
|
-
import { metricsCollector } from "./metrics";
|
|
12
|
+
import { metricsCollector } from "./telemetry/metrics";
|
|
13
13
|
|
|
14
14
|
// stores Queue instances
|
|
15
15
|
const queues: Record<string, Queue<KubernetesObject>> = {};
|
|
@@ -62,11 +62,11 @@ const watchCfg: WatchCfg = {
|
|
|
62
62
|
|
|
63
63
|
// Map the event to the watch phase
|
|
64
64
|
const eventToPhaseMap = {
|
|
65
|
-
[Event.
|
|
66
|
-
[Event.
|
|
67
|
-
[Event.
|
|
68
|
-
[Event.
|
|
69
|
-
[Event.
|
|
65
|
+
[Event.CREATE]: [WatchPhase.Added],
|
|
66
|
+
[Event.UPDATE]: [WatchPhase.Modified],
|
|
67
|
+
[Event.CREATE_OR_UPDATE]: [WatchPhase.Added, WatchPhase.Modified],
|
|
68
|
+
[Event.DELETE]: [WatchPhase.Deleted],
|
|
69
|
+
[Event.ANY]: [WatchPhase.Added, WatchPhase.Modified, WatchPhase.Deleted],
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
/**
|
|
@@ -90,7 +90,7 @@ export function setupWatch(capabilities: Capability[], ignoredNamespaces?: strin
|
|
|
90
90
|
*/
|
|
91
91
|
async function runBinding(binding: Binding, capabilityNamespaces: string[], ignoredNamespaces?: string[]) {
|
|
92
92
|
// Get the phases to match, fallback to any
|
|
93
|
-
const phaseMatch: WatchPhase[] = eventToPhaseMap[binding.event] || eventToPhaseMap[Event.
|
|
93
|
+
const phaseMatch: WatchPhase[] = eventToPhaseMap[binding.event] || eventToPhaseMap[Event.ANY];
|
|
94
94
|
|
|
95
95
|
// The watch callback is run when an object is received or dequeued
|
|
96
96
|
Log.debug({ watchCfg }, "Effective WatchConfig");
|
package/src/lib.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { K8s, RegisterKind, kind as a, fetch, fetchStatus, kind } from "kubernet
|
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
|
|
4
4
|
import { Capability } from "./lib/capability";
|
|
5
|
-
import Log from "./lib/logger";
|
|
5
|
+
import Log from "./lib/telemetry/logger";
|
|
6
6
|
import { PeprModule } from "./lib/module";
|
|
7
7
|
import { PeprMutateRequest } from "./lib/mutate-request";
|
|
8
8
|
import * as PeprUtils from "./lib/utils";
|
|
@@ -8,7 +8,7 @@ import crypto from "crypto";
|
|
|
8
8
|
import fs from "fs";
|
|
9
9
|
import { gunzipSync } from "zlib";
|
|
10
10
|
import { K8s, kind } from "kubernetes-fluent-client";
|
|
11
|
-
import Log from "../lib/logger";
|
|
11
|
+
import Log from "../lib/telemetry/logger";
|
|
12
12
|
import { packageJSON } from "../templates/data.json";
|
|
13
13
|
import { peprStoreCRD } from "../lib/assets/store";
|
|
14
14
|
import { validateHash } from "../lib/helpers";
|
package/src/sdk/sdk.ts
CHANGED
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import { PeprValidateRequest } from "../lib/validate-request";
|
|
5
5
|
import { PeprMutateRequest } from "../lib/mutate-request";
|
|
6
|
-
import { V1OwnerReference } from "@kubernetes/client-node";
|
|
7
|
-
import { GenericKind } from "kubernetes-fluent-client";
|
|
8
|
-
import { K8s, kind } from "kubernetes-fluent-client";
|
|
9
|
-
import Log from "../lib/logger";
|
|
6
|
+
import { V1OwnerReference, V1Container } from "@kubernetes/client-node";
|
|
7
|
+
import { GenericKind, K8s, kind } from "kubernetes-fluent-client";
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* Returns all containers in a pod
|
|
@@ -17,7 +15,7 @@ import Log from "../lib/logger";
|
|
|
17
15
|
export function containers(
|
|
18
16
|
request: PeprValidateRequest<kind.Pod> | PeprMutateRequest<kind.Pod>,
|
|
19
17
|
containerType?: "containers" | "initContainers" | "ephemeralContainers",
|
|
20
|
-
) {
|
|
18
|
+
): V1Container[] {
|
|
21
19
|
const containers = request.Raw.spec?.containers || [];
|
|
22
20
|
const initContainers = request.Raw.spec?.initContainers || [];
|
|
23
21
|
const ephemeralContainers = request.Raw.spec?.ephemeralContainers || [];
|
|
@@ -44,6 +42,7 @@ export function containers(
|
|
|
44
42
|
* @param reportingComponent The component that is reporting the event, for example "uds.dev/operator"
|
|
45
43
|
* @param reportingInstance The instance of the component that is reporting the event, for example process.env.HOSTNAME
|
|
46
44
|
*/
|
|
45
|
+
|
|
47
46
|
export async function writeEvent(
|
|
48
47
|
cr: GenericKind,
|
|
49
48
|
event: Partial<kind.CoreEvent>,
|
|
@@ -51,9 +50,7 @@ export async function writeEvent(
|
|
|
51
50
|
eventReason: string,
|
|
52
51
|
reportingComponent: string,
|
|
53
52
|
reportingInstance: string,
|
|
54
|
-
) {
|
|
55
|
-
Log.debug(cr.metadata, `Writing event: ${event.message}`);
|
|
56
|
-
|
|
53
|
+
): Promise<void> {
|
|
57
54
|
await K8s(kind.CoreEvent).Create({
|
|
58
55
|
type: eventType,
|
|
59
56
|
reason: eventReason,
|
|
@@ -109,7 +106,7 @@ export function getOwnerRefFrom(
|
|
|
109
106
|
* @param name the name of the resource to sanitize
|
|
110
107
|
* @returns the sanitized resource name
|
|
111
108
|
*/
|
|
112
|
-
export function sanitizeResourceName(name: string) {
|
|
109
|
+
export function sanitizeResourceName(name: string): string {
|
|
113
110
|
return (
|
|
114
111
|
name
|
|
115
112
|
// The name must be lowercase
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
fetchStatus,
|
|
10
10
|
kind,
|
|
11
11
|
} from "pepr";
|
|
12
|
-
import
|
|
12
|
+
import { MockAgent, setGlobalDispatcher } from "undici";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.
|
|
@@ -273,14 +273,24 @@ When(a.ConfigMap)
|
|
|
273
273
|
.WithLabel("chuck-norris")
|
|
274
274
|
.Mutate(cm => cm.SetLabel("got-jokes", "true"))
|
|
275
275
|
.Watch(async cm => {
|
|
276
|
-
const jokeURL = "https://icanhazdadjoke.com
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
276
|
+
const jokeURL = "https://icanhazdadjoke.com";
|
|
277
|
+
|
|
278
|
+
const mockAgent: MockAgent = new MockAgent();
|
|
279
|
+
setGlobalDispatcher(mockAgent);
|
|
280
|
+
const mockClient = mockAgent.get(jokeURL);
|
|
281
|
+
mockClient.intercept({ path: "/", method: "GET" }).reply(
|
|
282
|
+
200,
|
|
283
|
+
{
|
|
284
|
+
id: "R7UfaahVfFd",
|
|
285
|
+
joke: "Funny joke goes here.",
|
|
286
|
+
status: 200,
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
headers: {
|
|
290
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
);
|
|
284
294
|
|
|
285
295
|
// Try/catch is not needed as a response object will always be returned
|
|
286
296
|
const response = await fetch<TheChuckNorrisJoke>(jokeURL, {
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Operation } from "../enums";
|
|
2
|
-
import { AdmissionRequest } from "../../lib/types";
|
|
3
|
-
import { KubernetesObject } from "kubernetes-fluent-client";
|
|
4
|
-
export declare const declaredOperation: (request: AdmissionRequest<KubernetesObject>) => Operation;
|
|
5
|
-
export declare const declaredGroup: (request: AdmissionRequest<KubernetesObject>) => string;
|
|
6
|
-
export declare const declaredVersion: (request: AdmissionRequest<KubernetesObject>) => string;
|
|
7
|
-
export declare const declaredKind: (request: AdmissionRequest<KubernetesObject>) => string;
|
|
8
|
-
export declare const declaredUid: (request: AdmissionRequest<KubernetesObject>) => string;
|
|
9
|
-
export declare const carriesDeletionTimestamp: (kubernetesObject: any) => boolean;
|
|
10
|
-
export declare const missingDeletionTimestamp: (kubernetesObject: any) => boolean;
|
|
11
|
-
export declare const carriedKind: (kubernetesObject: any) => any;
|
|
12
|
-
export declare const carriedVersion: (kubernetesObject: any) => any;
|
|
13
|
-
export declare const carriedName: (kubernetesObject: any) => any;
|
|
14
|
-
export declare const carriesName: (kubernetesObject: any) => boolean;
|
|
15
|
-
export declare const missingName: (kubernetesObject: any) => boolean;
|
|
16
|
-
export declare const carriedNamespace: (kubernetesObject: any) => any;
|
|
17
|
-
export declare const carriesNamespace: (kubernetesObject: any) => boolean;
|
|
18
|
-
export declare const carriedAnnotations: (kubernetesObject: any) => any;
|
|
19
|
-
export declare const carriesAnnotations: (kubernetesObject: any) => boolean;
|
|
20
|
-
export declare const carriedLabels: (kubernetesObject: any) => any;
|
|
21
|
-
export declare const carriesLabels: (kubernetesObject: any) => boolean;
|
|
22
|
-
export declare const definesDeletionTimestamp: (binding: any) => any;
|
|
23
|
-
export declare const ignoresDeletionTimestamp: (binding: any) => boolean;
|
|
24
|
-
export declare const definedName: (binding: any) => any;
|
|
25
|
-
export declare const definesName: (binding: any) => boolean;
|
|
26
|
-
export declare const ignoresName: (binding: any) => boolean;
|
|
27
|
-
export declare const definedNameRegex: (binding: any) => any;
|
|
28
|
-
export declare const definesNameRegex: (binding: any) => boolean;
|
|
29
|
-
export declare const definedNamespaces: (binding: any) => any;
|
|
30
|
-
export declare const definesNamespaces: (binding: any) => boolean;
|
|
31
|
-
export declare const definedNamespaceRegexes: (binding: any) => any;
|
|
32
|
-
export declare const definesNamespaceRegexes: (binding: any) => boolean;
|
|
33
|
-
export declare const definedAnnotations: (binding: any) => any;
|
|
34
|
-
export declare const definesAnnotations: (binding: any) => boolean;
|
|
35
|
-
export declare const definedLabels: (binding: any) => any;
|
|
36
|
-
export declare const definesLabels: (binding: any) => boolean;
|
|
37
|
-
export declare const definedEvent: (binding: any) => any;
|
|
38
|
-
export declare const definesDelete: (binding: any) => boolean;
|
|
39
|
-
export declare const definedGroup: (binding: any) => any;
|
|
40
|
-
export declare const definesGroup: (binding: any) => boolean;
|
|
41
|
-
export declare const definedVersion: (binding: any) => any;
|
|
42
|
-
export declare const definesVersion: (binding: any) => boolean;
|
|
43
|
-
export declare const definedKind: (binding: any) => any;
|
|
44
|
-
export declare const definesKind: (binding: any) => boolean;
|
|
45
|
-
export declare const definedCategory: (binding: any) => "" | "Finalize" | "Watch" | "Mutate" | "Validate";
|
|
46
|
-
export declare const definedCallback: (binding: any) => any;
|
|
47
|
-
export declare const definedCallbackName: (binding: any) => any;
|
|
48
|
-
export declare const mismatchedDeletionTimestamp: (...args: any[]) => any;
|
|
49
|
-
export declare const mismatchedName: (...args: any[]) => boolean;
|
|
50
|
-
export declare const mismatchedNameRegex: (...args: any[]) => boolean;
|
|
51
|
-
export declare const bindsToKind: import("ts-toolbelt/out/Function/Curry").Curry<(...args: any[]) => boolean>;
|
|
52
|
-
export declare const bindsToNamespace: import("ts-toolbelt/out/Function/Curry").Curry<(...args: any[]) => unknown>;
|
|
53
|
-
export declare const misboundNamespace: ((binding: any) => boolean) | import("ts-toolbelt/out/Function/Curry").Curry<(...args: any[]) => unknown>;
|
|
54
|
-
export declare const mismatchedNamespace: (...args: any[]) => boolean;
|
|
55
|
-
export declare const mismatchedNamespaceRegex: (...args: any[]) => boolean;
|
|
56
|
-
export declare const metasMismatch: (defined: any, carried: any) => boolean;
|
|
57
|
-
export declare const mismatchedAnnotations: (...args: any[]) => boolean;
|
|
58
|
-
export declare const mismatchedLabels: (...args: any[]) => boolean;
|
|
59
|
-
export declare const uncarryableNamespace: (...args: any[]) => boolean;
|
|
60
|
-
export declare const missingCarriableNamespace: ((...args: any[]) => boolean) | ((namespaceSelector: string[], kubernetesObject: KubernetesObject) => boolean);
|
|
61
|
-
export declare const carriesIgnoredNamespace: ((...args: any[]) => boolean) | ((namespaceSelector: any, kubernetesObject: any) => any);
|
|
62
|
-
export declare const unbindableNamespaces: (...args: any[]) => boolean;
|
|
63
|
-
export declare const misboundDeleteWithDeletionTimestamp: (binding: any) => any;
|
|
64
|
-
export declare const operationMatchesEvent: ((...args: any[]) => boolean) | ((operation: any, event: any) => any);
|
|
65
|
-
export declare const mismatchedEvent: (binding: any, request: any) => boolean;
|
|
66
|
-
export declare const mismatchedGroup: (...args: any[]) => boolean;
|
|
67
|
-
export declare const mismatchedVersion: (...args: any[]) => boolean;
|
|
68
|
-
export declare const mismatchedKind: (...args: any[]) => boolean;
|
|
69
|
-
//# sourceMappingURL=adjudicators.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adjudicators.d.ts","sourceRoot":"","sources":["../../../src/lib/filter/adjudicators.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,SAAS,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAiBnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAY5D,eAAO,MAAM,iBAAiB,4DAG7B,CAAC;AACF,eAAO,MAAM,aAAa,yDAGzB,CAAC;AACF,eAAO,MAAM,eAAe,yDAG3B,CAAC;AACF,eAAO,MAAM,YAAY,yDAGxB,CAAC;AACF,eAAO,MAAM,WAAW,yDAA6F,CAAC;AAKtH,eAAO,MAAM,wBAAwB,oCAGpC,CAAC;AACF,eAAO,MAAM,wBAAwB,oCAAuC,CAAC;AAE7E,eAAO,MAAM,WAAW,gCAA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AAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAgB9B,QAAA,MAAM,GAAG,uCAGP,CAAC;AAMH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CASjD;AAED,wBAAgB,aAAa,CAAC,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAM,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAwB9F;AAED,eAAe,GAAG,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/lib/metrics.ts"],"names":[],"mappings":"AA2BA;;GAEG;AACH,qBAAa,gBAAgB;;IAiB3B;;;OAGG;gBACS,MAAM,SAAS;IAmC3B,UAAU,SAAU,MAAM,QAAQ,MAAM,UAEtC;IAEF,UAAU,SAAU,MAAM,QAAQ,MAAM,UAEtC;IAEF,QAAQ,SAAU,MAAM,QAAQ,MAAM,eAAe,MAAM,EAAE,UAE3D;IAEF,UAAU,SAAU,MAAM,UAExB;IAEF,QAAQ,SAAU,MAAM,WAAW,OAAO,MAAM,EAAE,MAAM,CAAC,UAAS,MAAM,UAEtE;IAEF;;OAEG;IACH,KAAK,aAAmD;IAExD;;OAEG;IACH,KAAK,aAAmD;IAExD;;;;OAIG;IACH,UAAU,cAAe,MAAM,SAAQ,MAAM,UAE3C;IAEF;;;OAGG;IACH,UAAU,wBAAkC;IAE5C;;;OAGG;IACH,MAAM,CAAC,YAAY;IAInB;;;OAGG;IACH,YAAY,WAAY,MAAM,UAE5B;IAEF;;;OAGG;IACH,aAAa,UAAW,MAAM,UAE5B;IAEF;;;OAGG;IACH,mBAAmB,WAAY,MAAM,UAInC;CAkBH;AAED,eAAO,MAAM,gBAAgB,kBAA+B,CAAC"}
|