pepr 0.44.0-nightly.2 → 0.44.0-nightly.4
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 +1 -1
- package/dist/cli/init/templates.d.ts +1 -0
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/controller.js +1 -1
- package/dist/lib/assets/webhooks.d.ts +2 -0
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/assets/yaml/overridesFile.d.ts +1 -3
- package/dist/lib/assets/yaml/overridesFile.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts +6 -1
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/core/module.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib.js +19 -13
- package/dist/lib.js.map +2 -2
- package/package.json +5 -1
- package/src/lib/assets/webhooks.ts +1 -1
- package/src/lib/assets/yaml/overridesFile.ts +3 -5
- package/src/lib/controller/index.ts +8 -7
- package/src/lib/core/module.ts +17 -11
- package/src/lib/telemetry/metrics.ts +4 -6
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"!src/**/*.test.ts",
|
|
16
16
|
"!dist/**/*.test.d.ts*"
|
|
17
17
|
],
|
|
18
|
-
"version": "0.44.0-nightly.
|
|
18
|
+
"version": "0.44.0-nightly.4",
|
|
19
19
|
"main": "dist/lib.js",
|
|
20
20
|
"types": "dist/lib.d.ts",
|
|
21
21
|
"scripts": {
|
|
@@ -72,9 +72,13 @@
|
|
|
72
72
|
"husky": "^9.1.6",
|
|
73
73
|
"jest": "29.7.0",
|
|
74
74
|
"js-yaml": "^4.1.0",
|
|
75
|
+
"shellcheck": "^3.0.0",
|
|
75
76
|
"ts-jest": "29.2.5",
|
|
76
77
|
"undici": "^7.0.1"
|
|
77
78
|
},
|
|
79
|
+
"overrides": {
|
|
80
|
+
"glob": "^9.0.0"
|
|
81
|
+
},
|
|
78
82
|
"peerDependencies": {
|
|
79
83
|
"@typescript-eslint/eslint-plugin": "7.18.0",
|
|
80
84
|
"@typescript-eslint/parser": "7.18.0",
|
|
@@ -15,7 +15,7 @@ import { Binding } from "../types";
|
|
|
15
15
|
|
|
16
16
|
export const peprIgnoreNamespaces: string[] = ["kube-system", "pepr-system"];
|
|
17
17
|
|
|
18
|
-
const validateRule = (binding: Binding, isMutateWebhook: boolean): V1RuleWithOperations | undefined => {
|
|
18
|
+
export const validateRule = (binding: Binding, isMutateWebhook: boolean): V1RuleWithOperations | undefined => {
|
|
19
19
|
const { event, kind, isMutate, isValidate } = binding;
|
|
20
20
|
|
|
21
21
|
// Skip invalid bindings based on webhook type
|
|
@@ -5,17 +5,15 @@ import { dumpYaml } from "@kubernetes/client-node";
|
|
|
5
5
|
import { clusterRole } from "../rbac";
|
|
6
6
|
import { promises as fs } from "fs";
|
|
7
7
|
|
|
8
|
-
type
|
|
8
|
+
type ChartOverrides = {
|
|
9
9
|
apiToken: string;
|
|
10
10
|
capabilities: CapabilityExport[];
|
|
11
11
|
config: ModuleConfig;
|
|
12
12
|
hash: string;
|
|
13
13
|
name: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type ChartOverrides = CommonOverrideValues & {
|
|
17
14
|
image: string;
|
|
18
15
|
};
|
|
16
|
+
|
|
19
17
|
// Helm Chart overrides file (values.yaml) generated from assets
|
|
20
18
|
export async function overridesFile(
|
|
21
19
|
{ hash, name, image, config, apiToken, capabilities }: ChartOverrides,
|
|
@@ -34,7 +32,7 @@ export async function overridesFile(
|
|
|
34
32
|
hash,
|
|
35
33
|
namespace: {
|
|
36
34
|
annotations: {},
|
|
37
|
-
labels: {
|
|
35
|
+
labels: config.customLabels?.namespace ?? {
|
|
38
36
|
"pepr.dev": "",
|
|
39
37
|
},
|
|
40
38
|
},
|
|
@@ -16,6 +16,12 @@ import { StoreController } from "./store";
|
|
|
16
16
|
import { AdmissionRequest } from "../types";
|
|
17
17
|
import { karForMutate, karForValidate, KubeAdmissionReview } from "./index.util";
|
|
18
18
|
|
|
19
|
+
export interface ControllerHooks {
|
|
20
|
+
beforeHook?: (req: AdmissionRequest) => void;
|
|
21
|
+
afterHook?: (res: MutateResponse | ValidateResponse) => void;
|
|
22
|
+
onReady?: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
if (!process.env.PEPR_NODE_WARNINGS) {
|
|
20
26
|
process.removeAllListeners("warning");
|
|
21
27
|
}
|
|
@@ -39,13 +45,8 @@ export class Controller {
|
|
|
39
45
|
readonly #beforeHook?: (req: AdmissionRequest) => void;
|
|
40
46
|
readonly #afterHook?: (res: MutateResponse | ValidateResponse) => void;
|
|
41
47
|
|
|
42
|
-
constructor(
|
|
43
|
-
|
|
44
|
-
capabilities: Capability[],
|
|
45
|
-
beforeHook?: (req: AdmissionRequest) => void,
|
|
46
|
-
afterHook?: (res: MutateResponse | ValidateResponse) => void,
|
|
47
|
-
onReady?: () => void,
|
|
48
|
-
) {
|
|
48
|
+
constructor(config: ModuleConfig, capabilities: Capability[], hooks: ControllerHooks = {}) {
|
|
49
|
+
const { beforeHook, afterHook, onReady } = hooks;
|
|
49
50
|
this.#config = config;
|
|
50
51
|
this.#capabilities = capabilities;
|
|
51
52
|
|
package/src/lib/core/module.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
import { clone } from "ramda";
|
|
4
4
|
import { Capability } from "./capability";
|
|
5
|
-
import { Controller } from "../controller";
|
|
5
|
+
import { Controller, ControllerHooks } from "../controller";
|
|
6
6
|
import { ValidateError } from "../errors";
|
|
7
7
|
import { MutateResponse, ValidateResponse, WebhookIgnore } from "../k8s";
|
|
8
8
|
import { CapabilityExport, AdmissionRequest } from "../types";
|
|
@@ -114,17 +114,23 @@ export class PeprModule {
|
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
const controllerHooks: ControllerHooks = {
|
|
118
|
+
beforeHook: opts.beforeHook,
|
|
119
|
+
afterHook: opts.afterHook,
|
|
120
|
+
onReady: (): void => {
|
|
121
|
+
// Wait for the controller to be ready before setting up watches
|
|
122
|
+
if (isWatchMode() || isDevMode()) {
|
|
123
|
+
try {
|
|
124
|
+
setupWatch(capabilities, resolveIgnoreNamespaces(pepr?.alwaysIgnore?.namespaces));
|
|
125
|
+
} catch (e) {
|
|
126
|
+
Log.error(e, "Error setting up watch");
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
125
129
|
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
this.#controller = new Controller(config, capabilities, controllerHooks);
|
|
128
134
|
|
|
129
135
|
// Stop processing if deferStart is set to true
|
|
130
136
|
if (opts.deferStart) {
|
|
@@ -66,9 +66,7 @@ export class MetricsCollector {
|
|
|
66
66
|
#addMetric = <T extends Counter<string> | Gauge<string> | Summary<string>>(
|
|
67
67
|
collection: Map<string, T>,
|
|
68
68
|
MetricType: new (args: MetricArgs) => T,
|
|
69
|
-
name:
|
|
70
|
-
help: string,
|
|
71
|
-
labelNames?: string[],
|
|
69
|
+
{ name, help, labelNames }: Omit<MetricArgs, "registers">,
|
|
72
70
|
): void => {
|
|
73
71
|
if (collection.has(this.#getMetricName(name))) {
|
|
74
72
|
Log.debug(`Metric for ${name} already exists`, loggingPrefix);
|
|
@@ -86,15 +84,15 @@ export class MetricsCollector {
|
|
|
86
84
|
};
|
|
87
85
|
|
|
88
86
|
addCounter = (name: string, help: string): void => {
|
|
89
|
-
this.#addMetric(this.#counters, promClient.Counter, name, help, []);
|
|
87
|
+
this.#addMetric(this.#counters, promClient.Counter, { name, help, labelNames: [] });
|
|
90
88
|
};
|
|
91
89
|
|
|
92
90
|
addSummary = (name: string, help: string): void => {
|
|
93
|
-
this.#addMetric(this.#summaries, promClient.Summary, name, help, []);
|
|
91
|
+
this.#addMetric(this.#summaries, promClient.Summary, { name, help, labelNames: [] });
|
|
94
92
|
};
|
|
95
93
|
|
|
96
94
|
addGauge = (name: string, help: string, labelNames?: string[]): void => {
|
|
97
|
-
this.#addMetric(this.#gauges, promClient.Gauge, name, help, labelNames);
|
|
95
|
+
this.#addMetric(this.#gauges, promClient.Gauge, { name, help, labelNames });
|
|
98
96
|
};
|
|
99
97
|
|
|
100
98
|
incCounter = (name: string): void => {
|