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