pepr 0.3.2 → 0.4.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/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1420 -0
- package/dist/controller.js +157 -0
- package/dist/{src/lib → lib}/capability.d.ts +1 -1
- package/dist/lib/capability.d.ts.map +1 -0
- package/dist/lib/controller.d.ts.map +1 -0
- package/dist/{src/lib → lib}/fetch.d.ts +1 -2
- package/dist/lib/fetch.d.ts.map +1 -0
- package/dist/{src/lib → lib}/filter.d.ts +1 -1
- package/dist/lib/filter.d.ts.map +1 -0
- package/dist/lib/k8s/index.d.ts.map +1 -0
- package/dist/lib/k8s/kinds.d.ts.map +1 -0
- package/dist/lib/k8s/tls.d.ts.map +1 -0
- package/dist/lib/k8s/types.d.ts.map +1 -0
- package/dist/{src/lib → lib}/k8s/upstream.d.ts +2 -2
- package/dist/lib/k8s/upstream.d.ts.map +1 -0
- package/dist/{src/lib → lib}/k8s/webhook.d.ts +1 -1
- package/dist/lib/k8s/webhook.d.ts.map +1 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/module.d.ts.map +1 -0
- package/dist/lib/processor.d.ts.map +1 -0
- package/dist/{src/lib → lib}/request.d.ts +1 -1
- package/dist/lib/request.d.ts.map +1 -0
- package/dist/{src/lib → lib}/types.d.ts +5 -1
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/{src/lib/index.d.ts → lib.d.ts} +8 -8
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +1150 -0
- package/dist/lib.js.map +7 -0
- package/package.json +8 -12
- package/src/cli.ts +37 -0
- package/src/lib/capability.ts +2 -1
- package/src/lib/controller.ts +15 -1
- package/src/lib/fetch.ts +3 -2
- package/src/lib/filter.ts +1 -1
- package/src/lib/k8s/upstream.ts +2 -2
- package/src/lib/k8s/webhook.ts +8 -3
- package/src/lib/module.ts +3 -2
- package/src/lib/processor.ts +2 -2
- package/src/lib/request.ts +4 -4
- package/src/lib/types.ts +6 -1
- package/src/{lib/index.ts → lib.ts} +7 -7
- package/dist/package.json +0 -66
- package/dist/src/cli/banner.js +0 -70
- package/dist/src/cli/build.js +0 -120
- package/dist/src/cli/capability.js +0 -14
- package/dist/src/cli/deploy.js +0 -54
- package/dist/src/cli/dev.js +0 -114
- package/dist/src/cli/index.js +0 -35
- package/dist/src/cli/init/index.js +0 -81
- package/dist/src/cli/init/templates/.prettierrc.json +0 -13
- package/dist/src/cli/init/templates/capabilities/hello-pepr.samples.json +0 -115
- package/dist/src/cli/init/templates/data.json +0 -1
- package/dist/src/cli/init/templates/pepr.code-snippets.json +0 -21
- package/dist/src/cli/init/templates/tsconfig.module.json +0 -12
- package/dist/src/cli/init/templates.js +0 -96
- package/dist/src/cli/init/utils.js +0 -56
- package/dist/src/cli/init/walkthrough.js +0 -84
- package/dist/src/cli/root.js +0 -21
- package/dist/src/cli/run.js +0 -58
- package/dist/src/cli/test.js +0 -50
- package/dist/src/cli/update.js +0 -58
- package/dist/src/lib/capability.d.ts.map +0 -1
- package/dist/src/lib/capability.js +0 -125
- package/dist/src/lib/controller.d.ts.map +0 -1
- package/dist/src/lib/controller.js +0 -108
- package/dist/src/lib/fetch.d.ts.map +0 -1
- package/dist/src/lib/fetch.js +0 -92
- package/dist/src/lib/filter.d.ts.map +0 -1
- package/dist/src/lib/filter.js +0 -77
- package/dist/src/lib/index.d.ts.map +0 -1
- package/dist/src/lib/index.js +0 -26
- package/dist/src/lib/k8s/index.d.ts.map +0 -1
- package/dist/src/lib/k8s/index.js +0 -39
- package/dist/src/lib/k8s/kinds.d.ts.map +0 -1
- package/dist/src/lib/k8s/kinds.js +0 -447
- package/dist/src/lib/k8s/tls.d.ts.map +0 -1
- package/dist/src/lib/k8s/tls.js +0 -74
- package/dist/src/lib/k8s/types.d.ts.map +0 -1
- package/dist/src/lib/k8s/types.js +0 -20
- package/dist/src/lib/k8s/upstream.d.ts.map +0 -1
- package/dist/src/lib/k8s/upstream.js +0 -50
- package/dist/src/lib/k8s/webhook.d.ts.map +0 -1
- package/dist/src/lib/k8s/webhook.js +0 -502
- package/dist/src/lib/logger.d.ts.map +0 -1
- package/dist/src/lib/logger.js +0 -125
- package/dist/src/lib/module.d.ts.map +0 -1
- package/dist/src/lib/module.js +0 -43
- package/dist/src/lib/processor.d.ts.map +0 -1
- package/dist/src/lib/processor.js +0 -85
- package/dist/src/lib/request.d.ts.map +0 -1
- package/dist/src/lib/request.js +0 -124
- package/dist/src/lib/types.d.ts.map +0 -1
- package/dist/src/lib/types.js +0 -34
- /package/dist/{src/lib → lib}/controller.d.ts +0 -0
- /package/dist/{src/lib → lib}/k8s/index.d.ts +0 -0
- /package/dist/{src/lib → lib}/k8s/kinds.d.ts +0 -0
- /package/dist/{src/lib → lib}/k8s/tls.d.ts +0 -0
- /package/dist/{src/lib → lib}/k8s/types.d.ts +0 -0
- /package/dist/{src/lib → lib}/logger.d.ts +0 -0
- /package/dist/{src/lib → lib}/module.d.ts +0 -0
- /package/dist/{src/lib → lib}/processor.d.ts +0 -0
|
@@ -1,502 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.Webhook = void 0;
|
|
9
|
-
const client_node_1 = require("@kubernetes/client-node");
|
|
10
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
-
const zlib_1 = require("zlib");
|
|
12
|
-
const logger_1 = __importDefault(require("../logger"));
|
|
13
|
-
const tls_1 = require("./tls");
|
|
14
|
-
const peprIgnore = {
|
|
15
|
-
key: "pepr.dev",
|
|
16
|
-
operator: "NotIn",
|
|
17
|
-
values: ["ignore"],
|
|
18
|
-
};
|
|
19
|
-
class Webhook {
|
|
20
|
-
get tls() {
|
|
21
|
-
return this._tls;
|
|
22
|
-
}
|
|
23
|
-
constructor(config, host) {
|
|
24
|
-
this.config = config;
|
|
25
|
-
this.host = host;
|
|
26
|
-
this.name = `pepr-${config.uuid}`;
|
|
27
|
-
this.image = `ghcr.io/defenseunicorns/pepr/controller:v${config.version}`;
|
|
28
|
-
// Generate the ephemeral tls things
|
|
29
|
-
this._tls = (0, tls_1.genTLS)(this.host || `${this.name}.pepr-system.svc`);
|
|
30
|
-
}
|
|
31
|
-
/** Generate the pepr-system namespace */
|
|
32
|
-
namespace() {
|
|
33
|
-
return {
|
|
34
|
-
apiVersion: "v1",
|
|
35
|
-
kind: "Namespace",
|
|
36
|
-
metadata: { name: "pepr-system" },
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Grants the controller access to cluster resources beyond the mutating webhook.
|
|
41
|
-
*
|
|
42
|
-
* @todo: should dynamically generate this based on resources used by the module. will also need to explore how this should work for multiple modules.
|
|
43
|
-
* @returns
|
|
44
|
-
*/
|
|
45
|
-
clusterRole() {
|
|
46
|
-
return {
|
|
47
|
-
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
48
|
-
kind: "ClusterRole",
|
|
49
|
-
metadata: { name: this.name },
|
|
50
|
-
rules: [
|
|
51
|
-
{
|
|
52
|
-
// @todo: make this configurable
|
|
53
|
-
apiGroups: ["*"],
|
|
54
|
-
resources: ["*"],
|
|
55
|
-
verbs: ["create", "delete", "get", "list", "patch", "update", "watch"],
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
clusterRoleBinding() {
|
|
61
|
-
const name = this.name;
|
|
62
|
-
return {
|
|
63
|
-
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
64
|
-
kind: "ClusterRoleBinding",
|
|
65
|
-
metadata: { name },
|
|
66
|
-
roleRef: {
|
|
67
|
-
apiGroup: "rbac.authorization.k8s.io",
|
|
68
|
-
kind: "ClusterRole",
|
|
69
|
-
name,
|
|
70
|
-
},
|
|
71
|
-
subjects: [
|
|
72
|
-
{
|
|
73
|
-
kind: "ServiceAccount",
|
|
74
|
-
name,
|
|
75
|
-
namespace: "pepr-system",
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
serviceAccount() {
|
|
81
|
-
return {
|
|
82
|
-
apiVersion: "v1",
|
|
83
|
-
kind: "ServiceAccount",
|
|
84
|
-
metadata: {
|
|
85
|
-
name: this.name,
|
|
86
|
-
namespace: "pepr-system",
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
tlsSecret() {
|
|
91
|
-
return {
|
|
92
|
-
apiVersion: "v1",
|
|
93
|
-
kind: "Secret",
|
|
94
|
-
metadata: {
|
|
95
|
-
name: `${this.name}-tls`,
|
|
96
|
-
namespace: "pepr-system",
|
|
97
|
-
},
|
|
98
|
-
type: "kubernetes.io/tls",
|
|
99
|
-
data: {
|
|
100
|
-
"tls.crt": this._tls.crt,
|
|
101
|
-
"tls.key": this._tls.key,
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
mutatingWebhook() {
|
|
106
|
-
const { name } = this;
|
|
107
|
-
const ignore = [peprIgnore];
|
|
108
|
-
// Add any namespaces to ignore
|
|
109
|
-
if (this.config.alwaysIgnore.namespaces && this.config.alwaysIgnore.namespaces.length > 0) {
|
|
110
|
-
ignore.push({
|
|
111
|
-
key: "kubernetes.io/metadata.name",
|
|
112
|
-
operator: "NotIn",
|
|
113
|
-
values: this.config.alwaysIgnore.namespaces,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const clientConfig = {
|
|
117
|
-
caBundle: this._tls.ca,
|
|
118
|
-
};
|
|
119
|
-
// If a host is specified, use that with a port of 3000
|
|
120
|
-
if (this.host) {
|
|
121
|
-
clientConfig.url = `https://${this.host}:3000/mutate`;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
// Otherwise, use the service
|
|
125
|
-
clientConfig.service = {
|
|
126
|
-
name: this.name,
|
|
127
|
-
namespace: "pepr-system",
|
|
128
|
-
path: "/mutate",
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
apiVersion: "admissionregistration.k8s.io/v1",
|
|
133
|
-
kind: "MutatingWebhookConfiguration",
|
|
134
|
-
metadata: { name },
|
|
135
|
-
webhooks: [
|
|
136
|
-
{
|
|
137
|
-
name: `${name}.pepr.dev`,
|
|
138
|
-
admissionReviewVersions: ["v1", "v1beta1"],
|
|
139
|
-
clientConfig,
|
|
140
|
-
failurePolicy: "Ignore",
|
|
141
|
-
matchPolicy: "Equivalent",
|
|
142
|
-
timeoutSeconds: 15,
|
|
143
|
-
namespaceSelector: {
|
|
144
|
-
matchExpressions: ignore,
|
|
145
|
-
},
|
|
146
|
-
objectSelector: {
|
|
147
|
-
matchExpressions: ignore,
|
|
148
|
-
},
|
|
149
|
-
// @todo: make this configurable
|
|
150
|
-
rules: [
|
|
151
|
-
{
|
|
152
|
-
apiGroups: ["*"],
|
|
153
|
-
apiVersions: ["*"],
|
|
154
|
-
operations: ["CREATE", "UPDATE", "DELETE"],
|
|
155
|
-
resources: ["*/*"],
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
// @todo: track side effects state
|
|
159
|
-
sideEffects: "None",
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
deployment(hash) {
|
|
165
|
-
return {
|
|
166
|
-
apiVersion: "apps/v1",
|
|
167
|
-
kind: "Deployment",
|
|
168
|
-
metadata: {
|
|
169
|
-
name: this.name,
|
|
170
|
-
namespace: "pepr-system",
|
|
171
|
-
labels: {
|
|
172
|
-
app: this.name,
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
spec: {
|
|
176
|
-
replicas: 2,
|
|
177
|
-
selector: {
|
|
178
|
-
matchLabels: {
|
|
179
|
-
app: this.name,
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
template: {
|
|
183
|
-
metadata: {
|
|
184
|
-
labels: {
|
|
185
|
-
app: this.name,
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
spec: {
|
|
189
|
-
priorityClassName: "system-node-critical",
|
|
190
|
-
serviceAccountName: this.name,
|
|
191
|
-
containers: [
|
|
192
|
-
{
|
|
193
|
-
name: "server",
|
|
194
|
-
image: this.image,
|
|
195
|
-
imagePullPolicy: "IfNotPresent",
|
|
196
|
-
command: ["node", "/app/node_modules/pepr/dist/src/cli/run.js", hash],
|
|
197
|
-
livenessProbe: {
|
|
198
|
-
httpGet: {
|
|
199
|
-
path: "/healthz",
|
|
200
|
-
port: 3000,
|
|
201
|
-
scheme: "HTTPS",
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
ports: [
|
|
205
|
-
{
|
|
206
|
-
containerPort: 3000,
|
|
207
|
-
},
|
|
208
|
-
],
|
|
209
|
-
resources: {
|
|
210
|
-
requests: {
|
|
211
|
-
memory: "64Mi",
|
|
212
|
-
cpu: "100m",
|
|
213
|
-
},
|
|
214
|
-
limits: {
|
|
215
|
-
memory: "256Mi",
|
|
216
|
-
cpu: "500m",
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
volumeMounts: [
|
|
220
|
-
{
|
|
221
|
-
name: "tls-certs",
|
|
222
|
-
mountPath: "/etc/certs",
|
|
223
|
-
readOnly: true,
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: "module",
|
|
227
|
-
mountPath: `/app/load`,
|
|
228
|
-
readOnly: true,
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
volumes: [
|
|
234
|
-
{
|
|
235
|
-
name: "tls-certs",
|
|
236
|
-
secret: {
|
|
237
|
-
secretName: `${this.name}-tls`,
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
name: "module",
|
|
242
|
-
secret: {
|
|
243
|
-
secretName: `${this.name}-module`,
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
],
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
/** Only permit the kube-system ns ingress access to the controller */
|
|
253
|
-
networkPolicy() {
|
|
254
|
-
return {
|
|
255
|
-
apiVersion: "networking.k8s.io/v1",
|
|
256
|
-
kind: "NetworkPolicy",
|
|
257
|
-
metadata: {
|
|
258
|
-
name: this.name,
|
|
259
|
-
namespace: "pepr-system",
|
|
260
|
-
},
|
|
261
|
-
spec: {
|
|
262
|
-
podSelector: {
|
|
263
|
-
matchLabels: {
|
|
264
|
-
app: this.name,
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
policyTypes: ["Ingress"],
|
|
268
|
-
ingress: [
|
|
269
|
-
{
|
|
270
|
-
from: [
|
|
271
|
-
{
|
|
272
|
-
namespaceSelector: {
|
|
273
|
-
matchLabels: {
|
|
274
|
-
"kubernetes.io/metadata.name": "kube-system",
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
],
|
|
279
|
-
ports: [
|
|
280
|
-
{
|
|
281
|
-
protocol: "TCP",
|
|
282
|
-
port: 443,
|
|
283
|
-
},
|
|
284
|
-
],
|
|
285
|
-
},
|
|
286
|
-
],
|
|
287
|
-
},
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
service() {
|
|
291
|
-
return {
|
|
292
|
-
apiVersion: "v1",
|
|
293
|
-
kind: "Service",
|
|
294
|
-
metadata: {
|
|
295
|
-
name: this.name,
|
|
296
|
-
namespace: "pepr-system",
|
|
297
|
-
},
|
|
298
|
-
spec: {
|
|
299
|
-
selector: {
|
|
300
|
-
app: this.name,
|
|
301
|
-
},
|
|
302
|
-
ports: [
|
|
303
|
-
{
|
|
304
|
-
port: 443,
|
|
305
|
-
targetPort: 3000,
|
|
306
|
-
},
|
|
307
|
-
],
|
|
308
|
-
},
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
moduleSecret(data, hash) {
|
|
312
|
-
// Compress the data
|
|
313
|
-
const compressed = (0, zlib_1.gzipSync)(data);
|
|
314
|
-
const path = `module-${hash}.js.gz`;
|
|
315
|
-
return {
|
|
316
|
-
apiVersion: "v1",
|
|
317
|
-
kind: "Secret",
|
|
318
|
-
metadata: {
|
|
319
|
-
name: `${this.name}-module`,
|
|
320
|
-
namespace: "pepr-system",
|
|
321
|
-
},
|
|
322
|
-
type: "Opaque",
|
|
323
|
-
data: {
|
|
324
|
-
[path]: compressed.toString("base64"),
|
|
325
|
-
},
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
zarfYaml(path) {
|
|
329
|
-
const zarfCfg = {
|
|
330
|
-
kind: "ZarfPackageConfig",
|
|
331
|
-
metadata: {
|
|
332
|
-
name: this.name,
|
|
333
|
-
description: `Pepr Module: ${this.config.description}`,
|
|
334
|
-
url: "https://github.com/defenseunicorns/pepr",
|
|
335
|
-
},
|
|
336
|
-
components: [
|
|
337
|
-
{
|
|
338
|
-
name: "module",
|
|
339
|
-
required: true,
|
|
340
|
-
manifests: [
|
|
341
|
-
{
|
|
342
|
-
name: "module",
|
|
343
|
-
namespace: "pepr-system",
|
|
344
|
-
files: [path],
|
|
345
|
-
},
|
|
346
|
-
],
|
|
347
|
-
images: [this.image],
|
|
348
|
-
},
|
|
349
|
-
],
|
|
350
|
-
};
|
|
351
|
-
return (0, client_node_1.dumpYaml)(zarfCfg, { noRefs: true });
|
|
352
|
-
}
|
|
353
|
-
allYaml(code) {
|
|
354
|
-
// Generate a hash of the code
|
|
355
|
-
const hash = crypto_1.default.createHash("sha256").update(code).digest("hex");
|
|
356
|
-
const resources = [
|
|
357
|
-
this.namespace(),
|
|
358
|
-
this.networkPolicy(),
|
|
359
|
-
this.clusterRole(),
|
|
360
|
-
this.clusterRoleBinding(),
|
|
361
|
-
this.serviceAccount(),
|
|
362
|
-
this.tlsSecret(),
|
|
363
|
-
this.mutatingWebhook(),
|
|
364
|
-
this.deployment(hash),
|
|
365
|
-
this.service(),
|
|
366
|
-
this.moduleSecret(code, hash),
|
|
367
|
-
];
|
|
368
|
-
// Convert the resources to a single YAML string
|
|
369
|
-
return resources.map(r => (0, client_node_1.dumpYaml)(r, { noRefs: true })).join("---\n");
|
|
370
|
-
}
|
|
371
|
-
async deploy(code) {
|
|
372
|
-
logger_1.default.info("Establishing connection to Kubernetes");
|
|
373
|
-
const namespace = "pepr-system";
|
|
374
|
-
const hash = crypto_1.default.createHash("sha256").update(code).digest("hex");
|
|
375
|
-
// Deploy the resources using the k8s API
|
|
376
|
-
const kubeConfig = new client_node_1.KubeConfig();
|
|
377
|
-
kubeConfig.loadFromDefault();
|
|
378
|
-
const coreV1Api = kubeConfig.makeApiClient(client_node_1.CoreV1Api);
|
|
379
|
-
const rbacApi = kubeConfig.makeApiClient(client_node_1.RbacAuthorizationV1Api);
|
|
380
|
-
const appsApi = kubeConfig.makeApiClient(client_node_1.AppsV1Api);
|
|
381
|
-
const admissionApi = kubeConfig.makeApiClient(client_node_1.AdmissionregistrationV1Api);
|
|
382
|
-
const networkApi = kubeConfig.makeApiClient(client_node_1.NetworkingV1Api);
|
|
383
|
-
const ns = this.namespace();
|
|
384
|
-
try {
|
|
385
|
-
logger_1.default.info("Checking for namespace");
|
|
386
|
-
await coreV1Api.readNamespace(namespace);
|
|
387
|
-
}
|
|
388
|
-
catch (e) {
|
|
389
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
390
|
-
logger_1.default.info("Creating namespace");
|
|
391
|
-
await coreV1Api.createNamespace(ns);
|
|
392
|
-
}
|
|
393
|
-
const wh = this.mutatingWebhook();
|
|
394
|
-
try {
|
|
395
|
-
logger_1.default.info("Creating mutating webhook");
|
|
396
|
-
await admissionApi.createMutatingWebhookConfiguration(wh);
|
|
397
|
-
}
|
|
398
|
-
catch (e) {
|
|
399
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
400
|
-
logger_1.default.info("Removing and re-creating mutating webhook");
|
|
401
|
-
await admissionApi.deleteMutatingWebhookConfiguration(wh.metadata?.name ?? "");
|
|
402
|
-
await admissionApi.createMutatingWebhookConfiguration(wh);
|
|
403
|
-
}
|
|
404
|
-
// If a host is specified, we don't need to deploy the rest of the resources
|
|
405
|
-
if (this.host) {
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
const netpol = this.networkPolicy();
|
|
409
|
-
try {
|
|
410
|
-
logger_1.default.info("Checking for network policy");
|
|
411
|
-
await networkApi.readNamespacedNetworkPolicy(netpol.metadata?.name ?? "", namespace);
|
|
412
|
-
}
|
|
413
|
-
catch (e) {
|
|
414
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
415
|
-
logger_1.default.info("Creating network policy");
|
|
416
|
-
await networkApi.createNamespacedNetworkPolicy(namespace, netpol);
|
|
417
|
-
}
|
|
418
|
-
const crb = this.clusterRoleBinding();
|
|
419
|
-
try {
|
|
420
|
-
logger_1.default.info("Creating cluster role binding");
|
|
421
|
-
await rbacApi.createClusterRoleBinding(crb);
|
|
422
|
-
}
|
|
423
|
-
catch (e) {
|
|
424
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
425
|
-
logger_1.default.info("Removing and re-creating cluster role binding");
|
|
426
|
-
await rbacApi.deleteClusterRoleBinding(crb.metadata?.name ?? "");
|
|
427
|
-
await rbacApi.createClusterRoleBinding(crb);
|
|
428
|
-
}
|
|
429
|
-
const cr = this.clusterRole();
|
|
430
|
-
try {
|
|
431
|
-
logger_1.default.info("Creating cluster role");
|
|
432
|
-
await rbacApi.createClusterRole(cr);
|
|
433
|
-
}
|
|
434
|
-
catch (e) {
|
|
435
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
436
|
-
logger_1.default.info("Removing and re-creating the cluster role");
|
|
437
|
-
try {
|
|
438
|
-
await rbacApi.deleteClusterRole(cr.metadata?.name ?? "");
|
|
439
|
-
await rbacApi.createClusterRole(cr);
|
|
440
|
-
}
|
|
441
|
-
catch (e) {
|
|
442
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
const sa = this.serviceAccount();
|
|
446
|
-
try {
|
|
447
|
-
logger_1.default.info("Creating service account");
|
|
448
|
-
await coreV1Api.createNamespacedServiceAccount(namespace, sa);
|
|
449
|
-
}
|
|
450
|
-
catch (e) {
|
|
451
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
452
|
-
logger_1.default.info("Removing and re-creating service account");
|
|
453
|
-
await coreV1Api.deleteNamespacedServiceAccount(sa.metadata?.name ?? "", namespace);
|
|
454
|
-
await coreV1Api.createNamespacedServiceAccount(namespace, sa);
|
|
455
|
-
}
|
|
456
|
-
const mod = this.moduleSecret(code, hash);
|
|
457
|
-
try {
|
|
458
|
-
logger_1.default.info("Creating module secret");
|
|
459
|
-
await coreV1Api.createNamespacedSecret(namespace, mod);
|
|
460
|
-
}
|
|
461
|
-
catch (e) {
|
|
462
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
463
|
-
logger_1.default.info("Removing and re-creating module secret");
|
|
464
|
-
await coreV1Api.deleteNamespacedSecret(mod.metadata?.name ?? "", namespace);
|
|
465
|
-
await coreV1Api.createNamespacedSecret(namespace, mod);
|
|
466
|
-
}
|
|
467
|
-
const svc = this.service();
|
|
468
|
-
try {
|
|
469
|
-
logger_1.default.info("Creating service");
|
|
470
|
-
await coreV1Api.createNamespacedService(namespace, svc);
|
|
471
|
-
}
|
|
472
|
-
catch (e) {
|
|
473
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
474
|
-
logger_1.default.info("Removing and re-creating service");
|
|
475
|
-
await coreV1Api.deleteNamespacedService(svc.metadata?.name ?? "", namespace);
|
|
476
|
-
await coreV1Api.createNamespacedService(namespace, svc);
|
|
477
|
-
}
|
|
478
|
-
const tls = this.tlsSecret();
|
|
479
|
-
try {
|
|
480
|
-
logger_1.default.info("Creating TLS secret");
|
|
481
|
-
await coreV1Api.createNamespacedSecret(namespace, tls);
|
|
482
|
-
}
|
|
483
|
-
catch (e) {
|
|
484
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
485
|
-
logger_1.default.info("Removing and re-creating TLS secret");
|
|
486
|
-
await coreV1Api.deleteNamespacedSecret(tls.metadata?.name ?? "", namespace);
|
|
487
|
-
await coreV1Api.createNamespacedSecret(namespace, tls);
|
|
488
|
-
}
|
|
489
|
-
const dep = this.deployment(hash);
|
|
490
|
-
try {
|
|
491
|
-
logger_1.default.info("Creating deployment");
|
|
492
|
-
await appsApi.createNamespacedDeployment(namespace, dep);
|
|
493
|
-
}
|
|
494
|
-
catch (e) {
|
|
495
|
-
logger_1.default.debug(e instanceof client_node_1.HttpError ? e.body : e);
|
|
496
|
-
logger_1.default.info("Removing and re-creating deployment");
|
|
497
|
-
await appsApi.deleteNamespacedDeployment(dep.metadata?.name ?? "", namespace);
|
|
498
|
-
await appsApi.createNamespacedDeployment(namespace, dep);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
exports.Webhook = Webhook;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/lib/logger.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACV;AA8BD;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,SAAS,CAAW;IAE5B;;;OAGG;gBACS,QAAQ,EAAE,QAAQ;IAI9B;;;OAGG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAK1C;;;OAGG;IACI,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAIlD;;;OAGG;IACI,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAIjD;;;OAGG;IACI,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAIjD;;;OAGG;IACI,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAIlD;;;;OAIG;IACH,OAAO,CAAC,GAAG;IAwBX,OAAO,CAAC,QAAQ;CAGjB;AAED,iEAAiE;AACjE,QAAA,MAAM,GAAG,QAA4B,CAAC;AAItC,eAAe,GAAG,CAAC"}
|
package/dist/src/lib/logger.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.Logger = exports.LogLevel = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* Enumeration representing different logging levels.
|
|
8
|
-
*/
|
|
9
|
-
var LogLevel;
|
|
10
|
-
(function (LogLevel) {
|
|
11
|
-
LogLevel[LogLevel["debug"] = 0] = "debug";
|
|
12
|
-
LogLevel[LogLevel["info"] = 1] = "info";
|
|
13
|
-
LogLevel[LogLevel["warn"] = 2] = "warn";
|
|
14
|
-
LogLevel[LogLevel["error"] = 3] = "error";
|
|
15
|
-
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
16
|
-
var ConsoleColors;
|
|
17
|
-
(function (ConsoleColors) {
|
|
18
|
-
ConsoleColors["Reset"] = "\u001B[0m";
|
|
19
|
-
ConsoleColors["Bright"] = "\u001B[1m";
|
|
20
|
-
ConsoleColors["Dim"] = "\u001B[2m";
|
|
21
|
-
ConsoleColors["Underscore"] = "\u001B[4m";
|
|
22
|
-
ConsoleColors["Blink"] = "\u001B[5m";
|
|
23
|
-
ConsoleColors["Reverse"] = "\u001B[7m";
|
|
24
|
-
ConsoleColors["Hidden"] = "\u001B[8m";
|
|
25
|
-
ConsoleColors["FgBlack"] = "\u001B[30m";
|
|
26
|
-
ConsoleColors["FgRed"] = "\u001B[31m";
|
|
27
|
-
ConsoleColors["FgGreen"] = "\u001B[32m";
|
|
28
|
-
ConsoleColors["FgYellow"] = "\u001B[33m";
|
|
29
|
-
ConsoleColors["FgBlue"] = "\u001B[34m";
|
|
30
|
-
ConsoleColors["FgMagenta"] = "\u001B[35m";
|
|
31
|
-
ConsoleColors["FgCyan"] = "\u001B[36m";
|
|
32
|
-
ConsoleColors["FgWhite"] = "\u001B[37m";
|
|
33
|
-
ConsoleColors["BgBlack"] = "\u001B[40m";
|
|
34
|
-
ConsoleColors["BgRed"] = "\u001B[41m";
|
|
35
|
-
ConsoleColors["BgGreen"] = "\u001B[42m";
|
|
36
|
-
ConsoleColors["BgYellow"] = "\u001B[43m";
|
|
37
|
-
ConsoleColors["BgBlue"] = "\u001B[44m";
|
|
38
|
-
ConsoleColors["BgMagenta"] = "\u001B[45m";
|
|
39
|
-
ConsoleColors["BgCyan"] = "\u001B[46m";
|
|
40
|
-
ConsoleColors["BgWhite"] = "\u001B[47m";
|
|
41
|
-
})(ConsoleColors || (ConsoleColors = {}));
|
|
42
|
-
/**
|
|
43
|
-
* Simple logger class that logs messages at different log levels.
|
|
44
|
-
*/
|
|
45
|
-
class Logger {
|
|
46
|
-
/**
|
|
47
|
-
* Create a new logger instance.
|
|
48
|
-
* @param logLevel - The minimum log level to log messages for.
|
|
49
|
-
*/
|
|
50
|
-
constructor(logLevel) {
|
|
51
|
-
this._logLevel = logLevel;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Change the log level of the logger.
|
|
55
|
-
* @param logLevel - The log level to log the message at.
|
|
56
|
-
*/
|
|
57
|
-
SetLogLevel(logLevel) {
|
|
58
|
-
this._logLevel = LogLevel[logLevel];
|
|
59
|
-
this.debug(`Log level set to ${logLevel}`);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Log a debug message.
|
|
63
|
-
* @param message - The message to log.
|
|
64
|
-
*/
|
|
65
|
-
debug(message, prefix) {
|
|
66
|
-
this.log(LogLevel.debug, message, prefix);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Log an info message.
|
|
70
|
-
* @param message - The message to log.
|
|
71
|
-
*/
|
|
72
|
-
info(message, prefix) {
|
|
73
|
-
this.log(LogLevel.info, message, prefix);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Log a warning message.
|
|
77
|
-
* @param message - The message to log.
|
|
78
|
-
*/
|
|
79
|
-
warn(message, prefix) {
|
|
80
|
-
this.log(LogLevel.warn, message, prefix);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Log an error message.
|
|
84
|
-
* @param message - The message to log.
|
|
85
|
-
*/
|
|
86
|
-
error(message, prefix) {
|
|
87
|
-
this.log(LogLevel.error, message, prefix);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Log a message at the specified log level.
|
|
91
|
-
* @param logLevel - The log level of the message.
|
|
92
|
-
* @param message - The message to log.
|
|
93
|
-
*/
|
|
94
|
-
log(logLevel, message, callerPrefix = "") {
|
|
95
|
-
const color = {
|
|
96
|
-
[LogLevel.debug]: ConsoleColors.FgBlack,
|
|
97
|
-
[LogLevel.info]: ConsoleColors.FgCyan,
|
|
98
|
-
[LogLevel.warn]: ConsoleColors.FgYellow,
|
|
99
|
-
[LogLevel.error]: ConsoleColors.FgRed,
|
|
100
|
-
};
|
|
101
|
-
if (logLevel >= this._logLevel) {
|
|
102
|
-
// Prefix the message with the colored log level.
|
|
103
|
-
let prefix = "[" + LogLevel[logLevel] + "]\t" + callerPrefix;
|
|
104
|
-
prefix = this.colorize(prefix, color[logLevel]);
|
|
105
|
-
// If the message is not a string, use the debug method to log the object.
|
|
106
|
-
if (typeof message !== "string") {
|
|
107
|
-
console.log(prefix);
|
|
108
|
-
console.debug("%o", message);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
console.log(prefix + "\t" + message);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
colorize(text, color) {
|
|
116
|
-
return color + text + ConsoleColors.Reset;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.Logger = Logger;
|
|
120
|
-
/** Log is an instance of Logger used to generate log entries. */
|
|
121
|
-
const Log = new Logger(LogLevel.info);
|
|
122
|
-
if (process.env.LOG_LEVEL) {
|
|
123
|
-
Log.SetLogLevel(process.env.LOG_LEVEL);
|
|
124
|
-
}
|
|
125
|
-
exports.default = Log;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/lib/module.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAOvC,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,qHAAqH;IACrH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAEpC,6GAA6G;IAC7G,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,CAAC;CACrC,CAAC;AAEF,qBAAa,UAAU;IACrB,OAAO,CAAC,WAAW,CAAa;IAEhC;;;;;;OAMG;gBACS,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,YAAY,GAAE,UAAU,EAAO,EAAE,IAAI,GAAE,iBAAsB;IAc7G;;;;;OAKG;IACH,KAAK,CAAC,IAAI,SAAO;CAGlB"}
|
package/dist/src/lib/module.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.PeprModule = void 0;
|
|
9
|
-
const ramda_1 = __importDefault(require("ramda"));
|
|
10
|
-
const controller_1 = require("./controller");
|
|
11
|
-
const alwaysIgnore = {
|
|
12
|
-
namespaces: ["kube-system", "pepr-system"],
|
|
13
|
-
labels: [{ "pepr.dev": "ignore" }],
|
|
14
|
-
};
|
|
15
|
-
class PeprModule {
|
|
16
|
-
/**
|
|
17
|
-
* Create a new Pepr runtime
|
|
18
|
-
*
|
|
19
|
-
* @param config The configuration for the Pepr runtime
|
|
20
|
-
* @param capabilities The capabilities to be loaded into the Pepr runtime
|
|
21
|
-
* @param _deferStart (optional) If set to `true`, the Pepr runtime will not be started automatically. This can be used to start the Pepr runtime manually with `start()`.
|
|
22
|
-
*/
|
|
23
|
-
constructor({ description, pepr }, capabilities = [], opts = {}) {
|
|
24
|
-
const config = ramda_1.default.mergeDeepWith(ramda_1.default.concat, pepr, alwaysIgnore);
|
|
25
|
-
config.description = description;
|
|
26
|
-
this._controller = new controller_1.Controller(config, capabilities, opts.beforeHook, opts.afterHook);
|
|
27
|
-
// Stop processing if deferStart is set to true
|
|
28
|
-
if (opts.deferStart) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
this.start();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Start the Pepr runtime manually.
|
|
35
|
-
* Normally this is called automatically when the Pepr module is instantiated, but can be called manually if `deferStart` is set to `true` in the constructor.
|
|
36
|
-
*
|
|
37
|
-
* @param port
|
|
38
|
-
*/
|
|
39
|
-
start(port = 3000) {
|
|
40
|
-
this._controller.startServer(port);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.PeprModule = PeprModule;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../../../src/lib/processor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,wBAAsB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsFjH"}
|