pepr 0.31.1 → 0.32.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.js +76 -13
- package/dist/controller.js +3 -3
- package/dist/lib/assets/helm.d.ts.map +1 -1
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/mutate-processor.d.ts.map +1 -1
- package/dist/lib.js +23 -9
- package/dist/lib.js.map +3 -3
- package/package.json +6 -6
- package/src/lib/assets/helm.ts +18 -0
- package/src/lib/assets/index.ts +3 -1
- package/src/lib/assets/yaml.ts +35 -0
- package/src/lib/controller/index.ts +3 -3
- package/src/lib/controller/store.ts +7 -3
- package/src/lib/mutate-processor.ts +17 -6
- package/src/runtime/controller.ts +2 -2
- package/dist/cli.d.ts +0 -3
- package/dist/lib/assets/deploy.d.ts +0 -3
- package/dist/lib/assets/destroy.d.ts +0 -2
- package/dist/lib/assets/helm.d.ts +0 -5
- package/dist/lib/assets/index.d.ts +0 -24
- package/dist/lib/assets/loader.d.ts +0 -8
- package/dist/lib/assets/networking.d.ts +0 -7
- package/dist/lib/assets/pods.d.ts +0 -126
- package/dist/lib/assets/rbac.d.ts +0 -14
- package/dist/lib/assets/store.d.ts +0 -7
- package/dist/lib/assets/webhooks.d.ts +0 -6
- package/dist/lib/assets/yaml.d.ts +0 -5
- package/dist/lib/capability.d.ts +0 -66
- package/dist/lib/controller/index.d.ts +0 -10
- package/dist/lib/controller/store.d.ts +0 -7
- package/dist/lib/errors.d.ts +0 -12
- package/dist/lib/filter.d.ts +0 -11
- package/dist/lib/helpers.d.ts +0 -34
- package/dist/lib/included-files.d.ts +0 -2
- package/dist/lib/k8s.d.ts +0 -132
- package/dist/lib/logger.d.ts +0 -3
- package/dist/lib/metrics.d.ts +0 -39
- package/dist/lib/module.d.ts +0 -62
- package/dist/lib/mutate-processor.d.ts +0 -5
- package/dist/lib/mutate-request.d.ts +0 -79
- package/dist/lib/queue.d.ts +0 -19
- package/dist/lib/schedule.d.ts +0 -76
- package/dist/lib/storage.d.ts +0 -83
- package/dist/lib/tls.d.ts +0 -18
- package/dist/lib/types.d.ts +0 -192
- package/dist/lib/utils.d.ts +0 -23
- package/dist/lib/validate-processor.d.ts +0 -4
- package/dist/lib/validate-request.d.ts +0 -55
- package/dist/lib/watch-processor.d.ts +0 -10
- package/dist/lib.d.ts +0 -11
- package/dist/runtime/controller.d.ts +0 -3
- package/dist/sdk/sdk.d.ts +0 -38
package/dist/cli.js
CHANGED
|
@@ -1191,8 +1191,11 @@ async function overridesFile({ hash, name: name2, image, config, apiToken }, pat
|
|
|
1191
1191
|
drop: ["ALL"]
|
|
1192
1192
|
}
|
|
1193
1193
|
},
|
|
1194
|
+
podAnnotations: {},
|
|
1194
1195
|
nodeSelector: {},
|
|
1195
1196
|
tolerations: [],
|
|
1197
|
+
extraVolumeMounts: [],
|
|
1198
|
+
extraVolumes: [],
|
|
1196
1199
|
affinity: {}
|
|
1197
1200
|
},
|
|
1198
1201
|
watcher: {
|
|
@@ -1238,7 +1241,10 @@ async function overridesFile({ hash, name: name2, image, config, apiToken }, pat
|
|
|
1238
1241
|
},
|
|
1239
1242
|
nodeSelector: {},
|
|
1240
1243
|
tolerations: [],
|
|
1241
|
-
|
|
1244
|
+
extraVolumeMounts: [],
|
|
1245
|
+
extraVolumes: [],
|
|
1246
|
+
affinity: {},
|
|
1247
|
+
podAnnotations: {}
|
|
1242
1248
|
}
|
|
1243
1249
|
};
|
|
1244
1250
|
if (process.env.PEPR_MODE === "dev") {
|
|
@@ -1275,6 +1281,33 @@ function zarfYaml({ name: name2, image, config }, path) {
|
|
|
1275
1281
|
};
|
|
1276
1282
|
return (0, import_client_node.dumpYaml)(zarfCfg, { noRefs: true });
|
|
1277
1283
|
}
|
|
1284
|
+
function zarfYamlChart({ name: name2, image, config }, path) {
|
|
1285
|
+
const zarfCfg = {
|
|
1286
|
+
kind: "ZarfPackageConfig",
|
|
1287
|
+
metadata: {
|
|
1288
|
+
name: name2,
|
|
1289
|
+
description: `Pepr Module: ${config.description}`,
|
|
1290
|
+
url: "https://github.com/defenseunicorns/pepr",
|
|
1291
|
+
version: `${config.appVersion || "0.0.1"}`
|
|
1292
|
+
},
|
|
1293
|
+
components: [
|
|
1294
|
+
{
|
|
1295
|
+
name: "module",
|
|
1296
|
+
required: true,
|
|
1297
|
+
charts: [
|
|
1298
|
+
{
|
|
1299
|
+
name: "module",
|
|
1300
|
+
namespace: "pepr-system",
|
|
1301
|
+
version: `${config.appVersion || "0.0.1"}`,
|
|
1302
|
+
localPath: path
|
|
1303
|
+
}
|
|
1304
|
+
],
|
|
1305
|
+
images: [image]
|
|
1306
|
+
}
|
|
1307
|
+
]
|
|
1308
|
+
};
|
|
1309
|
+
return (0, import_client_node.dumpYaml)(zarfCfg, { noRefs: true });
|
|
1310
|
+
}
|
|
1278
1311
|
async function allYaml(assets, rbacMode) {
|
|
1279
1312
|
const { name: name2, tls, apiToken, path } = assets;
|
|
1280
1313
|
const code = await import_fs4.promises.readFile(path);
|
|
@@ -1379,6 +1412,9 @@ function watcherDeployTemplate(buildTimestamp) {
|
|
|
1379
1412
|
metadata:
|
|
1380
1413
|
annotations:
|
|
1381
1414
|
buildTimestamp: "${buildTimestamp}"
|
|
1415
|
+
{{- if .Values.watcher.podAnnotations }}
|
|
1416
|
+
{{- toYaml .Values.watcher.podAnnotations | nindent 8 }}
|
|
1417
|
+
{{- end }}
|
|
1382
1418
|
labels:
|
|
1383
1419
|
app: {{ .Values.uuid }}-watcher
|
|
1384
1420
|
pepr.dev/controller: watcher
|
|
@@ -1420,6 +1456,9 @@ function watcherDeployTemplate(buildTimestamp) {
|
|
|
1420
1456
|
- name: module
|
|
1421
1457
|
mountPath: /app/load
|
|
1422
1458
|
readOnly: true
|
|
1459
|
+
{{- if .Values.watcher.extraVolumeMounts }}
|
|
1460
|
+
{{- toYaml .Values.watcher.extraVolumeMounts | nindent 12 }}
|
|
1461
|
+
{{- end }}
|
|
1423
1462
|
volumes:
|
|
1424
1463
|
- name: tls-certs
|
|
1425
1464
|
secret:
|
|
@@ -1427,6 +1466,9 @@ function watcherDeployTemplate(buildTimestamp) {
|
|
|
1427
1466
|
- name: module
|
|
1428
1467
|
secret:
|
|
1429
1468
|
secretName: {{ .Values.uuid }}-module
|
|
1469
|
+
{{- if .Values.watcher.extraVolumes }}
|
|
1470
|
+
{{- toYaml .Values.watcher.extraVolumes | nindent 8 }}
|
|
1471
|
+
{{- end }}
|
|
1430
1472
|
`;
|
|
1431
1473
|
}
|
|
1432
1474
|
function admissionDeployTemplate(buildTimestamp) {
|
|
@@ -1450,6 +1492,9 @@ function admissionDeployTemplate(buildTimestamp) {
|
|
|
1450
1492
|
metadata:
|
|
1451
1493
|
annotations:
|
|
1452
1494
|
buildTimestamp: "${buildTimestamp}"
|
|
1495
|
+
{{- if .Values.admission.podAnnotations }}
|
|
1496
|
+
{{- toYaml .Values.admission.podAnnotations | nindent 8 }}
|
|
1497
|
+
{{- end }}
|
|
1453
1498
|
labels:
|
|
1454
1499
|
app: {{ .Values.uuid }}
|
|
1455
1500
|
pepr.dev/controller: admission
|
|
@@ -1495,6 +1540,9 @@ function admissionDeployTemplate(buildTimestamp) {
|
|
|
1495
1540
|
- name: module
|
|
1496
1541
|
mountPath: /app/load
|
|
1497
1542
|
readOnly: true
|
|
1543
|
+
{{- if .Values.admission.extraVolumeMounts }}
|
|
1544
|
+
{{- toYaml .Values.admission.extraVolumeMounts | nindent 12 }}
|
|
1545
|
+
{{- end }}
|
|
1498
1546
|
volumes:
|
|
1499
1547
|
- name: tls-certs
|
|
1500
1548
|
secret:
|
|
@@ -1505,6 +1553,9 @@ function admissionDeployTemplate(buildTimestamp) {
|
|
|
1505
1553
|
- name: module
|
|
1506
1554
|
secret:
|
|
1507
1555
|
secretName: {{ .Values.uuid }}-module
|
|
1556
|
+
{{- if .Values.admission.extraVolumes }}
|
|
1557
|
+
{{- toYaml .Values.admission.extraVolumes | nindent 8 }}
|
|
1558
|
+
{{- end }}
|
|
1508
1559
|
`;
|
|
1509
1560
|
}
|
|
1510
1561
|
|
|
@@ -1539,6 +1590,7 @@ var Assets = class {
|
|
|
1539
1590
|
await deploy(this, force, webhookTimeout);
|
|
1540
1591
|
};
|
|
1541
1592
|
zarfYaml = (path) => zarfYaml(this, path);
|
|
1593
|
+
zarfYamlChart = (path) => zarfYamlChart(this, path);
|
|
1542
1594
|
allYaml = async (rbacMode) => {
|
|
1543
1595
|
this.capabilities = await loadCapabilities(this.path);
|
|
1544
1596
|
for (const capability of this.capabilities) {
|
|
@@ -1836,7 +1888,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
1836
1888
|
var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
|
|
1837
1889
|
var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
|
|
1838
1890
|
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://api.chucknorris.io/jokes/random?category=dev");\n * const joke = await fetch("https://api.chucknorris.io/jokes/random?category=dev") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://api.chucknorris.io/jokes/random?category=dev")\n * ```\n */\ninterface TheChuckNorrisJoke {\n icon_url: string;\n id: string;\n url: string;\n value: string;\n}\n\nWhen(a.ConfigMap)\n .IsCreated()\n .WithLabel("chuck-norris")\n .Mutate(async change => {\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(\n "https://api.chucknorris.io/jokes/random?category=dev",\n );\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n // Add the Chuck Norris joke to the configmap\n change.Raw.data["chuck-says"] = response.data.value;\n return;\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
|
|
1839
|
-
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.
|
|
1891
|
+
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.32.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", "build:image": "npm run build && docker buildx build --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.30.0", express: "4.19.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.6.1", pino: "9.2.0", "pino-pretty": "11.2.0", "prom-client": "15.1.2", ramda: "0.30.1" }, devDependencies: { "@commitlint/cli": "19.3.0", "@commitlint/config-conventional": "19.2.2", "@jest/globals": "29.7.0", "@types/eslint": "8.56.10", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "@types/uuid": "9.0.8", jest: "29.7.0", nock: "13.5.4", "ts-jest": "29.1.4" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.15.0", "@typescript-eslint/parser": "6.15.0", commander: "11.1.0", esbuild: "0.19.10", eslint: "8.56.0", "node-forge": "1.3.1", prettier: "3.1.1", prompts: "2.4.2", typescript: "5.3.3", uuid: "9.0.1" } };
|
|
1840
1892
|
|
|
1841
1893
|
// src/templates/pepr.code-snippets.json
|
|
1842
1894
|
var pepr_code_snippets_default = {
|
|
@@ -2061,7 +2113,7 @@ async function peprFormat(validateOnly) {
|
|
|
2061
2113
|
}
|
|
2062
2114
|
return !hasFailure;
|
|
2063
2115
|
} catch (e) {
|
|
2064
|
-
console.error(e
|
|
2116
|
+
console.error(`Error formatting module:`, e);
|
|
2065
2117
|
return false;
|
|
2066
2118
|
}
|
|
2067
2119
|
}
|
|
@@ -2093,6 +2145,11 @@ function build_default(program2) {
|
|
|
2093
2145
|
"--registry <GitHub|Iron Bank>",
|
|
2094
2146
|
"Container registry: Choose container registry for deployment manifests. Can't be used with --custom-image."
|
|
2095
2147
|
).choices(["GitHub", "Iron Bank"])
|
|
2148
|
+
).addOption(
|
|
2149
|
+
new import_commander.Option(
|
|
2150
|
+
"-z, --zarf [manifest|chart]",
|
|
2151
|
+
"Zarf package type: manifest, chart (default: manifest)"
|
|
2152
|
+
).choices(["manifest", "chart"]).default("manifest")
|
|
2096
2153
|
).addOption(
|
|
2097
2154
|
new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(["admin", "scoped"]).default("admin")
|
|
2098
2155
|
).action(async (opts) => {
|
|
@@ -2152,16 +2209,22 @@ function build_default(program2) {
|
|
|
2152
2209
|
assets.image = image;
|
|
2153
2210
|
}
|
|
2154
2211
|
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
2212
|
+
const chartPath = `${uuid}-chart`;
|
|
2155
2213
|
const yamlPath = (0, import_path2.resolve)(outputDir, yamlFile);
|
|
2156
2214
|
const yaml = await assets.allYaml(opts.rbacMode);
|
|
2157
2215
|
try {
|
|
2158
2216
|
validateCapabilityNames(assets.capabilities);
|
|
2159
2217
|
} catch (e) {
|
|
2160
|
-
console.error(e
|
|
2218
|
+
console.error(`Error loading capability:`, e);
|
|
2161
2219
|
process.exit(1);
|
|
2162
2220
|
}
|
|
2163
2221
|
const zarfPath = (0, import_path2.resolve)(outputDir, "zarf.yaml");
|
|
2164
|
-
|
|
2222
|
+
let zarf = "";
|
|
2223
|
+
if (opts.zarf === "chart") {
|
|
2224
|
+
zarf = assets.zarfYamlChart(chartPath);
|
|
2225
|
+
} else {
|
|
2226
|
+
zarf = assets.zarfYaml(yamlFile);
|
|
2227
|
+
}
|
|
2165
2228
|
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2166
2229
|
await import_fs8.promises.writeFile(zarfPath, zarf);
|
|
2167
2230
|
await assets.generateHelmChart(outputDir);
|
|
@@ -2261,7 +2324,7 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
2261
2324
|
}
|
|
2262
2325
|
return { ctx, path, cfg, uuid };
|
|
2263
2326
|
} catch (e) {
|
|
2264
|
-
console.error(e
|
|
2327
|
+
console.error(`Error building module:`, e);
|
|
2265
2328
|
if (e.stdout) {
|
|
2266
2329
|
const out = e.stdout.toString();
|
|
2267
2330
|
const err = e.stderr.toString();
|
|
@@ -2325,7 +2388,7 @@ function deploy_default(program2) {
|
|
|
2325
2388
|
await namespaceDeploymentsReady();
|
|
2326
2389
|
console.info(`\u2705 Module deployed successfully`);
|
|
2327
2390
|
} catch (e) {
|
|
2328
|
-
console.error(`Error deploying module
|
|
2391
|
+
console.error(`Error deploying module:`, e);
|
|
2329
2392
|
process.exit(1);
|
|
2330
2393
|
}
|
|
2331
2394
|
});
|
|
@@ -2370,7 +2433,7 @@ function dev_default(program2) {
|
|
|
2370
2433
|
try {
|
|
2371
2434
|
validateCapabilityNames(webhook.capabilities);
|
|
2372
2435
|
} catch (e) {
|
|
2373
|
-
console.error(e
|
|
2436
|
+
console.error(`Error validating capability names:`, e);
|
|
2374
2437
|
process.exit(1);
|
|
2375
2438
|
}
|
|
2376
2439
|
program3 = (0, import_child_process3.fork)(path, {
|
|
@@ -2410,7 +2473,7 @@ function dev_default(program2) {
|
|
|
2410
2473
|
}
|
|
2411
2474
|
});
|
|
2412
2475
|
} catch (e) {
|
|
2413
|
-
console.error(`Error deploying module
|
|
2476
|
+
console.error(`Error deploying module:`, e);
|
|
2414
2477
|
process.exit(1);
|
|
2415
2478
|
}
|
|
2416
2479
|
});
|
|
@@ -2628,7 +2691,7 @@ function init_default(program2) {
|
|
|
2628
2691
|
console.log(`Open VSCode or your editor of choice in ${dirName} to get started!`);
|
|
2629
2692
|
} catch (e) {
|
|
2630
2693
|
if (e instanceof Error) {
|
|
2631
|
-
console.error(e
|
|
2694
|
+
console.error(`Error creating Pepr module:`, e);
|
|
2632
2695
|
}
|
|
2633
2696
|
process.exit(1);
|
|
2634
2697
|
}
|
|
@@ -2701,7 +2764,7 @@ function update_default(program2) {
|
|
|
2701
2764
|
}
|
|
2702
2765
|
console.log(`\u2705 Module updated successfully`);
|
|
2703
2766
|
} catch (e) {
|
|
2704
|
-
console.error(e
|
|
2767
|
+
console.error(`Error updating Pepr module:`, e);
|
|
2705
2768
|
process.exit(1);
|
|
2706
2769
|
}
|
|
2707
2770
|
});
|
|
@@ -2724,7 +2787,7 @@ function update_default(program2) {
|
|
|
2724
2787
|
}
|
|
2725
2788
|
}
|
|
2726
2789
|
} catch (e) {
|
|
2727
|
-
console.error(e
|
|
2790
|
+
console.error(`Error updating template files:`, e);
|
|
2728
2791
|
process.exit(1);
|
|
2729
2792
|
}
|
|
2730
2793
|
});
|
|
@@ -2752,7 +2815,7 @@ function kfc_default(program2) {
|
|
|
2752
2815
|
stdio: "inherit"
|
|
2753
2816
|
});
|
|
2754
2817
|
} catch (e) {
|
|
2755
|
-
console.error(e
|
|
2818
|
+
console.error(`Error creating CRD generated class:`, e);
|
|
2756
2819
|
process.exit(1);
|
|
2757
2820
|
}
|
|
2758
2821
|
});
|
package/dist/controller.js
CHANGED
|
@@ -51,7 +51,7 @@ if (process.env.LOG_LEVEL) {
|
|
|
51
51
|
var logger_default = Log;
|
|
52
52
|
|
|
53
53
|
// src/templates/data.json
|
|
54
|
-
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.
|
|
54
|
+
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.32.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", "build:image": "npm run build && docker buildx build --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.30.0", express: "4.19.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.6.1", pino: "9.2.0", "pino-pretty": "11.2.0", "prom-client": "15.1.2", ramda: "0.30.1" }, devDependencies: { "@commitlint/cli": "19.3.0", "@commitlint/config-conventional": "19.2.2", "@jest/globals": "29.7.0", "@types/eslint": "8.56.10", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "@types/uuid": "9.0.8", jest: "29.7.0", nock: "13.5.4", "ts-jest": "29.1.4" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.15.0", "@typescript-eslint/parser": "6.15.0", commander: "11.1.0", esbuild: "0.19.10", eslint: "8.56.0", "node-forge": "1.3.1", prettier: "3.1.1", prompts: "2.4.2", typescript: "5.3.3", uuid: "9.0.1" } };
|
|
55
55
|
|
|
56
56
|
// src/lib/k8s.ts
|
|
57
57
|
var import_kubernetes_fluent_client = require("kubernetes-fluent-client");
|
|
@@ -157,8 +157,8 @@ var startup = async () => {
|
|
|
157
157
|
validateHash(hash);
|
|
158
158
|
runModule(hash);
|
|
159
159
|
} catch (err) {
|
|
160
|
-
logger_default.error(err);
|
|
160
|
+
logger_default.error(err, `Error starting Pepr Store CRD`);
|
|
161
161
|
process.exit(1);
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
|
-
startup().catch((err) => logger_default.error(err));
|
|
164
|
+
startup().catch((err) => logger_default.error(err, `Error starting Pepr Controller`));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helm.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/helm.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,WAezB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,UA2B3D;AAED,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"helm.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/helm.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,WAezB;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,UA2B3D;AAED,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,MAAM,UAiF3D;AAED,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,MAAM,UAsF7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAcvC,qBAAa,MAAM;IAYf,QAAQ,CAAC,MAAM,EAAE,YAAY;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,CAAC;IAbhB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAG,aAAa,CAAC;IACtC,YAAY,EAAG,gBAAgB,EAAE,CAAC;IAElC,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;gBAGF,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,oBAAQ;IAcxB,OAAO,SAAU,MAAM,UAErB;IAEF,MAAM,UAAiB,OAAO,mBAAmB,MAAM,mBAGrD;IAEF,QAAQ,SAAU,MAAM,YAA0B;IAElD,OAAO,aAAoB,MAAM,qBAQ/B;IAEF,iBAAiB,aAAoB,MAAM,mBAoGzC;CACH"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAcvC,qBAAa,MAAM;IAYf,QAAQ,CAAC,MAAM,EAAE,YAAY;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,CAAC;IAbhB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAG,aAAa,CAAC;IACtC,YAAY,EAAG,gBAAgB,EAAE,CAAC;IAElC,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;gBAGF,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,oBAAQ;IAcxB,OAAO,SAAU,MAAM,UAErB;IAEF,MAAM,UAAiB,OAAO,mBAAmB,MAAM,mBAGrD;IAEF,QAAQ,SAAU,MAAM,YAA0B;IAElD,aAAa,SAAU,MAAM,YAA+B;IAE5D,OAAO,aAAoB,MAAM,qBAQ/B;IAEF,iBAAiB,aAAoB,MAAM,mBAoGzC;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/yaml.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAO3B,wBAAsB,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/yaml.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAO3B,wBAAsB,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAwHhG;AACD,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UA0BrE;AAED,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UA2B1E;AAED,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAyC7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,qBAAa,mBAAmB;;gBAMlB,YAAY,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/store.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,qBAAa,mBAAmB;;gBAMlB,YAAY,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,IAAI;CAqM3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutate-processor.d.ts","sourceRoot":"","sources":["../../src/lib/mutate-processor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,wBAAsB,eAAe,CACnC,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,UAAU,EAAE,EAC1B,GAAG,EAAE,gBAAgB,EACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"mutate-processor.d.ts","sourceRoot":"","sources":["../../src/lib/mutate-processor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,wBAAsB,eAAe,CACnC,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,UAAU,EAAE,EAC1B,GAAG,EAAE,gBAAgB,EACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,cAAc,CAAC,CA2IzB"}
|
package/dist/lib.js
CHANGED
|
@@ -456,18 +456,28 @@ async function mutateProcessor(config, capabilities, req, reqMetadata) {
|
|
|
456
456
|
logger_default.info(actionMetadata, `Mutation action succeeded (${label})`);
|
|
457
457
|
updateStatus("succeeded");
|
|
458
458
|
} catch (e) {
|
|
459
|
-
logger_default.warn(actionMetadata, `Action failed: ${e}`);
|
|
460
459
|
updateStatus("warning");
|
|
461
460
|
response.warnings = response.warnings || [];
|
|
462
|
-
|
|
461
|
+
let errorMessage = "";
|
|
462
|
+
try {
|
|
463
|
+
if (e.message && e.message !== "[object Object]") {
|
|
464
|
+
errorMessage = e.message;
|
|
465
|
+
} else {
|
|
466
|
+
throw new Error("An error occurred in the mutate action.");
|
|
467
|
+
}
|
|
468
|
+
} catch (e2) {
|
|
469
|
+
errorMessage = "An error occurred with the mutate action.";
|
|
470
|
+
}
|
|
471
|
+
logger_default.error(actionMetadata, `Action failed: ${errorMessage}`);
|
|
472
|
+
response.warnings.push(`Action failed: ${errorMessage}`);
|
|
463
473
|
switch (config.onError) {
|
|
464
474
|
case Errors.reject:
|
|
465
|
-
logger_default.error(actionMetadata, `Action failed: ${
|
|
475
|
+
logger_default.error(actionMetadata, `Action failed: ${errorMessage}`);
|
|
466
476
|
response.result = "Pepr module configured to reject on error";
|
|
467
477
|
return response;
|
|
468
478
|
case Errors.audit:
|
|
469
479
|
response.auditAnnotations = response.auditAnnotations || {};
|
|
470
|
-
response.auditAnnotations[Date.now()] =
|
|
480
|
+
response.auditAnnotations[Date.now()] = `Action failed: ${errorMessage}`;
|
|
471
481
|
break;
|
|
472
482
|
}
|
|
473
483
|
}
|
|
@@ -718,8 +728,12 @@ var PeprControllerStore = class {
|
|
|
718
728
|
await (0, import_kubernetes_fluent_client2.K8s)(PeprStore, { namespace, name: this.#name }).Patch(payload);
|
|
719
729
|
} catch (err) {
|
|
720
730
|
logger_default.error(err, "Pepr store update failure");
|
|
721
|
-
|
|
722
|
-
sendCache
|
|
731
|
+
if (err.status === 422) {
|
|
732
|
+
Object.keys(sendCache).forEach((key) => delete sendCache[key]);
|
|
733
|
+
} else {
|
|
734
|
+
for (const idx of indexes) {
|
|
735
|
+
sendCache[idx] = payload[Number(idx)];
|
|
736
|
+
}
|
|
723
737
|
}
|
|
724
738
|
}
|
|
725
739
|
};
|
|
@@ -871,7 +885,7 @@ var Controller = class _Controller {
|
|
|
871
885
|
try {
|
|
872
886
|
res.send(await this.#metricsCollector.getMetrics());
|
|
873
887
|
} catch (err) {
|
|
874
|
-
logger_default.error(err);
|
|
888
|
+
logger_default.error(err, `Error getting metrics`);
|
|
875
889
|
res.status(500).send("Internal Server Error");
|
|
876
890
|
}
|
|
877
891
|
};
|
|
@@ -938,7 +952,7 @@ var Controller = class _Controller {
|
|
|
938
952
|
logger_default.debug({ ...reqMetadata, kubeAdmissionResponse }, "Outgoing response");
|
|
939
953
|
this.#metricsCollector.observeEnd(startTime, admissionKind);
|
|
940
954
|
} catch (err) {
|
|
941
|
-
logger_default.error(err);
|
|
955
|
+
logger_default.error(err, `Error processing ${admissionKind} request`);
|
|
942
956
|
res.status(500).send("Internal Server Error");
|
|
943
957
|
this.#metricsCollector.error();
|
|
944
958
|
}
|
|
@@ -976,7 +990,7 @@ var Controller = class _Controller {
|
|
|
976
990
|
try {
|
|
977
991
|
res.send("OK");
|
|
978
992
|
} catch (err) {
|
|
979
|
-
logger_default.error(err);
|
|
993
|
+
logger_default.error(err, `Error processing health check`);
|
|
980
994
|
res.status(500).send("Internal Server Error");
|
|
981
995
|
}
|
|
982
996
|
}
|