pepr 0.28.7 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  <img align="right" width="40%" src="_images/pepr.png" />
13
13
 
14
- Pepr is on a mission to save Kubernetes from the tyranny of YAML, intimidating glue code, bash scripts, and other makeshift solutions. As a Kubernetes controller, Pepr empowers you to define Kubernetes transformations using TypeScript, without software development expertise thanks to plain-english configurations. Pepr transforms a patchwork of forks, scripts, overlays, and other chaos into a cohesive, well-structured, and maintainable system. With Pepr, you can seamlessly transition IT ops tribal knowledge into code, simplifying documentation, testing, validation, and coordination of changes for a more predictable outcome.
14
+ Pepr is on a mission to save Kubernetes from the tyranny of YAML, intimidating glue code, bash scripts, and other makeshift solutions. As a Kubernetes controller, Pepr empowers you to define Kubernetes transformations using TypeScript, without software development expertise thanks to plain-english configurations. Pepr transforms a patchwork of forks, scripts, overlays, and other chaos into a cohesive, well-structured, and maintainable system. With Pepr, you can seamlessly transition IT ops organizational knowledge into code, simplifying documentation, testing, validation, and coordination of changes for a more predictable outcome.
15
15
 
16
16
  ## Features
17
17
 
package/dist/cli.js CHANGED
@@ -1815,7 +1815,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
1815
1815
  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';
1816
1816
  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';
1817
1817
  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';
1818
- 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.28.7", 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", 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.29.11", express: "4.19.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.3.0", pino: "8.19.0", "pino-pretty": "11.0.0", "prom-client": "15.1.1", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "19.2.1", "@commitlint/config-conventional": "19.1.0", "@jest/globals": "29.7.0", "@types/eslint": "8.56.6", "@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.2" }, 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" } };
1818
+ 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.29.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.29.12", express: "4.19.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.3.0", pino: "8.19.0", "pino-pretty": "11.0.0", "prom-client": "15.1.1", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "19.2.1", "@commitlint/config-conventional": "19.1.0", "@jest/globals": "29.7.0", "@types/eslint": "8.56.7", "@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.2" }, 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" } };
1819
1819
 
1820
1820
  // src/templates/pepr.code-snippets.json
1821
1821
  var pepr_code_snippets_default = {
@@ -28,7 +28,7 @@ var import_child_process = require("child_process");
28
28
  var import_crypto = __toESM(require("crypto"));
29
29
  var import_fs = __toESM(require("fs"));
30
30
  var import_zlib = require("zlib");
31
- var import_kubernetes_fluent_client2 = require("kubernetes-fluent-client");
31
+ var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
32
32
 
33
33
  // src/lib/logger.ts
34
34
  var import_pino = require("pino");
@@ -49,7 +49,7 @@ if (process.env.LOG_LEVEL) {
49
49
  var logger_default = Log;
50
50
 
51
51
  // src/templates/data.json
52
- 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.28.7", 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", 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.29.11", express: "4.19.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.3.0", pino: "8.19.0", "pino-pretty": "11.0.0", "prom-client": "15.1.1", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "19.2.1", "@commitlint/config-conventional": "19.1.0", "@jest/globals": "29.7.0", "@types/eslint": "8.56.6", "@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.2" }, 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" } };
52
+ 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.29.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.29.12", express: "4.19.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.3.0", pino: "8.19.0", "pino-pretty": "11.0.0", "prom-client": "15.1.1", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "19.2.1", "@commitlint/config-conventional": "19.1.0", "@jest/globals": "29.7.0", "@types/eslint": "8.56.7", "@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.2" }, 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" } };
53
53
 
54
54
  // src/lib/k8s.ts
55
55
  var import_kubernetes_fluent_client = require("kubernetes-fluent-client");
@@ -105,45 +105,53 @@ var peprStoreCRD = {
105
105
  }
106
106
  };
107
107
 
108
- // src/runtime/controller.ts
109
- var { version: version2 } = packageJSON;
108
+ // src/lib/helpers.ts
109
+ var import_kubernetes_fluent_client2 = require("kubernetes-fluent-client");
110
+ var ValidationError = class extends Error {
111
+ };
110
112
  function validateHash(expectedHash) {
111
- if (!expectedHash || expectedHash.length !== 64) {
112
- logger_default.error("Invalid hash");
113
- process.exit(1);
113
+ const sha256Regex = /^[a-f0-9]{64}$/i;
114
+ if (!expectedHash || !sha256Regex.test(expectedHash)) {
115
+ logger_default.error(`Invalid hash. Expected a valid SHA-256 hash, got ${expectedHash}`);
116
+ throw new ValidationError("Invalid hash");
114
117
  }
115
118
  }
119
+
120
+ // src/runtime/controller.ts
121
+ var { version: version2 } = packageJSON;
116
122
  function runModule(expectedHash) {
117
123
  const gzPath = `/app/load/module-${expectedHash}.js.gz`;
118
124
  const jsPath = `/app/module-${expectedHash}.js`;
119
125
  logger_default.level = "info";
120
126
  if (!import_fs.default.existsSync(gzPath)) {
121
- logger_default.error(`File not found: ${gzPath}`);
122
- process.exit(1);
127
+ throw new Error(`File not found: ${gzPath}`);
123
128
  }
124
129
  try {
125
130
  logger_default.info(`Loading module ${gzPath}`);
126
131
  const codeGZ = import_fs.default.readFileSync(gzPath);
127
132
  const code = (0, import_zlib.gunzipSync)(codeGZ);
128
133
  const actualHash = import_crypto.default.createHash("sha256").update(code).digest("hex");
129
- if (expectedHash !== actualHash) {
130
- logger_default.error(`File hash does not match, expected ${expectedHash} but got ${actualHash}`);
131
- process.exit(1);
134
+ if (!import_crypto.default.timingSafeEqual(Buffer.from(expectedHash, "hex"), Buffer.from(actualHash, "hex"))) {
135
+ throw new Error(`File hash does not match, expected ${expectedHash} but got ${actualHash}`);
132
136
  }
133
137
  logger_default.info(`File hash matches, running module`);
134
138
  import_fs.default.writeFileSync(jsPath, code);
135
139
  (0, import_child_process.fork)(jsPath);
136
140
  } catch (e) {
137
- logger_default.error(`Failed to decompress module: ${e}`);
138
- process.exit(1);
141
+ throw new Error(`Failed to decompress module: ${e}`);
139
142
  }
140
143
  }
141
144
  logger_default.info(`Pepr Controller (v${version2})`);
142
145
  var hash = process.argv[2];
143
146
  var startup = async () => {
144
- logger_default.info("Applying the Pepr Store CRD if it doesn't exist");
145
- await (0, import_kubernetes_fluent_client2.K8s)(import_kubernetes_fluent_client2.kind.CustomResourceDefinition).Apply(peprStoreCRD, { force: true });
146
- validateHash(hash);
147
- runModule(hash);
147
+ try {
148
+ logger_default.info("Applying the Pepr Store CRD if it doesn't exist");
149
+ await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.CustomResourceDefinition).Apply(peprStoreCRD, { force: true });
150
+ validateHash(hash);
151
+ runModule(hash);
152
+ } catch (err) {
153
+ logger_default.error(err);
154
+ process.exit(1);
155
+ }
148
156
  };
149
157
  startup().catch((err) => logger_default.error(err));
@@ -1,5 +1,8 @@
1
1
  import { KubernetesObject } from "kubernetes-fluent-client";
2
2
  import { Binding, CapabilityExport } from "./types";
3
+ export declare class ValidationError extends Error {
4
+ }
5
+ export declare function validateHash(expectedHash: string): void;
3
6
  type RBACMap = {
4
7
  [key: string]: {
5
8
  verbs: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAO,gBAAgB,EAAQ,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEpD,KAAK,OAAO,GAAG;IACb,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAGF,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CA2BnH;AAED;;IAEI;AACJ,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,GAAG,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAC9B,oBAAoB,EAAE,MAAM,EAAE,GAC7B,MAAM,CAiER;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,QAI/D;AAED,wBAAgB,aAAa,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAyBvE;AAED,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,MAAM,iBAU5D;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAMpE;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAMlE;AAED,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE,MAAM,EAAE,EAAE,iBAAiB,EAAE,MAAM,EAAE,WAE/F;AAED,wBAAgB,8BAA8B,CAAC,iBAAiB,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAKzG;AAED,wBAAgB,2BAA2B,CACzC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,EAAE,MAAM,EAAE,UAoB/B;AAGD,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,EAAE,MAAM,EAAE,QActG;AAID,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,MAAM,oBAsB5D;AAGD,wBAAsB,yBAAyB,CAAC,SAAS,GAAE,MAAsB,6BAWhF;AAGD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMpD;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,YAAY,OAAO,KAAG,MAW/D,CAAC;AAGF,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,UAelC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAK1E"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAO,gBAAgB,EAAQ,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEpD,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAE7C,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAOvD;AAED,KAAK,OAAO,GAAG;IACb,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAGF,wBAAgB,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CA2BnH;AAED;;IAEI;AACJ,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,GAAG,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAC9B,oBAAoB,EAAE,MAAM,EAAE,GAC7B,MAAM,CAiER;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,QAI/D;AAED,wBAAgB,aAAa,CAAC,YAAY,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAyBvE;AAED,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,MAAM,iBAU5D;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAMpE;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAMlE;AAED,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE,MAAM,EAAE,EAAE,iBAAiB,EAAE,MAAM,EAAE,WAE/F;AAED,wBAAgB,8BAA8B,CAAC,iBAAiB,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAKzG;AAED,wBAAgB,2BAA2B,CACzC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,EAAE,MAAM,EAAE,UAoB/B;AAGD,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,EAAE,MAAM,EAAE,QActG;AAID,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,MAAM,oBAsB5D;AAGD,wBAAsB,yBAAyB,CAAC,SAAS,GAAE,MAAsB,6BAWhF;AAGD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMpD;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,YAAY,OAAO,KAAG,MAW/D,CAAC;AAGF,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,UAelC;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAK1E"}
package/dist/lib.d.ts CHANGED
@@ -6,6 +6,6 @@ import { PeprModule } from "./lib/module";
6
6
  import { PeprMutateRequest } from "./lib/mutate-request";
7
7
  import * as PeprUtils from "./lib/utils";
8
8
  import { PeprValidateRequest } from "./lib/validate-request";
9
- import { containers } from "./lib/module-helpers";
10
- export { Capability, K8s, Log, PeprModule, PeprMutateRequest, PeprUtils, PeprValidateRequest, R, RegisterKind, a, fetch, fetchStatus, kind, containers, };
9
+ import * as sdk from "./sdk/sdk";
10
+ export { Capability, K8s, Log, PeprModule, PeprMutateRequest, PeprUtils, PeprValidateRequest, R, RegisterKind, a, fetch, fetchStatus, kind, sdk, };
11
11
  //# sourceMappingURL=lib.d.ts.map
package/dist/lib.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EACL,UAAU,EACV,GAAG,EACH,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,CAAC,EACD,YAAY,EACZ,CAAC,EACD,KAAK,EACL,WAAW,EACX,IAAI,EACJ,UAAU,GACX,CAAC"}
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,UAAU,EACV,GAAG,EACH,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,CAAC,EACD,YAAY,EACZ,CAAC,EACD,KAAK,EACL,WAAW,EACX,IAAI,EACJ,GAAG,GACJ,CAAC"}
package/dist/lib.js CHANGED
@@ -31,22 +31,22 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var lib_exports = {};
32
32
  __export(lib_exports, {
33
33
  Capability: () => Capability,
34
- K8s: () => import_kubernetes_fluent_client6.K8s,
34
+ K8s: () => import_kubernetes_fluent_client7.K8s,
35
35
  Log: () => logger_default,
36
36
  PeprModule: () => PeprModule,
37
37
  PeprMutateRequest: () => PeprMutateRequest,
38
38
  PeprUtils: () => utils_exports,
39
39
  PeprValidateRequest: () => PeprValidateRequest,
40
40
  R: () => R,
41
- RegisterKind: () => import_kubernetes_fluent_client6.RegisterKind,
42
- a: () => import_kubernetes_fluent_client6.kind,
43
- containers: () => containers,
44
- fetch: () => import_kubernetes_fluent_client6.fetch,
45
- fetchStatus: () => import_kubernetes_fluent_client6.fetchStatus,
46
- kind: () => import_kubernetes_fluent_client6.kind
41
+ RegisterKind: () => import_kubernetes_fluent_client7.RegisterKind,
42
+ a: () => import_kubernetes_fluent_client7.kind,
43
+ fetch: () => import_kubernetes_fluent_client7.fetch,
44
+ fetchStatus: () => import_kubernetes_fluent_client7.fetchStatus,
45
+ kind: () => import_kubernetes_fluent_client7.kind,
46
+ sdk: () => sdk_exports
47
47
  });
48
48
  module.exports = __toCommonJS(lib_exports);
49
- var import_kubernetes_fluent_client6 = require("kubernetes-fluent-client");
49
+ var import_kubernetes_fluent_client7 = require("kubernetes-fluent-client");
50
50
  var R = __toESM(require("ramda"));
51
51
 
52
52
  // src/lib/capability.ts
@@ -187,7 +187,7 @@ var peprStoreGVK = {
187
187
 
188
188
  // src/lib/filter.ts
189
189
  function shouldSkipRequest(binding, req, capabilityNamespaces) {
190
- const { group, kind: kind3, version } = binding.kind || {};
190
+ const { group, kind: kind4, version } = binding.kind || {};
191
191
  const { namespaces, labels, annotations, name } = binding.filters || {};
192
192
  const operation = req.operation.toUpperCase();
193
193
  const uid = req.uid;
@@ -200,7 +200,7 @@ function shouldSkipRequest(binding, req, capabilityNamespaces) {
200
200
  if (name && name !== req.name) {
201
201
  return true;
202
202
  }
203
- if (kind3 !== req.kind.kind) {
203
+ if (kind4 !== req.kind.kind) {
204
204
  return true;
205
205
  }
206
206
  if (group && group !== req.kind.group) {
@@ -1472,7 +1472,7 @@ var Capability = class {
1472
1472
  OnSchedule = (schedule) => {
1473
1473
  const { name, every, unit, run, startTime, completions } = schedule;
1474
1474
  this.hasSchedule = true;
1475
- if (process.env.PEPR_WATCH_MODE === "true") {
1475
+ if (process.env.PEPR_WATCH_MODE === "true" || process.env.PEPR_MODE === "dev") {
1476
1476
  const newSchedule = {
1477
1477
  name,
1478
1478
  every,
@@ -1579,15 +1579,15 @@ var Capability = class {
1579
1579
  * @param kind if using a custom KubernetesObject not available in `a.*`, specify the GroupVersionKind
1580
1580
  * @returns
1581
1581
  */
1582
- When = (model, kind3) => {
1582
+ When = (model, kind4) => {
1583
1583
  const matchedKind = (0, import_kubernetes_fluent_client5.modelToGroupVersionKind)(model.name);
1584
- if (!matchedKind && !kind3) {
1584
+ if (!matchedKind && !kind4) {
1585
1585
  throw new Error(`Kind not specified for ${model.name}`);
1586
1586
  }
1587
1587
  const binding = {
1588
1588
  model,
1589
1589
  // If the kind is not specified, use the matched kind from the model
1590
- kind: kind3 || matchedKind,
1590
+ kind: kind4 || matchedKind,
1591
1591
  event: "*" /* Any */,
1592
1592
  filters: {
1593
1593
  name: "",
@@ -1686,7 +1686,15 @@ var Capability = class {
1686
1686
  };
1687
1687
  };
1688
1688
 
1689
- // src/lib/module-helpers.ts
1689
+ // src/sdk/sdk.ts
1690
+ var sdk_exports = {};
1691
+ __export(sdk_exports, {
1692
+ containers: () => containers,
1693
+ getOwnerRefFrom: () => getOwnerRefFrom,
1694
+ sanitizeResourceName: () => sanitizeResourceName,
1695
+ writeEvent: () => writeEvent
1696
+ });
1697
+ var import_kubernetes_fluent_client6 = require("kubernetes-fluent-client");
1690
1698
  function containers(request, containerType) {
1691
1699
  const containers2 = request.Raw.spec?.containers || [];
1692
1700
  const initContainers = request.Raw.spec?.initContainers || [];
@@ -1702,6 +1710,43 @@ function containers(request, containerType) {
1702
1710
  }
1703
1711
  return [...containers2, ...initContainers, ...ephemeralContainers];
1704
1712
  }
1713
+ async function writeEvent(cr, event, eventType, eventReason, reportingComponent, reportingInstance) {
1714
+ logger_default.debug(cr.metadata, `Writing event: ${event.message}`);
1715
+ await (0, import_kubernetes_fluent_client6.K8s)(import_kubernetes_fluent_client6.kind.CoreEvent).Create({
1716
+ type: eventType,
1717
+ reason: eventReason,
1718
+ ...event,
1719
+ // Fixed values
1720
+ metadata: {
1721
+ namespace: cr.metadata.namespace,
1722
+ generateName: cr.metadata.name
1723
+ },
1724
+ involvedObject: {
1725
+ apiVersion: cr.apiVersion,
1726
+ kind: cr.kind,
1727
+ name: cr.metadata.name,
1728
+ namespace: cr.metadata.namespace,
1729
+ uid: cr.metadata.uid
1730
+ },
1731
+ firstTimestamp: /* @__PURE__ */ new Date(),
1732
+ reportingComponent,
1733
+ reportingInstance
1734
+ });
1735
+ }
1736
+ function getOwnerRefFrom(cr) {
1737
+ const { name, uid } = cr.metadata;
1738
+ return [
1739
+ {
1740
+ apiVersion: cr.apiVersion,
1741
+ kind: cr.kind,
1742
+ uid,
1743
+ name
1744
+ }
1745
+ ];
1746
+ }
1747
+ function sanitizeResourceName(name) {
1748
+ return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
1749
+ }
1705
1750
  // Annotate the CommonJS export names for ESM import in node:
1706
1751
  0 && (module.exports = {
1707
1752
  Capability,
@@ -1714,9 +1759,9 @@ function containers(request, containerType) {
1714
1759
  R,
1715
1760
  RegisterKind,
1716
1761
  a,
1717
- containers,
1718
1762
  fetch,
1719
1763
  fetchStatus,
1720
- kind
1764
+ kind,
1765
+ sdk
1721
1766
  });
1722
1767
  //# sourceMappingURL=lib.js.map