pepr 0.1.43 → 0.1.45

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
@@ -20,8 +20,12 @@ pepr init
20
20
 
21
21
  # Follow the prompts...
22
22
 
23
- # Within the new project dir, start playing with things
23
+ # If you already have a Kind or K3d cluster you want to use, skip this step
24
+ npm run k3d-setup
25
+
26
+ # Start playing with Pepr now
24
27
  pepr dev
28
+ kubectl apply -f capabilities/hello-pepr.samples.yaml
25
29
 
26
30
  # Be amazed and ⭐️ this repo
27
31
  ```
package/dist/index.d.ts CHANGED
@@ -2,11 +2,12 @@ import k8s from "@kubernetes/client-node";
2
2
  import utils from "ramda";
3
3
  import { Capability } from "./src/lib/capability";
4
4
  import { fetch, fetchRaw } from "./src/lib/fetch";
5
- import { a } from "./src/lib/k8s";
5
+ import { RegisterKind, a } from "./src/lib/k8s";
6
6
  import Log from "./src/lib/logger";
7
7
  import { PeprModule } from "./src/lib/module";
8
+ import { PeprRequest } from "./src/lib/request";
8
9
  import type * as KubernetesClientNode from "@kubernetes/client-node";
9
10
  import type * as RamdaUtils from "ramda";
10
11
  export { a,
11
12
  /** PeprModule is used to setup a complete Pepr Module: `new PeprModule(cfg, {...capabilities})` */
12
- PeprModule, Capability, Log, utils, fetch, fetchRaw, k8s, RamdaUtils, KubernetesClientNode, };
13
+ PeprModule, PeprRequest, RegisterKind, Capability, Log, utils, fetch, fetchRaw, k8s, RamdaUtils, KubernetesClientNode, };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.k8s = exports.fetchRaw = exports.fetch = exports.utils = exports.Log = exports.Capability = exports.PeprModule = exports.a = void 0;
6
+ exports.k8s = exports.fetchRaw = exports.fetch = exports.utils = exports.Log = exports.Capability = exports.RegisterKind = exports.PeprRequest = exports.PeprModule = exports.a = void 0;
7
7
  const client_node_1 = __importDefault(require("@kubernetes/client-node"));
8
8
  exports.k8s = client_node_1.default;
9
9
  const ramda_1 = __importDefault(require("ramda"));
@@ -14,8 +14,11 @@ const fetch_1 = require("./src/lib/fetch");
14
14
  Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
15
15
  Object.defineProperty(exports, "fetchRaw", { enumerable: true, get: function () { return fetch_1.fetchRaw; } });
16
16
  const k8s_1 = require("./src/lib/k8s");
17
+ Object.defineProperty(exports, "RegisterKind", { enumerable: true, get: function () { return k8s_1.RegisterKind; } });
17
18
  Object.defineProperty(exports, "a", { enumerable: true, get: function () { return k8s_1.a; } });
18
19
  const logger_1 = __importDefault(require("./src/lib/logger"));
19
20
  exports.Log = logger_1.default;
20
21
  const module_1 = require("./src/lib/module");
21
22
  Object.defineProperty(exports, "PeprModule", { enumerable: true, get: function () { return module_1.PeprModule; } });
23
+ const request_1 = require("./src/lib/request");
24
+ Object.defineProperty(exports, "PeprRequest", { enumerable: true, get: function () { return request_1.PeprRequest; } });
package/dist/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "engines": {
10
10
  "node": ">=18.0.0"
11
11
  },
12
- "version": "0.1.43",
12
+ "version": "0.1.45",
13
13
  "main": "dist/index.js",
14
14
  "types": "dist/index.d.ts",
15
15
  "pepr": {
@@ -27,20 +27,21 @@
27
27
  "prebuild": "rm -fr dist/* && node hack/build-template-data.js",
28
28
  "build": "tsc -p tsconfig.build.json",
29
29
  "test": "npm run build && ava && node dist/cli.js -V",
30
+ "test:e2e": "ava hack/e2e.test.js",
31
+ "test:e2e-setup": "npm run build && npm uninstall pepr -g && npm install -g .",
30
32
  "lint": "npx eslint src",
31
33
  "lint:fix": "npm run lint -- --fix",
32
34
  "prettier": "npx prettier src --check",
33
35
  "prettier:fix": "npm run prettier -- --write",
34
36
  "prepublishOnly": "npm run lint:fix && npm run prettier:fix && npm run test",
35
- "e2e-dev-setup": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'",
36
- "e2e-dev": "npm run build && docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev && node dist/pepr-cli.js deploy -f -i pepr:dev"
37
+ "e2e-dev-setup": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'"
37
38
  },
38
39
  "dependencies": {
39
40
  "@kubernetes/client-node": "^0.18.1",
40
41
  "@rollup/plugin-json": "^6.0.0",
41
42
  "@rollup/plugin-node-resolve": "^15.0.1",
42
43
  "@rollup/plugin-typescript": "^11.0.0",
43
- "@types/ramda": "^0.28.23",
44
+ "@types/ramda": "^0.29.0",
44
45
  "chokidar": "^3.5.3",
45
46
  "commander": "^10.0.0",
46
47
  "express": "^4.18.2",
@@ -19,16 +19,19 @@ function default_1(program) {
19
19
  .description("Setup a local webhook development environment")
20
20
  .option("-d, --dir [directory]", "Pepr module directory", ".")
21
21
  .option("-h, --host [host]", "Host to listen on", "host.docker.internal")
22
+ .option("--confirm", "Skip confirmation prompt")
22
23
  .action(async (opts) => {
23
- // Prompt the user to confirm
24
- const confirm = await (0, prompts_1.prompt)({
25
- type: "confirm",
26
- name: "confirm",
27
- message: "This will remove and redeploy the module. Continue?",
28
- });
29
- // Exit if the user doesn't confirm
30
- if (!confirm.confirm) {
31
- process.exit(0);
24
+ // Prompt the user to confirm if they didn't pass the --confirm flag
25
+ if (!opts.confirm) {
26
+ const confirm = await (0, prompts_1.prompt)({
27
+ type: "confirm",
28
+ name: "confirm",
29
+ message: "This will remove and redeploy the module. Continue?",
30
+ });
31
+ // Exit if the user doesn't confirm
32
+ if (!confirm.confirm) {
33
+ process.exit(0);
34
+ }
32
35
  }
33
36
  // Build the module
34
37
  const { cfg, path } = await (0, build_1.buildModule)(opts.dir);
@@ -12,6 +12,7 @@ const deploy_1 = __importDefault(require("./deploy"));
12
12
  const dev_1 = __importDefault(require("./dev"));
13
13
  const init_1 = __importDefault(require("./init"));
14
14
  const root_1 = require("./root");
15
+ const update_1 = __importDefault(require("./update"));
15
16
  const program = new root_1.RootCmd();
16
17
  program
17
18
  .version(package_json_1.version)
@@ -26,6 +27,7 @@ program
26
27
  (0, build_1.default)(program);
27
28
  (0, deploy_1.default)(program);
28
29
  (0, dev_1.default)(program);
30
+ (0, update_1.default)(program);
29
31
  // @todo: finish/re-evaluate these commands
30
32
  // test(program);
31
33
  // capability(program);
@@ -7,6 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  const child_process_1 = require("child_process");
9
9
  const path_1 = require("path");
10
+ const prompts_1 = __importDefault(require("prompts"));
10
11
  const logger_1 = __importDefault(require("../../../src/lib/logger"));
11
12
  const templates_1 = require("./templates");
12
13
  const utils_1 = require("./utils");
@@ -18,9 +19,15 @@ function default_1(program) {
18
19
  // skip auto npm install and git init
19
20
  .option("--skip-post-init", "Skip npm install, git init and VSCode launch")
20
21
  .action(async (opts) => {
22
+ let pkgOverride = "";
23
+ // Overrides for testing. @todo: don't be so gross with Node CLI testing
24
+ if (process.env.TEST_MODE === "true") {
25
+ prompts_1.default.inject(["pepr-test-module", "A test module for Pepr", "ignore", "y"]);
26
+ pkgOverride = "file:../";
27
+ }
21
28
  const response = await (0, walkthrough_1.walkthrough)();
22
29
  const dirName = (0, utils_1.sanitizeName)(response.name);
23
- const packageJSON = (0, templates_1.genPkgJSON)(response);
30
+ const packageJSON = (0, templates_1.genPkgJSON)(response, pkgOverride);
24
31
  const peprTS = (0, templates_1.genPeprTS)();
25
32
  const confirmed = await (0, walkthrough_1.confirm)(dirName, packageJSON, peprTS.path);
26
33
  if (confirmed) {
@@ -1 +1 @@
1
- { "gitignore": "# Ignore node_modules and Pepr build artifacts\nnode_modules\ndist\ninsecure*\n", "readme": "# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a Kubernetes tranformation system\nwritten in Typescript.\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├── package.json\n├── pepr.ts\n└── capabilities\n ├── example-one.ts\n ├── example-three.ts\n └── example-two.ts\n```\n", "peprTS": "import { PeprModule } from \"pepr\";\nimport { HelloPepr } from \"./capabilities/hello-pepr\";\nimport cfg from \"./package.json\";\n\n/**\n * This is the main entrypoint for the Pepr module. It is the file that is run when the module is started.\n * This is where you register your configurations and capabilities with the module.\n */\nnew PeprModule(cfg, [\n // \"HelloPepr\" is a demo capability that is included with Pepr. You can remove it if you want.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n", "helloPeprTS": "import { Capability, a } 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 can run `pepr dev` or `npm start` 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\"],\n});\n\n// Use the 'When' function to create a new Capability Action\nconst { When } = HelloPepr;\n\n/**\n * This is a single Capability Action. They can be in the same file or imported from other files.\n * In this exmaple, when a ConfigMap is created with the name `example-1`, we add a label and annotation.\n *\n * Equivelant 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 .Then(request => {\n request.SetLabel(\"pepr\", \"was-here\").SetAnnotation(\"pepr.dev\", \"annotations-work-too\");\n });\n\n/**\n * This Capabiility Action does the exact same changes for example-2, except this time it uses the `.ThenSet()` feature.\n * You can stack multiple `.Then()` calls, but only a single `.ThenSet()`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName(\"example-2\")\n .ThenSet({\n metadata: {\n labels: {\n pepr: \"was-here\",\n },\n annotations: {\n \"pepr.dev\": \"annotations-work-too\",\n },\n },\n });\n\n/**\n * This Capability Action combines different styles. Unlike the previous actions, this one will look for any ConfigMap\n * in the `pepr-demo` namespace that has the label `change=by-label` during either CREATE or UPDATE. Note that all\n * conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`, are ANDs so all conditions must be true\n * for the request to be procssed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel(\"change\", \"by-label\")\n .Then(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 reuest\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" }
1
+ { "gitignore": "# Ignore node_modules and Pepr build artifacts\nnode_modules\ndist\ninsecure*\n", "readme": "# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a Kubernetes transformation system\nwritten in Typescript.\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├── package.json\n├── pepr.ts\n└── capabilities\n ├── example-one.ts\n ├── example-three.ts\n └── example-two.ts\n```\n", "peprTS": "import { PeprModule } from \"pepr\";\nimport { HelloPepr } from \"./capabilities/hello-pepr\";\nimport cfg from \"./package.json\";\n\n/**\n * This is the main entrypoint for the Pepr module. It is the file that is run when the module is started.\n * This is where you register your configurations and capabilities with the module.\n */\nnew PeprModule(cfg, [\n // \"HelloPepr\" is a demo capability that is included with Pepr. You can remove it if you want.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n", "helloPeprTS": "import { Capability, PeprRequest, RegisterKind, a, fetch } 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 can run `pepr dev` or `npm start` 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\"],\n});\n\n// Use the 'When' function to create a new Capability Action\nconst { When } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * CAPABILITY ACTION *\n * ---------------------------------------------------------------------------------------------------\n *\n * This Capability 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 .Then(ns => ns.RemoveLabel(\"remove-me\"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * CAPABILITY ACTION *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single Capability Action. They can be in the same file or put imported from other files.\n * In this exmaple, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivelant 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 .Then(request =>\n request\n .SetLabel(\"pepr\", \"was-here\")\n .SetAnnotation(\"pepr.dev\", \"annotations-work-too\")\n );\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * CAPABILITY ACTION *\n * ---------------------------------------------------------------------------------------------------\n *\n * This Capabiility Action does the exact same changes for example-2, except this time it uses\n * the `.ThenSet()` feature. You can stack multiple `.Then()` calls, but only a single `.ThenSet()`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName(\"example-2\")\n .ThenSet({\n metadata: {\n labels: {\n pepr: \"was-here\",\n },\n annotations: {\n \"pepr.dev\": \"annotations-work-too\",\n },\n },\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * CAPABILITY ACTION *\n * ---------------------------------------------------------------------------------------------------\n *\n * This Capability 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 procssed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel(\"change\", \"by-label\")\n .Then(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 reuest\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/**\n * ---------------------------------------------------------------------------------------------------\n * CAPABILITY ACTION *\n * ---------------------------------------------------------------------------------------------------\n *\n * This Capability Action show how you can use the `Then()` function to make multiple changes to the\n * same object from different functions. This is useful if you want to keep your Capability Actions\n * small and focused on a single task, or if you want to reuse the same function in multiple\n * Capability Actions.\n *\n * Note that the order of the `.Then()` calls matters. The first call will be executed first,\n * then the second, and so on. Also note the functions are not called until the Capability Action\n * is triggered.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName(\"example-5\")\n .Then(cm => cm.SetLabel(\"pepr.dev/first\", \"true\"))\n .Then(addSecond)\n .Then(addThird);\n\n//This function uses the complete type definition, but is not required.\nfunction addSecond(cm: PeprRequest<a.ConfigMap>) {\n cm.SetLabel(\"pepr.dev/second\", \"true\");\n}\n\n// This function has no type definition, so you won't have intelisense in the function body.\nfunction addThird(cm) {\n cm.SetLabel(\"pepr.dev/third\", \"true\");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * CAPABILITY ACTION *\n * ---------------------------------------------------------------------------------------------------\n *\n * This Capability 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 Capability 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 equivelant:\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 .Then(async change => {\n const joke = await fetch<TheChuckNorrisJoke>(\n \"https://api.chucknorris.io/jokes/random?category=dev\"\n );\n\n // Add the Chuck Norris joke to the configmap\n change.Raw.data[\"chuck-says\"] = joke.value;\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * CAPABILITY ACTION *\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 Capability Action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intelisense 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 ot 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 .ThenSet({\n spec: {\n message: \"Hello Pepr without type data!\",\n counter: Math.random(),\n },\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * CAPABILITY ACTION *\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 intelisense\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 Capability 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 Capability Actions, but we are putting it here for demonstration purposes.\n *\n * You will need ot 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 .ThenSet({\n spec: {\n message: \"Hello Pepr now with type data!\",\n counter: Math.random(),\n },\n });\n" }
@@ -3,7 +3,11 @@
3
3
  "apiVersion": "v1",
4
4
  "kind": "Namespace",
5
5
  "metadata": {
6
- "name": "pepr-demo"
6
+ "name": "pepr-demo",
7
+ "labels": {
8
+ "keep-me": "please",
9
+ "remove-me": "please"
10
+ }
7
11
  }
8
12
  },
9
13
  {
@@ -41,5 +45,68 @@
41
45
  "data": {
42
46
  "key": "ex-3-val"
43
47
  }
48
+ },
49
+ {
50
+ "apiVersion": "v1",
51
+ "kind": "ConfigMap",
52
+ "metadata": {
53
+ "name": "example-4",
54
+ "namespace": "pepr-demo",
55
+ "labels": {
56
+ "chuck-norris": "test"
57
+ }
58
+ },
59
+ "data": {
60
+ "key": "ex-4-val"
61
+ }
62
+ },
63
+ {
64
+ "apiVersion": "v1",
65
+ "kind": "ConfigMap",
66
+ "metadata": {
67
+ "name": "example-5",
68
+ "namespace": "pepr-demo"
69
+ }
70
+ },
71
+ {
72
+ "apiVersion": "apiextensions.k8s.io/v1",
73
+ "kind": "CustomResourceDefinition",
74
+ "metadata": {
75
+ "name": "unicorns.pepr.dev"
76
+ },
77
+ "spec": {
78
+ "group": "pepr.dev",
79
+ "versions": [
80
+ {
81
+ "name": "v1",
82
+ "served": true,
83
+ "storage": true,
84
+ "schema": {
85
+ "openAPIV3Schema": {
86
+ "type": "object",
87
+ "properties": {
88
+ "spec": {
89
+ "type": "object",
90
+ "properties": {
91
+ "message": {
92
+ "type": "string"
93
+ },
94
+ "counter": {
95
+ "type": "number"
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ ],
104
+ "scope": "Namespaced",
105
+ "names": {
106
+ "plural": "unicorns",
107
+ "singular": "unicorn",
108
+ "kind": "Unicorn"
109
+ }
110
+ }
44
111
  }
45
112
  ]
@@ -1,5 +1,5 @@
1
1
  import { InitOptions } from "./walkthrough";
2
- export declare function genPkgJSON(opts: InitOptions): {
2
+ export declare function genPkgJSON(opts: InitOptions, pgkVerOverride?: string): {
3
3
  data: {
4
4
  name: string;
5
5
  version: string;
@@ -25,6 +25,7 @@ export declare function genPkgJSON(opts: InitOptions): {
25
25
  };
26
26
  devDependencies: {
27
27
  typescript: string;
28
+ "ts-node": string;
28
29
  };
29
30
  };
30
31
  path: string;
@@ -10,19 +10,19 @@ const client_node_1 = require("@kubernetes/client-node");
10
10
  const util_1 = require("util");
11
11
  const uuid_1 = require("uuid");
12
12
  const package_json_1 = require("../../../package.json");
13
+ const _prettierrc_json_1 = __importDefault(require("./templates/.prettierrc.json"));
13
14
  const data_json_1 = __importDefault(require("./templates/data.json"));
14
15
  const pepr_code_snippets_json_1 = __importDefault(require("./templates/pepr.code-snippets.json"));
15
- const prettierrc_json_1 = __importDefault(require("./templates/prettierrc.json"));
16
16
  const samples_json_1 = __importDefault(require("./templates/samples.json"));
17
17
  const tsconfig_module_json_1 = __importDefault(require("./templates/tsconfig.module.json"));
18
18
  const utils_1 = require("./utils");
19
- function genPkgJSON(opts) {
19
+ function genPkgJSON(opts, pgkVerOverride) {
20
20
  // Generate a random UUID for the module based on the module name
21
21
  const uuid = (0, uuid_1.v5)(opts.name, (0, uuid_1.v4)());
22
22
  // Generate a name for the module based on the module name
23
23
  const name = (0, utils_1.sanitizeName)(opts.name);
24
24
  // Make typescript a dev dependency
25
- const { typescript } = package_json_1.dependencies;
25
+ const { typescript, "ts-node": tsNode } = package_json_1.dependencies;
26
26
  const data = {
27
27
  name,
28
28
  version: "0.0.1",
@@ -31,7 +31,7 @@ function genPkgJSON(opts) {
31
31
  pepr: {
32
32
  name: opts.name.trim(),
33
33
  version: package_json_1.version,
34
- uuid,
34
+ uuid: pgkVerOverride ? "static-test" : uuid,
35
35
  onError: opts.errorBehavior,
36
36
  alwaysIgnore: {
37
37
  namespaces: [],
@@ -44,10 +44,11 @@ function genPkgJSON(opts) {
44
44
  start: "pepr dev",
45
45
  },
46
46
  dependencies: {
47
- pepr: `^${package_json_1.version}`,
47
+ pepr: pgkVerOverride || `^${package_json_1.version}`,
48
48
  },
49
49
  devDependencies: {
50
50
  typescript,
51
+ "ts-node": tsNode,
51
52
  },
52
53
  };
53
54
  return {
@@ -90,5 +91,5 @@ exports.tsConfig = {
90
91
  };
91
92
  exports.prettierRC = {
92
93
  path: ".prettierrc",
93
- data: prettierrc_json_1.default,
94
+ data: _prettierrc_json_1.default,
94
95
  };
@@ -0,0 +1,2 @@
1
+ import { RootCmd } from "./root";
2
+ export default function (program: RootCmd): void;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const child_process_1 = require("child_process");
9
+ const path_1 = require("path");
10
+ const prompts_1 = require("prompts");
11
+ const logger_1 = __importDefault(require("../../src/lib/logger"));
12
+ const templates_1 = require("./init/templates");
13
+ const utils_1 = require("./init/utils");
14
+ function default_1(program) {
15
+ program
16
+ .command("update")
17
+ .description("Update this Pepr module")
18
+ .option("--skip-template-update", "Skip updating the template files`")
19
+ .action(async (opts) => {
20
+ if (!opts.skipTemplateUpdate) {
21
+ const { confirm } = await (0, prompts_1.prompt)({
22
+ type: "confirm",
23
+ name: "confirm",
24
+ message: "This will overwrite previously auto-generated files inluding the capabilities/HelloPepr.ts file.\n" +
25
+ "Are you sure you want to continue?",
26
+ });
27
+ // If the user doesn't confirm, exit
28
+ if (!confirm) {
29
+ return;
30
+ }
31
+ }
32
+ console.log("Updating the Pepr module...");
33
+ try {
34
+ await (0, utils_1.write)((0, path_1.resolve)(templates_1.prettierRC.path), templates_1.prettierRC.data);
35
+ await (0, utils_1.write)((0, path_1.resolve)(templates_1.tsConfig.path), templates_1.tsConfig.data);
36
+ await (0, utils_1.write)((0, path_1.resolve)(".vscode", templates_1.snippet.path), templates_1.snippet.data);
37
+ await (0, utils_1.write)((0, path_1.resolve)("capabilities", templates_1.samplesYaml.path), templates_1.samplesYaml.data);
38
+ await (0, utils_1.write)((0, path_1.resolve)("capabilities", templates_1.helloPeprTS.path), templates_1.helloPeprTS.data);
39
+ // Update Pepr for the module
40
+ (0, child_process_1.execSync)("npm install pepr@latest", {
41
+ stdio: "inherit",
42
+ });
43
+ // Update Pepr globally
44
+ (0, child_process_1.execSync)("npm install -g pepr@latest", {
45
+ stdio: "inherit",
46
+ });
47
+ console.log(`Module updated!`);
48
+ }
49
+ catch (e) {
50
+ logger_1.default.debug(e);
51
+ logger_1.default.error(e.message);
52
+ process.exit(1);
53
+ }
54
+ });
55
+ }
56
+ exports.default = default_1;
@@ -1,3 +1,4 @@
1
+ import { GroupVersionKind } from "./k8s";
1
2
  import { Binding, CapabilityCfg, GenericClass, HookPhase, WhenSelector } from "./types";
2
3
  /**
3
4
  * A capability is a unit of functionality that can be registered with the Pepr runtime.
@@ -19,8 +20,9 @@ export declare class Capability implements CapabilityCfg {
19
20
  * processed by Pepr. The action will be executed if the resource matches the specified kind and any
20
21
  * filters that are applied.
21
22
  *
22
- * @param model if using a custom KubernetesObject not available in `a.*`, specify the GroupVersionKind
23
+ * @param model the KubernetesObject model to match
24
+ * @param kind if using a custom KubernetesObject not available in `a.*`, specify the GroupVersionKind
23
25
  * @returns
24
26
  */
25
- When: <T extends GenericClass>(model: T) => WhenSelector<T>;
27
+ When: <T extends GenericClass>(model: T, kind?: GroupVersionKind) => WhenSelector<T>;
26
28
  }
@@ -37,13 +37,19 @@ class Capability {
37
37
  * processed by Pepr. The action will be executed if the resource matches the specified kind and any
38
38
  * filters that are applied.
39
39
  *
40
- * @param model if using a custom KubernetesObject not available in `a.*`, specify the GroupVersionKind
40
+ * @param model the KubernetesObject model to match
41
+ * @param kind if using a custom KubernetesObject not available in `a.*`, specify the GroupVersionKind
41
42
  * @returns
42
43
  */
43
- this.When = (model) => {
44
+ this.When = (model, kind) => {
45
+ const matchedKind = (0, k8s_1.modelToGroupVersionKind)(model.name);
46
+ // If the kind is not specified and the model is not a KubernetesObject, throw an error
47
+ if (!matchedKind && !kind) {
48
+ throw new Error(`Kind not specified for ${model.name}`);
49
+ }
44
50
  const binding = {
45
- // If the kind is not specified, use the default KubernetesObject
46
- kind: (0, k8s_1.modelToGroupVersionKind)(model.name),
51
+ // If the kind is not specified, use the matched kind from the model
52
+ kind: kind || matchedKind,
47
53
  filters: {
48
54
  name: "",
49
55
  namespaces: [],
@@ -15,34 +15,59 @@ const logger_1 = __importDefault(require("./logger"));
15
15
  * @returns
16
16
  */
17
17
  function shouldSkipRequest(binding, req) {
18
- const { group, kind, version } = binding.kind;
19
- const { namespaces, labels, annotations } = binding.filters;
20
- const { metadata } = req.object;
18
+ const { group, kind, version } = binding.kind || {};
19
+ const { namespaces, labels, annotations, name } = binding.filters || {};
20
+ const { metadata } = req.object || {};
21
+ // Test name first, since it's the most specific
22
+ if (name && name !== req.name) {
23
+ return true;
24
+ }
25
+ // Test for matching kinds
21
26
  if (kind !== req.kind.kind) {
22
27
  return true;
23
28
  }
29
+ // Test for matching groups
24
30
  if (group && group !== req.kind.group) {
25
31
  return true;
26
32
  }
33
+ // Test for matching versions
27
34
  if (version && version !== req.kind.version) {
28
35
  return true;
29
36
  }
37
+ // Test for matching namespaces
30
38
  if (namespaces.length && !namespaces.includes(req.namespace || "")) {
31
39
  logger_1.default.debug("Namespace does not match");
32
40
  return true;
33
41
  }
42
+ // Test for matching lables
34
43
  for (const [key, value] of Object.entries(labels)) {
35
- if (metadata?.labels?.[key] !== value) {
36
- logger_1.default.debug(`${metadata?.labels?.[key]} does not match ${value}`);
44
+ const testKey = metadata?.labels?.[key];
45
+ // First check if the label exists
46
+ if (!testKey) {
47
+ logger_1.default.debug(`Label ${key} does not exist`);
48
+ return true;
49
+ }
50
+ // Then check if the value matches, if specified
51
+ if (value && testKey !== value) {
52
+ logger_1.default.debug(`${testKey} does not match ${value}`);
37
53
  return true;
38
54
  }
39
55
  }
56
+ // Test for matching annotations
40
57
  for (const [key, value] of Object.entries(annotations)) {
41
- if (metadata?.annotations?.[key] !== value) {
42
- logger_1.default.debug(`${metadata?.annotations?.[key]} does not match ${value}`);
58
+ const testKey = metadata?.annotations?.[key];
59
+ // First check if the annotation exists
60
+ if (!testKey) {
61
+ logger_1.default.debug(`Annotation ${key} does not exist`);
62
+ return true;
63
+ }
64
+ // Then check if the value matches, if specified
65
+ if (value && testKey !== value) {
66
+ logger_1.default.debug(`${testKey} does not match ${value}`);
43
67
  return true;
44
68
  }
45
69
  }
70
+ // No failed filters, so we should not skip this request
46
71
  return false;
47
72
  }
48
73
  exports.shouldSkipRequest = shouldSkipRequest;
@@ -1,5 +1,5 @@
1
1
  import * as kind from "./upstream";
2
2
  /** a is a colleciton of K8s types to be used within a CapabilityAction: `When(a.Configmap)` */
3
3
  export { kind as a };
4
- export { modelToGroupVersionKind, gvkMap } from "./kinds";
4
+ export { modelToGroupVersionKind, gvkMap, RegisterKind } from "./kinds";
5
5
  export * from "./types";
@@ -28,11 +28,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
28
28
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.gvkMap = exports.modelToGroupVersionKind = exports.a = void 0;
31
+ exports.RegisterKind = exports.gvkMap = exports.modelToGroupVersionKind = exports.a = void 0;
32
32
  // Export kinds as a single object
33
33
  const kind = __importStar(require("./upstream"));
34
34
  exports.a = kind;
35
35
  var kinds_1 = require("./kinds");
36
36
  Object.defineProperty(exports, "modelToGroupVersionKind", { enumerable: true, get: function () { return kinds_1.modelToGroupVersionKind; } });
37
37
  Object.defineProperty(exports, "gvkMap", { enumerable: true, get: function () { return kinds_1.gvkMap; } });
38
+ Object.defineProperty(exports, "RegisterKind", { enumerable: true, get: function () { return kinds_1.RegisterKind; } });
38
39
  __exportStar(require("./types"), exports);
@@ -1,3 +1,11 @@
1
+ import { GenericClass } from "../types";
1
2
  import { GroupVersionKind } from "./types";
2
3
  export declare const gvkMap: Record<string, GroupVersionKind>;
3
4
  export declare function modelToGroupVersionKind(key: string): GroupVersionKind;
5
+ /**
6
+ * Registers a new model and GroupVersionKind with Pepr for use with `When(a.<Kind>)`
7
+ *
8
+ * @param model Used to match the GroupVersionKind and define the type-data for the request
9
+ * @param groupVersionKind Contains the match paramaters to determine the request should be handled
10
+ */
11
+ export declare const RegisterKind: (model: GenericClass, groupVersionKind: GroupVersionKind) => void;
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.modelToGroupVersionKind = exports.gvkMap = void 0;
5
+ exports.RegisterKind = exports.modelToGroupVersionKind = exports.gvkMap = void 0;
6
6
  exports.gvkMap = {
7
7
  /**
8
8
  * Represents a K8s ConfigMap resource.
@@ -429,3 +429,19 @@ function modelToGroupVersionKind(key) {
429
429
  return exports.gvkMap[key];
430
430
  }
431
431
  exports.modelToGroupVersionKind = modelToGroupVersionKind;
432
+ /**
433
+ * Registers a new model and GroupVersionKind with Pepr for use with `When(a.<Kind>)`
434
+ *
435
+ * @param model Used to match the GroupVersionKind and define the type-data for the request
436
+ * @param groupVersionKind Contains the match paramaters to determine the request should be handled
437
+ */
438
+ const RegisterKind = (model, groupVersionKind) => {
439
+ const name = model.name;
440
+ // Do not allow overwriting existing GVKs
441
+ if (exports.gvkMap[name]) {
442
+ throw new Error(`GVK ${name} already registered`);
443
+ }
444
+ // Set the GVK
445
+ exports.gvkMap[name] = groupVersionKind;
446
+ };
447
+ exports.RegisterKind = RegisterKind;
@@ -16,6 +16,17 @@ export interface KubernetesListObject<T extends KubernetesObject> {
16
16
  metadata?: V1ListMeta;
17
17
  items: T[];
18
18
  }
19
+ /**
20
+ * GenericKind is a generic Kubernetes object that can be used to represent any Kubernetes object
21
+ * that is not explicitly supported by Pepr. This can be used on its own or as a base class for
22
+ * other types. See the examples in `HelloPepr.ts` for more information.
23
+ */
24
+ export declare class GenericKind {
25
+ apiVersion?: string;
26
+ kind?: string;
27
+ metadata?: V1ObjectMeta;
28
+ [key: string]: any;
29
+ }
19
30
  /**
20
31
  * GroupVersionKind unambiguously identifies a kind. It doesn't anonymously include GroupVersion
21
32
  * to avoid automatic coercion. It doesn't use a GroupVersion to avoid custom marshalling
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.Operation = void 0;
5
+ exports.GenericKind = exports.Operation = void 0;
6
6
  var Operation;
7
7
  (function (Operation) {
8
8
  Operation["CREATE"] = "CREATE";
@@ -10,3 +10,11 @@ var Operation;
10
10
  Operation["DELETE"] = "DELETE";
11
11
  Operation["CONNECT"] = "CONNECT";
12
12
  })(Operation = exports.Operation || (exports.Operation = {}));
13
+ /**
14
+ * GenericKind is a generic Kubernetes object that can be used to represent any Kubernetes object
15
+ * that is not explicitly supported by Pepr. This can be used on its own or as a base class for
16
+ * other types. See the examples in `HelloPepr.ts` for more information.
17
+ */
18
+ class GenericKind {
19
+ }
20
+ exports.GenericKind = GenericKind;
@@ -1,2 +1,3 @@
1
1
  /** a is a colleciton of K8s types to be used within a CapabilityAction: `When(a.Configmap)` */
2
2
  export { V1APIService as APIService, V1CertificateSigningRequest as CertificateSigningRequest, V1ConfigMap as ConfigMap, V1ControllerRevision as ControllerRevision, V1CronJob as CronJob, V1CSIDriver as CSIDriver, V1CSIStorageCapacity as CSIStorageCapacity, V1CustomResourceDefinition as CustomResourceDefinition, V1DaemonSet as DaemonSet, V1Deployment as Deployment, V1EndpointSlice as EndpointSlice, V1HorizontalPodAutoscaler as HorizontalPodAutoscaler, V1Ingress as Ingress, V1IngressClass as IngressClass, V1Job as Job, V1LimitRange as LimitRange, V1LocalSubjectAccessReview as LocalSubjectAccessReview, V1MutatingWebhookConfiguration as MutatingWebhookConfiguration, V1Namespace as Namespace, V1NetworkPolicy as NetworkPolicy, V1Node as Node, V1PersistentVolume as PersistentVolume, V1PersistentVolumeClaim as PersistentVolumeClaim, V1Pod as Pod, V1PodDisruptionBudget as PodDisruptionBudget, V1PodTemplate as PodTemplate, V1ReplicaSet as ReplicaSet, V1ReplicationController as ReplicationController, V1ResourceQuota as ResourceQuota, V1RuntimeClass as RuntimeClass, V1Secret as Secret, V1SelfSubjectAccessReview as SelfSubjectAccessReview, V1SelfSubjectRulesReview as SelfSubjectRulesReview, V1Service as Service, V1ServiceAccount as ServiceAccount, V1StatefulSet as StatefulSet, V1StorageClass as StorageClass, V1SubjectAccessReview as SubjectAccessReview, V1TokenReview as TokenReview, V1ValidatingWebhookConfiguration as ValidatingWebhookConfiguration, V1VolumeAttachment as VolumeAttachment, } from "@kubernetes/client-node/dist";
3
+ export { GenericKind } from "./types";
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.VolumeAttachment = exports.ValidatingWebhookConfiguration = exports.TokenReview = exports.SubjectAccessReview = exports.StorageClass = exports.StatefulSet = exports.ServiceAccount = exports.Service = exports.SelfSubjectRulesReview = exports.SelfSubjectAccessReview = exports.Secret = exports.RuntimeClass = exports.ResourceQuota = exports.ReplicationController = exports.ReplicaSet = exports.PodTemplate = exports.PodDisruptionBudget = exports.Pod = exports.PersistentVolumeClaim = exports.PersistentVolume = exports.Node = exports.NetworkPolicy = exports.Namespace = exports.MutatingWebhookConfiguration = exports.LocalSubjectAccessReview = exports.LimitRange = exports.Job = exports.IngressClass = exports.Ingress = exports.HorizontalPodAutoscaler = exports.EndpointSlice = exports.Deployment = exports.DaemonSet = exports.CustomResourceDefinition = exports.CSIStorageCapacity = exports.CSIDriver = exports.CronJob = exports.ControllerRevision = exports.ConfigMap = exports.CertificateSigningRequest = exports.APIService = void 0;
5
+ exports.GenericKind = exports.VolumeAttachment = exports.ValidatingWebhookConfiguration = exports.TokenReview = exports.SubjectAccessReview = exports.StorageClass = exports.StatefulSet = exports.ServiceAccount = exports.Service = exports.SelfSubjectRulesReview = exports.SelfSubjectAccessReview = exports.Secret = exports.RuntimeClass = exports.ResourceQuota = exports.ReplicationController = exports.ReplicaSet = exports.PodTemplate = exports.PodDisruptionBudget = exports.Pod = exports.PersistentVolumeClaim = exports.PersistentVolume = exports.Node = exports.NetworkPolicy = exports.Namespace = exports.MutatingWebhookConfiguration = exports.LocalSubjectAccessReview = exports.LimitRange = exports.Job = exports.IngressClass = exports.Ingress = exports.HorizontalPodAutoscaler = exports.EndpointSlice = exports.Deployment = exports.DaemonSet = exports.CustomResourceDefinition = exports.CSIStorageCapacity = exports.CSIDriver = exports.CronJob = exports.ControllerRevision = exports.ConfigMap = exports.CertificateSigningRequest = exports.APIService = void 0;
6
6
  /** a is a colleciton of K8s types to be used within a CapabilityAction: `When(a.Configmap)` */
7
7
  var dist_1 = require("@kubernetes/client-node/dist");
8
8
  Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return dist_1.V1APIService; } });
@@ -46,3 +46,5 @@ Object.defineProperty(exports, "SubjectAccessReview", { enumerable: true, get: f
46
46
  Object.defineProperty(exports, "TokenReview", { enumerable: true, get: function () { return dist_1.V1TokenReview; } });
47
47
  Object.defineProperty(exports, "ValidatingWebhookConfiguration", { enumerable: true, get: function () { return dist_1.V1ValidatingWebhookConfiguration; } });
48
48
  Object.defineProperty(exports, "VolumeAttachment", { enumerable: true, get: function () { return dist_1.V1VolumeAttachment; } });
49
+ var types_1 = require("./types");
50
+ Object.defineProperty(exports, "GenericKind", { enumerable: true, get: function () { return types_1.GenericKind; } });
@@ -11,7 +11,7 @@ const filter_1 = require("./filter");
11
11
  const logger_1 = __importDefault(require("./logger"));
12
12
  const request_1 = require("./request");
13
13
  async function processor(config, capabilities, req) {
14
- const wrapped = new request_1.RequestWrapper(req);
14
+ const wrapped = new request_1.PeprRequest(req);
15
15
  const response = {
16
16
  uid: req.uid,
17
17
  warnings: [],
@@ -4,7 +4,7 @@ import { DeepPartial } from "./types";
4
4
  * The RequestWrapper class provides methods to modify Kubernetes objects in the context
5
5
  * of a mutating webhook request.
6
6
  */
7
- export declare class RequestWrapper<T extends KubernetesObject> {
7
+ export declare class PeprRequest<T extends KubernetesObject> {
8
8
  private _input;
9
9
  Raw: T;
10
10
  get PermitSideEffects(): boolean;
@@ -5,13 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.RequestWrapper = void 0;
8
+ exports.PeprRequest = void 0;
9
9
  const ramda_1 = __importDefault(require("ramda"));
10
10
  /**
11
11
  * The RequestWrapper class provides methods to modify Kubernetes objects in the context
12
12
  * of a mutating webhook request.
13
13
  */
14
- class RequestWrapper {
14
+ class PeprRequest {
15
15
  get PermitSideEffects() {
16
16
  return !this._input.dryRun;
17
17
  }
@@ -121,4 +121,4 @@ class RequestWrapper {
121
121
  return this.Raw?.metadata?.annotations?.[key] !== undefined;
122
122
  }
123
123
  }
124
- exports.RequestWrapper = RequestWrapper;
124
+ exports.PeprRequest = PeprRequest;
@@ -1,5 +1,5 @@
1
1
  import { GroupVersionKind, KubernetesObject, WebhookIgnore } from "./k8s";
2
- import { RequestWrapper } from "./request";
2
+ import { PeprRequest } from "./request";
3
3
  /**
4
4
  * The behavior of this module when an error occurs.
5
5
  */
@@ -184,4 +184,4 @@ export type BindToActionOrSet<T extends GenericClass> = BindToAction<T> & {
184
184
  */
185
185
  ThenSet: (val: DeepPartial<InstanceType<T>>) => BindToAction<T>;
186
186
  };
187
- export type CapabilityAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (req: RequestWrapper<K>) => Promise<void> | void | Promise<RequestWrapper<K>> | RequestWrapper<K>;
187
+ export type CapabilityAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (req: PeprRequest<K>) => Promise<void> | void | Promise<PeprRequest<K>> | PeprRequest<K>;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "engines": {
10
10
  "node": ">=18.0.0"
11
11
  },
12
- "version": "0.1.43",
12
+ "version": "0.1.45",
13
13
  "main": "dist/index.js",
14
14
  "types": "dist/index.d.ts",
15
15
  "pepr": {
@@ -27,20 +27,21 @@
27
27
  "prebuild": "rm -fr dist/* && node hack/build-template-data.js",
28
28
  "build": "tsc -p tsconfig.build.json",
29
29
  "test": "npm run build && ava && node dist/cli.js -V",
30
+ "test:e2e": "ava hack/e2e.test.js",
31
+ "test:e2e-setup": "npm run build && npm uninstall pepr -g && npm install -g .",
30
32
  "lint": "npx eslint src",
31
33
  "lint:fix": "npm run lint -- --fix",
32
34
  "prettier": "npx prettier src --check",
33
35
  "prettier:fix": "npm run prettier -- --write",
34
36
  "prepublishOnly": "npm run lint:fix && npm run prettier:fix && npm run test",
35
- "e2e-dev-setup": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'",
36
- "e2e-dev": "npm run build && docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev && node dist/pepr-cli.js deploy -f -i pepr:dev"
37
+ "e2e-dev-setup": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'"
37
38
  },
38
39
  "dependencies": {
39
40
  "@kubernetes/client-node": "^0.18.1",
40
41
  "@rollup/plugin-json": "^6.0.0",
41
42
  "@rollup/plugin-node-resolve": "^15.0.1",
42
43
  "@rollup/plugin-typescript": "^11.0.0",
43
- "@types/ramda": "^0.28.23",
44
+ "@types/ramda": "^0.29.0",
44
45
  "chokidar": "^3.5.3",
45
46
  "commander": "^10.0.0",
46
47
  "express": "^4.18.2",