pepr 0.22.4 → 0.23.1
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 +9 -11
- package/dist/cli.js +11 -6
- package/dist/controller.js +1 -1
- package/package.json +5 -5
- package/BEST_PRACTICES.md +0 -37
- package/CODE_OF_CONDUCT.md +0 -83
- package/CONTRIBUTING.md +0 -70
package/README.md
CHANGED
|
@@ -12,13 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
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
14
|
|
|
15
|
-
#### _Note: Pepr is still in active development so breaking changes may occur, but will be documented in release notes._
|
|
16
|
-
|
|
17
15
|
## Features
|
|
18
16
|
|
|
19
17
|
- Zero-config K8s webhook mutations and validations
|
|
20
18
|
- Automatic leader-elected K8s resource watching
|
|
21
|
-
- Lightweight async key-value store backed by K8s for stateful operations with the [Pepr Store](./docs/
|
|
19
|
+
- Lightweight async key-value store backed by K8s for stateful operations with the [Pepr Store](./docs/030_user-guide/050_store.md)
|
|
22
20
|
- Human-readable fluent API for generating [Pepr Capabilities](#capability)
|
|
23
21
|
- A fluent API for creating/modifying/watching and server-side applying K8s resources via [Kubernetes Fluent Client](https://github.com/defenseunicorns/kubernetes-fluent-client)
|
|
24
22
|
- Generate new K8s resources based off of cluster resource changes
|
|
@@ -27,12 +25,12 @@ Pepr is on a mission to save Kubernetes from the tyranny of YAML, intimidating g
|
|
|
27
25
|
- Entire NPM ecosystem available for advanced operations
|
|
28
26
|
- Realtime K8s debugging system for testing/reacting to cluster changes
|
|
29
27
|
- Controller network isolation and tamper-resistent module execution
|
|
30
|
-
- Least-privilege [RBAC](
|
|
28
|
+
- Least-privilege [RBAC](./docs/030_user-guide/090_rbac.md) generation
|
|
31
29
|
- AMD64 and ARM64 support
|
|
32
30
|
|
|
33
31
|
## Example Pepr Action
|
|
34
32
|
|
|
35
|
-
This quick sample shows how to react to a ConfigMap being created or updated in the cluster. It adds a label and annotation to the ConfigMap and adds some data to the ConfigMap. It also creates a Validating Webhook to make sure the "pepr" label still exists. Finally, after the ConfigMap is created, it logs a message to the Pepr controller and creates or updates a separate ConfigMap with the [kubernetes-fluent-client](https://github.com/defenseunicorns/kubernetes-fluent-client) using server-side apply. For more details see [actions](./docs/
|
|
33
|
+
This quick sample shows how to react to a ConfigMap being created or updated in the cluster. It adds a label and annotation to the ConfigMap and adds some data to the ConfigMap. It also creates a Validating Webhook to make sure the "pepr" label still exists. Finally, after the ConfigMap is created, it logs a message to the Pepr controller and creates or updates a separate ConfigMap with the [kubernetes-fluent-client](https://github.com/defenseunicorns/kubernetes-fluent-client) using server-side apply. For more details see [actions](./docs/030_user-guide/030_actions.md) section.
|
|
36
34
|
|
|
37
35
|
```ts
|
|
38
36
|
When(a.ConfigMap)
|
|
@@ -80,9 +78,9 @@ When(a.ConfigMap)
|
|
|
80
78
|
## Prerequisites
|
|
81
79
|
|
|
82
80
|
- [Node.js](https://nodejs.org/en/) v18.0.0+ (even-numbered releases only)
|
|
83
|
-
- To ensure compatability and optimal performance, it is recommended to use even-numbered releases of Node.js as they are stable releases and receive long-term support for three years. Odd-numbered releases are experimental and may not be supported by certain libraries utilized in Pepr.
|
|
81
|
+
- To ensure compatability and optimal performance, it is recommended to use even-numbered releases of Node.js as they are stable releases and receive long-term support for three years. Odd-numbered releases are experimental and may not be supported by certain libraries utilized in Pepr.
|
|
84
82
|
|
|
85
|
-
- [npm](https://www.npmjs.com/) v10.1.0+
|
|
83
|
+
- [npm](https://www.npmjs.com/) v10.1.0+
|
|
86
84
|
|
|
87
85
|
- Recommended (optional) tools:
|
|
88
86
|
- [Visual Studio Code](https://code.visualstudio.com/) for inline debugging and [Pepr Capabilities](#capability) creation.
|
|
@@ -113,13 +111,13 @@ https://user-images.githubusercontent.com/882485/230895880-c5623077-f811-4870-bb
|
|
|
113
111
|
|
|
114
112
|
A module is the top-level collection of capabilities. It is a single, complete TypeScript project that includes an entry point to load all the configuration and capabilities, along with their actions. During the Pepr build process, each module produces a unique Kubernetes MutatingWebhookConfiguration and ValidatingWebhookConfiguration, along with a secret containing the transpiled and compressed TypeScript code. The webhooks and secret are deployed into the Kubernetes cluster with their own isolated controller.
|
|
115
113
|
|
|
116
|
-
See [Module](./docs/
|
|
114
|
+
See [Module](./docs/030_user-guide/020_pepr-modules.md) for more details.
|
|
117
115
|
|
|
118
116
|
### Capability
|
|
119
117
|
|
|
120
118
|
A capability is set of related actions that work together to achieve a specific transformation or operation on Kubernetes resources. Capabilities are user-defined and can include one or more actions. They are defined within a Pepr module and can be used in both MutatingWebhookConfigurations and ValidatingWebhookConfigurations. A Capability can have a specific scope, such as mutating or validating, and can be reused in multiple Pepr modules.
|
|
121
119
|
|
|
122
|
-
See [Capabilities](./docs/
|
|
120
|
+
See [Capabilities](./docs/030_user-guide/040_capabilities.md) for more details.
|
|
123
121
|
|
|
124
122
|
### Action
|
|
125
123
|
|
|
@@ -129,11 +127,11 @@ For example, an action could be responsible for adding a specific label to a Kub
|
|
|
129
127
|
|
|
130
128
|
There are both `Mutate()` and `Validate()` Actions that can be used to modify or validate Kubernetes resources within the admission controller lifecycle. There is also a `Watch()` Action that can be used to watch for changes to Kubernetes resources that already exist.
|
|
131
129
|
|
|
132
|
-
See [actions](./docs/
|
|
130
|
+
See [actions](./docs/030_user-guide/030_actions.md) for more details.
|
|
133
131
|
|
|
134
132
|
## Logical Pepr Flow
|
|
135
133
|
|
|
136
|
-

|
|
137
135
|
[Source Diagram](_images/pepr-arch.svg)
|
|
138
136
|
|
|
139
137
|
## TypeScript
|
package/dist/cli.js
CHANGED
|
@@ -1357,7 +1357,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
1357
1357
|
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';
|
|
1358
1358
|
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';
|
|
1359
1359
|
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';
|
|
1360
|
-
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.
|
|
1360
|
+
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.23.1", 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": "git clone https://github.com/defenseunicorns/pepr-upgrade-test.git", "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.10", express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.1.0", pino: "8.17.2", "pino-pretty": "10.3.1", "prom-client": "15.1.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.5.0", "@commitlint/config-conventional": "18.5.0", "@jest/globals": "29.7.0", "@types/eslint": "8.56.2", "@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.7", jest: "29.7.0", nock: "13.5.0", "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" } };
|
|
1361
1361
|
|
|
1362
1362
|
// src/templates/pepr.code-snippets.json
|
|
1363
1363
|
var pepr_code_snippets_default = {
|
|
@@ -1871,15 +1871,20 @@ var import_client_node3 = require("@kubernetes/client-node");
|
|
|
1871
1871
|
var import_kubernetes_fluent_client4 = require("kubernetes-fluent-client");
|
|
1872
1872
|
var import_stream = __toESM(require("stream"));
|
|
1873
1873
|
function monitor_default(program2) {
|
|
1874
|
-
program2.command("monitor
|
|
1874
|
+
program2.command("monitor [module-uuid]").description("Monitor a Pepr Module").action(async (uuid) => {
|
|
1875
|
+
let labels;
|
|
1876
|
+
let errorMessage;
|
|
1875
1877
|
if (!uuid) {
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
+
labels = ["pepr.dev/controller", "admission"];
|
|
1879
|
+
errorMessage = `No pods found with admission labels`;
|
|
1880
|
+
} else {
|
|
1881
|
+
labels = ["app", `pepr-${uuid}`];
|
|
1882
|
+
errorMessage = `No pods found for module ${uuid}`;
|
|
1878
1883
|
}
|
|
1879
|
-
const pods = await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.Pod).InNamespace("pepr-system").WithLabel(
|
|
1884
|
+
const pods = await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.Pod).InNamespace("pepr-system").WithLabel(labels[0], labels[1]).Get();
|
|
1880
1885
|
const podNames = pods.items.flatMap((pod) => pod.metadata.name);
|
|
1881
1886
|
if (podNames.length < 1) {
|
|
1882
|
-
console.error(
|
|
1887
|
+
console.error(errorMessage);
|
|
1883
1888
|
process.exit(1);
|
|
1884
1889
|
}
|
|
1885
1890
|
const kc = new import_client_node3.KubeConfig();
|
package/dist/controller.js
CHANGED
|
@@ -48,7 +48,7 @@ if (process.env.LOG_LEVEL) {
|
|
|
48
48
|
var logger_default = Log;
|
|
49
49
|
|
|
50
50
|
// src/templates/data.json
|
|
51
|
-
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.
|
|
51
|
+
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.23.1", 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": "git clone https://github.com/defenseunicorns/pepr-upgrade-test.git", "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.10", express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.1.0", pino: "8.17.2", "pino-pretty": "10.3.1", "prom-client": "15.1.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.5.0", "@commitlint/config-conventional": "18.5.0", "@jest/globals": "29.7.0", "@types/eslint": "8.56.2", "@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.7", jest: "29.7.0", nock: "13.5.0", "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
52
|
|
|
53
53
|
// src/runtime/controller.ts
|
|
54
54
|
var { version } = packageJSON;
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=18.0.0"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.23.1",
|
|
13
13
|
"main": "dist/lib.js",
|
|
14
14
|
"types": "dist/lib.d.ts",
|
|
15
15
|
"scripts": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"format:fix": "eslint src --fix && prettier src --write"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@types/ramda": "0.29.
|
|
34
|
+
"@types/ramda": "0.29.10",
|
|
35
35
|
"express": "4.18.2",
|
|
36
36
|
"fast-json-patch": "3.1.1",
|
|
37
37
|
"kubernetes-fluent-client": "2.1.0",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"ramda": "0.29.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "18.
|
|
45
|
-
"@commitlint/config-conventional": "18.
|
|
44
|
+
"@commitlint/cli": "18.5.0",
|
|
45
|
+
"@commitlint/config-conventional": "18.5.0",
|
|
46
46
|
"@jest/globals": "29.7.0",
|
|
47
47
|
"@types/eslint": "8.56.2",
|
|
48
48
|
"@types/express": "4.17.21",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@types/uuid": "9.0.7",
|
|
53
53
|
"jest": "29.7.0",
|
|
54
54
|
"nock": "13.5.0",
|
|
55
|
-
"ts-jest": "29.1.
|
|
55
|
+
"ts-jest": "29.1.2"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@typescript-eslint/eslint-plugin": "6.15.0",
|
package/BEST_PRACTICES.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Pepr Best Practices (WIP)
|
|
2
|
-
|
|
3
|
-
## TOC
|
|
4
|
-
|
|
5
|
-
- [Store](#pepr-store)
|
|
6
|
-
- [OnSchedule](#onschedule)
|
|
7
|
-
- [Watch](#watch)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Pepr Store
|
|
11
|
-
|
|
12
|
-
The store is backed by ETCD in a `PeprStore` resource, and updates happen at 5-second intervals when an array of patches is sent to the Kubernetes API Server. The store is intentionally not designed to be `transactional`; instead, it is built to be eventually consistent, meaning that the last operation within the interval will be persisted, potentially overwriting other operations. In simpler terms, changes to the data are made without a guarantee that they will occur simultaneously, so caution is needed in managing errors and ensuring consistency.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## OnSchedule
|
|
16
|
-
|
|
17
|
-
`OnSchedule` is supported by a `PeprStore` to safeguard against schedule loss following a pod restart. It is utilized at the top level, distinct from being within a `Validate`, `Mutate`, or `Watch`. Recommended intervals are 30 seconds or longer, and jobs are advised to be idempotent, meaning that if the code is applied or executed multiple times, the outcome should be the same as if it had been executed only once. A major use-case for `OnSchedule` is day 2 operations.
|
|
18
|
-
|
|
19
|
-
## Watch
|
|
20
|
-
|
|
21
|
-
Pepr streamlines the process of receiving timely change notifications on resources by employing the `Watch` mechanism. It is advisable to opt for `Watch` over `Mutate` or `Validate` when dealing with more extended operations, as `Watch` does not face any [timeout limitations](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#timeouts). Additionally, `Watch` proves particularly advantageous for monitoring previously existing resources within a cluster. One compelling scenario for leveraging `Watch` is when there is a need to chain API calls together, allowing `Watch` operations to be sequentially executed following `Mutate` and `Validate` actions.
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
When(a.Pod)
|
|
25
|
-
.IsCreated()
|
|
26
|
-
.InNamespace("my-app")
|
|
27
|
-
.WithName("database")
|
|
28
|
-
.Mutate(pod => // .... )
|
|
29
|
-
.Validate(pod => // .... )
|
|
30
|
-
.Watch(async (pod, phase) => {
|
|
31
|
-
Log.info(pod, `Pod was ${phase}.`);
|
|
32
|
-
|
|
33
|
-
// do consecutive api calls
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
[TOP](#pepr-best-practices)
|
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# Contributor Covenant Code of Conduct
|
|
3
|
-
|
|
4
|
-
## Our Pledge
|
|
5
|
-
|
|
6
|
-
We as members, contributors, and leaders pledge to make participation in our
|
|
7
|
-
community a harassment-free experience for everyone.
|
|
8
|
-
|
|
9
|
-
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
10
|
-
diverse, inclusive, and healthy community.
|
|
11
|
-
|
|
12
|
-
## Our Standards
|
|
13
|
-
|
|
14
|
-
Examples of behavior that contributes to a positive environment for our
|
|
15
|
-
community include:
|
|
16
|
-
|
|
17
|
-
* Demonstrating empathy and kindness toward other people
|
|
18
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
|
19
|
-
* Giving and gracefully accepting constructive feedback
|
|
20
|
-
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
21
|
-
and learning from the experience
|
|
22
|
-
* Focusing on what is best not just for us as individuals, but for the overall
|
|
23
|
-
community
|
|
24
|
-
|
|
25
|
-
Examples of unacceptable behavior include:
|
|
26
|
-
|
|
27
|
-
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
28
|
-
any kind
|
|
29
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
30
|
-
* Public or private harassment
|
|
31
|
-
* Publishing others' private information, such as a physical or email address,
|
|
32
|
-
without their explicit permission
|
|
33
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
34
|
-
professional setting
|
|
35
|
-
|
|
36
|
-
## Enforcement Responsibilities
|
|
37
|
-
|
|
38
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
|
39
|
-
acceptable behavior and will take appropriate and fair corrective action in
|
|
40
|
-
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
41
|
-
or harmful.
|
|
42
|
-
|
|
43
|
-
Community leaders have the right and responsibility to remove, edit, or reject
|
|
44
|
-
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
45
|
-
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
46
|
-
decisions when appropriate.
|
|
47
|
-
|
|
48
|
-
## Scope
|
|
49
|
-
|
|
50
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
|
51
|
-
an individual is officially representing the community in public spaces.
|
|
52
|
-
Examples of representing our community include using an official e-mail address,
|
|
53
|
-
posting via an official social media account, or acting as an appointed
|
|
54
|
-
representative at an online or offline event.
|
|
55
|
-
|
|
56
|
-
## Enforcement
|
|
57
|
-
|
|
58
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
59
|
-
reported to the community leaders responsible for enforcement at
|
|
60
|
-
`pepr-complaints` `@` `defenseunicorns.com`.
|
|
61
|
-
All complaints will be reviewed and investigated promptly and fairly.
|
|
62
|
-
|
|
63
|
-
All community leaders are obligated to respect the privacy and security of the
|
|
64
|
-
reporter of any incident.
|
|
65
|
-
|
|
66
|
-
## Attribution
|
|
67
|
-
|
|
68
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
69
|
-
version 2.1, available at
|
|
70
|
-
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
71
|
-
|
|
72
|
-
Community Impact Guidelines were inspired by
|
|
73
|
-
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
74
|
-
|
|
75
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
|
76
|
-
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
77
|
-
[https://www.contributor-covenant.org/translations][translations].
|
|
78
|
-
|
|
79
|
-
[homepage]: https://www.contributor-covenant.org
|
|
80
|
-
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
81
|
-
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
82
|
-
[FAQ]: https://www.contributor-covenant.org/faq
|
|
83
|
-
[translations]: https://www.contributor-covenant.org/translations
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
# Contributing to Pepr
|
|
4
|
-
|
|
5
|
-
Thank you for your interest in contributing to Pepr! We welcome all contributions and are grateful for your help. This guide outlines how to get started with contributing to this project.
|
|
6
|
-
|
|
7
|
-
## Table of Contents
|
|
8
|
-
|
|
9
|
-
1. [Code of Conduct](#code-of-conduct)
|
|
10
|
-
2. [Getting Started](#getting-started)
|
|
11
|
-
3. [Submitting a Pull Request](#submitting-a-pull-request)
|
|
12
|
-
4. [Coding Guidelines](#coding-guidelines)
|
|
13
|
-
5. [Running Tests](#running-tests)
|
|
14
|
-
6. [Contact](#contact)
|
|
15
|
-
|
|
16
|
-
## Code of Conduct
|
|
17
|
-
|
|
18
|
-
Please follow our [Code of Conduct](CODE_OF_CONDUCT.md) to maintain a respectful and collaborative environment.
|
|
19
|
-
|
|
20
|
-
## Getting Started
|
|
21
|
-
|
|
22
|
-
- **Repository**: [https://github.com/defenseunicorns/pepr/](https://github.com/defenseunicorns/pepr/)
|
|
23
|
-
- **npm package**: [https://www.npmjs.com/package/pepr](https://www.npmjs.com/package/pepr)
|
|
24
|
-
- **Required Node version**: `>=18.0.0`
|
|
25
|
-
|
|
26
|
-
### Setup
|
|
27
|
-
|
|
28
|
-
1. Fork the repository.
|
|
29
|
-
2. Clone your fork locally: `git clone https://github.com/your-username/pepr.git`.
|
|
30
|
-
3. Install dependencies: `npm ci`.
|
|
31
|
-
4. Create a new branch for your feature or fix: `git checkout -b my-feature-branch`.
|
|
32
|
-
|
|
33
|
-
## Submitting a Pull Request
|
|
34
|
-
|
|
35
|
-
1. **Create an Issue**: For significant changes, please create an issue first, describing the problem or feature proposal. Trivial fixes do not require an issue.
|
|
36
|
-
2. **Commit Your Changes**: Make your changes and commit them. All commits must be signed.
|
|
37
|
-
3. **Run Tests**: Ensure that your changes pass all tests by running `npm test`.
|
|
38
|
-
4. **Push Your Branch**: Push your branch to your fork on GitHub.
|
|
39
|
-
5. **Create a Pull Request**: Open a pull request against the `main` branch of the Pepr repository. Please make sure that your PR passes all CI checks.
|
|
40
|
-
|
|
41
|
-
### PR Requirements
|
|
42
|
-
|
|
43
|
-
- PRs must be against the `main` branch.
|
|
44
|
-
- PRs must pass CI checks.
|
|
45
|
-
- All commits must be signed.
|
|
46
|
-
- PRs should have a related issue, except for trivial fixes.
|
|
47
|
-
|
|
48
|
-
## Coding Guidelines
|
|
49
|
-
|
|
50
|
-
Please follow the coding conventions and style used in the project. Use ESLint and Prettier for linting and formatting:
|
|
51
|
-
|
|
52
|
-
- Check formatting: `npm run format:check`
|
|
53
|
-
- Fix formatting: `npm run format:fix`
|
|
54
|
-
|
|
55
|
-
## Running Tests
|
|
56
|
-
|
|
57
|
-
### Run Tests Locally
|
|
58
|
-
|
|
59
|
-
- Run all tests: `npm test`
|
|
60
|
-
|
|
61
|
-
### Test a Local Development Version
|
|
62
|
-
|
|
63
|
-
1. Run `npm test` and wait for completion.
|
|
64
|
-
2. Change to the test module directory: `cd pepr-test-module`.
|
|
65
|
-
3. You can now run any of the `npx pepr` commands.
|
|
66
|
-
|
|
67
|
-
## Contact
|
|
68
|
-
|
|
69
|
-
For any questions or concerns, please open an issue on GitHub or contact the maintainers.
|
|
70
|
-
|