pepr 0.1.42 → 0.1.44
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 +5 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/package.json +5 -4
- package/dist/src/cli/dev.js +12 -9
- package/dist/src/cli/index.js +2 -0
- package/dist/src/cli/init/index.js +8 -1
- package/dist/src/cli/init/templates/data.json +1 -1
- package/dist/src/cli/init/templates/samples.json +27 -1
- package/dist/src/cli/init/templates/tsconfig.module.json +12 -0
- package/dist/src/cli/init/templates.d.ts +2 -1
- package/dist/src/cli/init/templates.js +9 -8
- package/dist/src/cli/update.d.ts +2 -0
- package/dist/src/cli/update.js +56 -0
- package/dist/src/lib/filter.js +32 -7
- package/dist/src/lib/processor.js +1 -1
- package/dist/src/lib/request.d.ts +1 -1
- package/dist/src/lib/request.js +3 -3
- package/dist/src/lib/types.d.ts +2 -2
- package/package.json +5 -4
- package/hack/build-template-data.js +0 -23
- package/tsconfig.build.json +0 -4
- /package/dist/src/cli/init/templates/{prettierrc.json → .prettierrc.json} +0 -0
package/README.md
CHANGED
|
@@ -20,8 +20,12 @@ pepr init
|
|
|
20
20
|
|
|
21
21
|
# Follow the prompts...
|
|
22
22
|
|
|
23
|
-
#
|
|
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
|
@@ -5,8 +5,9 @@ import { fetch, fetchRaw } from "./src/lib/fetch";
|
|
|
5
5
|
import { 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, 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.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"));
|
|
@@ -19,3 +19,5 @@ const logger_1 = __importDefault(require("./src/lib/logger"));
|
|
|
19
19
|
exports.Log = logger_1.default;
|
|
20
20
|
const module_1 = require("./src/lib/module");
|
|
21
21
|
Object.defineProperty(exports, "PeprModule", { enumerable: true, get: function () { return module_1.PeprModule; } });
|
|
22
|
+
const request_1 = require("./src/lib/request");
|
|
23
|
+
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.
|
|
12
|
+
"version": "0.1.44",
|
|
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.
|
|
44
|
+
"@types/ramda": "^0.29.0",
|
|
44
45
|
"chokidar": "^3.5.3",
|
|
45
46
|
"commander": "^10.0.0",
|
|
46
47
|
"express": "^4.18.2",
|
package/dist/src/cli/dev.js
CHANGED
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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);
|
package/dist/src/cli/index.js
CHANGED
|
@@ -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
|
|
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, 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" }
|
|
@@ -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,27 @@
|
|
|
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
|
+
}
|
|
44
70
|
}
|
|
45
71
|
]
|
|
@@ -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
|
-
const
|
|
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 {
|
|
@@ -86,9 +87,9 @@ exports.snippet = {
|
|
|
86
87
|
};
|
|
87
88
|
exports.tsConfig = {
|
|
88
89
|
path: "tsconfig.json",
|
|
89
|
-
data:
|
|
90
|
+
data: tsconfig_module_json_1.default,
|
|
90
91
|
};
|
|
91
92
|
exports.prettierRC = {
|
|
92
93
|
path: ".prettierrc",
|
|
93
|
-
data:
|
|
94
|
+
data: _prettierrc_json_1.default,
|
|
94
95
|
};
|
|
@@ -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;
|
package/dist/src/lib/filter.js
CHANGED
|
@@ -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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
42
|
-
|
|
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;
|
|
@@ -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.
|
|
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
|
|
7
|
+
export declare class PeprRequest<T extends KubernetesObject> {
|
|
8
8
|
private _input;
|
|
9
9
|
Raw: T;
|
|
10
10
|
get PermitSideEffects(): boolean;
|
package/dist/src/lib/request.js
CHANGED
|
@@ -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.
|
|
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
|
|
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.
|
|
124
|
+
exports.PeprRequest = PeprRequest;
|
package/dist/src/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GroupVersionKind, KubernetesObject, WebhookIgnore } from "./k8s";
|
|
2
|
-
import {
|
|
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:
|
|
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.
|
|
12
|
+
"version": "0.1.44",
|
|
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.
|
|
44
|
+
"@types/ramda": "^0.29.0",
|
|
44
45
|
"chokidar": "^3.5.3",
|
|
45
46
|
"commander": "^10.0.0",
|
|
46
47
|
"express": "^4.18.2",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// This is a helper script to collect the contents of the template files before building the CLI
|
|
2
|
-
|
|
3
|
-
/* eslint-disable */
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
|
|
7
|
-
const baseDir = path.join(__dirname, "..", "src", "cli", "init", "templates");
|
|
8
|
-
|
|
9
|
-
// Read the text file
|
|
10
|
-
const gitignore = fs.readFileSync(path.join(baseDir, "gitignore"), "utf8");
|
|
11
|
-
const readme = fs.readFileSync(path.join(baseDir, "README.md"), "utf8");
|
|
12
|
-
const peprTS = fs.readFileSync(path.join(baseDir, "pepr.ts"), "utf8");
|
|
13
|
-
const helloPeprTS = fs.readFileSync(path.join(baseDir, "hello-pepr.ts"), "utf8");
|
|
14
|
-
|
|
15
|
-
fs.writeFileSync(
|
|
16
|
-
path.join(baseDir, "data.json"),
|
|
17
|
-
JSON.stringify({
|
|
18
|
-
gitignore,
|
|
19
|
-
readme,
|
|
20
|
-
peprTS,
|
|
21
|
-
helloPeprTS,
|
|
22
|
-
})
|
|
23
|
-
);
|
package/tsconfig.build.json
DELETED
|
File without changes
|