pepr 0.14.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +110 -43
- package/dist/controller.js +1 -1
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/index.d.ts +1 -1
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/rbac.d.ts +2 -1
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts +1 -1
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +11 -0
- package/dist/lib/helpers.d.ts.map +1 -0
- package/dist/lib/included-files.d.ts +2 -0
- package/dist/lib/included-files.d.ts.map +1 -0
- package/package.json +16 -14
- package/src/lib/assets/deploy.ts +4 -3
- package/src/lib/assets/index.ts +2 -2
- package/src/lib/assets/rbac.ts +27 -11
- package/src/lib/assets/yaml.ts +2 -2
- package/src/lib/helpers.ts +39 -0
- package/src/lib/included-files.ts +19 -0
- package/src/templates/capabilities/hello-pepr.ts +16 -11
- package/src/templates/package.json +2 -1
- package/website/.linkinator.config.json +8 -0
- package/website/.markdownlint.json +6 -0
- package/website/.prettierignore +12 -0
- package/website/LICENSE +201 -0
- package/website/README.md +50 -0
- package/website/archetypes/default.md +6 -0
- package/website/assets/img/doug.svg +345 -0
- package/website/assets/img/pepr.svg +212 -0
- package/website/assets/scss/_styles_project.scss +3 -0
- package/website/assets/scss/_variables_project.scss +1 -0
- package/website/content/en/docs/_index.md +9 -0
- package/website/content/en/docs/cli.md +64 -0
- package/website/content/en/docs/codeSample.txt +31 -0
- package/website/content/en/docs/concepts.md +238 -0
- package/website/content/en/docs/customresources.md +167 -0
- package/website/content/en/docs/diagrams.txt +18 -0
- package/website/content/en/docs/metrics.md +74 -0
- package/website/content/en/docs/rbac.md +153 -0
- package/website/content/en/docs/webassembly.md +189 -0
- package/website/go.mod +8 -0
- package/website/go.sum +4 -0
- package/website/package-lock.json +3907 -0
- package/website/package.json +30 -0
- package/website/renovate.json +16 -0
- package/website/static/favicons/android-144x144.png +0 -0
- package/website/static/favicons/android-192x192.png +0 -0
- package/website/static/favicons/android-36x36.png +0 -0
- package/website/static/favicons/android-48x48.png +0 -0
- package/website/static/favicons/android-72x72.png +0 -0
- package/website/static/favicons/android-96x96.png +0 -0
- package/website/static/favicons/android-chrome-192x192.png +0 -0
- package/website/static/favicons/android-chrome-512x512.png +0 -0
- package/website/static/favicons/android-chrome-maskable-192x192.png +0 -0
- package/website/static/favicons/android-chrome-maskable-512x512.png +0 -0
- package/website/static/favicons/apple-touch-icon-180x180.png +0 -0
- package/website/static/favicons/apple-touch-icon.png +0 -0
- package/website/static/favicons/favicon-16x16.png +0 -0
- package/website/static/favicons/favicon-32x32.png +0 -0
- package/website/static/favicons/favicon.ico +0 -0
- package/website/static/img/how-to-use.png +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$secondary: #EFCA81;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Overview
|
|
3
|
+
linkTitle: Documentation
|
|
4
|
+
menu: {main: {weight: 1}}
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## What is Pepr?
|
|
8
|
+
|
|
9
|
+
Pepr functions as both a Mutating and Validating Admission Webhook, offering a fluent API that facilitates real-time resource alterations and the establishment and enforcement of policies on Kubernetes resources. Its design is not only lightweight but also includes an integrated Kubernetes client, ensuring a straightforward and effective user experience for additional interactions with Kubernetes.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: CLI
|
|
3
|
+
linkTitle: CLI
|
|
4
|
+
---
|
|
5
|
+
# Pepr CLI
|
|
6
|
+
|
|
7
|
+
## pepr init
|
|
8
|
+
|
|
9
|
+
Initialize a new Pepr Module.
|
|
10
|
+
|
|
11
|
+
**Options:**
|
|
12
|
+
|
|
13
|
+
- `-l, --log-level [level]` - Log level: debug, info, warn, error (default: "info")
|
|
14
|
+
- `--skip-post-init` - Skip npm install, git init and VSCode launch
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## pepr update
|
|
19
|
+
|
|
20
|
+
Update the current Pepr Module to the latest SDK version and update the global Pepr CLI to the same version.
|
|
21
|
+
|
|
22
|
+
**Options:**
|
|
23
|
+
|
|
24
|
+
- `-l, --log-level [level]` - Log level: debug, info, warn, error (default: "info")
|
|
25
|
+
- `--skip-template-update` - Skip updating the template files
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## pepr dev
|
|
30
|
+
|
|
31
|
+
Connect a local cluster to a local version of the Pepr Controller to do real-time debugging of your module. Note
|
|
32
|
+
the `pepr dev` assumes a K3d cluster is running by default. If you are working with Kind or another docker-based
|
|
33
|
+
K8s distro, you will need to pass the `--host host.docker.internal` option to `pepr dev`. If working with a remote
|
|
34
|
+
cluster you will have to give Pepr a host path to your machine that is reachable from the K8s cluster.
|
|
35
|
+
|
|
36
|
+
**Options:**
|
|
37
|
+
|
|
38
|
+
- `-l, --log-level [level]` - Log level: debug, info, warn, error (default: "info")
|
|
39
|
+
- `-h, --host [host]` - Host to listen on (default: "host.k3d.internal")
|
|
40
|
+
- `--confirm` - Skip confirmation prompt
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## pepr deploy
|
|
45
|
+
|
|
46
|
+
Deploy the current module into a Kubernetes cluster, useful for CI systems. Not recommended for production use.
|
|
47
|
+
|
|
48
|
+
**Options:**
|
|
49
|
+
|
|
50
|
+
- `-l, --log-level [level]` - Log level: debug, info, warn, error (default: "info")
|
|
51
|
+
- `-i, --image [image]` - Override the image tag
|
|
52
|
+
- `--confirm` - Skip confirmation prompt
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## pepr build
|
|
57
|
+
|
|
58
|
+
Create a [zarf.yaml](https://zarf.dev) and K8s manifest for the current module. This includes everything needed to deploy Pepr and the current module into production environments.
|
|
59
|
+
|
|
60
|
+
**Options:**
|
|
61
|
+
|
|
62
|
+
- `-r, --registry-info [<registry>/<username>]` - Registry Info: Image registry and username. Note: You must be signed into the registry
|
|
63
|
+
- `--rbac-mode [admin|scoped]` - Rbac Mode: admin, scoped (default: admin)
|
|
64
|
+
- `-l, --log-level [level]` - Log level: debug, info, warn, error (default: "info")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Code Sample
|
|
3
|
+
description: Samples of code
|
|
4
|
+
---
|
|
5
|
+
<!--
|
|
6
|
+
In certain instances a markdown viewer may not display due to
|
|
7
|
+
the '---' frontmatter block above. If you're one of those edge
|
|
8
|
+
cases enclose the frontmatter at the top of this file entirely
|
|
9
|
+
within a comment block just like this comment.
|
|
10
|
+
-->
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
echo "This is bash"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
console.log('This is JS')
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```go
|
|
21
|
+
func main() {
|
|
22
|
+
fmt.Println("Go with language defined")
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```gherkin
|
|
27
|
+
Scenario: Document a product
|
|
28
|
+
Given there is documentation to publish
|
|
29
|
+
When I review the documentation
|
|
30
|
+
Then it will meet the Unicorn style
|
|
31
|
+
```
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Concepts
|
|
3
|
+
linkTitle: Concepts
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Pepr Module
|
|
7
|
+
|
|
8
|
+
Each Pepr Module is it's own Typescript project, produced by [`pepr init`](./cli.md#pepr-init). Typically a module is maintained by a unique group or system. For example, a module for internal [Zarf](https://zarf.dev/) mutations would be different from a module for [Big Bang](https://p1.dso.mil/products/big-bang). An important idea with modules is that they are _wholly independent of one another_. This means that 2 different modules can be on completely different versions of Pepr and any other dependencies; their only interaction is through the standard K8s interfaces like any other webhook or controller.
|
|
9
|
+
|
|
10
|
+
## Module development lifecycle
|
|
11
|
+
|
|
12
|
+
1. **Create the module**:
|
|
13
|
+
|
|
14
|
+
Use [`pepr init`](./cli.md#pepr-init) to generate a new module.
|
|
15
|
+
|
|
16
|
+
1. **Quickly validate system setup**:
|
|
17
|
+
|
|
18
|
+
Every new module includes a sample Pepr Capability called `HelloPepr`. By default,
|
|
19
|
+
this capability is deployed and monitoring the `pepr-demo` namespace. There is a sample
|
|
20
|
+
yaml also included you can use to see Pepr in your cluster. Here's the quick steps to do
|
|
21
|
+
that after `pepr init`:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# cd to the newly-created Pepr module folder
|
|
25
|
+
cd my-module-name
|
|
26
|
+
|
|
27
|
+
# If you don't already have a local K8s cluster, you can set one up with k3d
|
|
28
|
+
npm run k3d-setup
|
|
29
|
+
|
|
30
|
+
# Launch pepr dev mode
|
|
31
|
+
# If using another local K8s distro instead of k3d, use `pepr dev --host host.docker.internal`
|
|
32
|
+
pepr dev
|
|
33
|
+
|
|
34
|
+
# From another terminal, apply the sample yaml
|
|
35
|
+
kubectl apply -f capabilities/hello-pepr.samples.yaml
|
|
36
|
+
|
|
37
|
+
# Verify the configmaps were transformed using kubectl, k9s or another tool
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
1. **Create your custom Pepr Capabilities**
|
|
41
|
+
|
|
42
|
+
Now that you have confirmed Pepr is working, you can now create new [capabilities](./capabilities.md). You'll also want to disable the `HelloPepr` capability in your module (`pepr.ts`) before pushing to production. You can disable by commenting out or deleting the `HelloPepr` variable below:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
new PeprModule(cfg, [
|
|
46
|
+
// Remove or comment the line below to disable the HelloPepr capability
|
|
47
|
+
HelloPepr,
|
|
48
|
+
|
|
49
|
+
// Your additional capabilities go here
|
|
50
|
+
]);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
_Note: if you also delete the `capabilities/hello-pepr.ts` file, it will be added again on the next [`pepr update`](./cli.md#pepr-update) so you have the latest examples usages from the Pepr SDK. Therefore, it is sufficient to remove the entry from your `pepr.ts` module
|
|
54
|
+
config._
|
|
55
|
+
|
|
56
|
+
1. **Build and deploy the Pepr Module**
|
|
57
|
+
|
|
58
|
+
Most of the time, you'll likely be iterating on a module with `pepr dev` for real-time feedback and validation Once you are ready to move beyond the local dev environment, Pepr provides deployment and build tools you can use.
|
|
59
|
+
|
|
60
|
+
`pepr deploy` - you can use this command to build your module and deploy it into any K8s cluster your current `kubecontext` has access to. This setup is ideal for CI systems during testing, but is not recommended for production use. See [`pepr deploy`](./cli.md#pepr-deploy) for more info.
|
|
61
|
+
|
|
62
|
+
## Advanced Module Configuration
|
|
63
|
+
|
|
64
|
+
By default, when you run `pepr init`, the module is not configured with any additional options. Currently, there are 3 options you can configure:
|
|
65
|
+
|
|
66
|
+
- `deferStart` - if set to `true`, the module will not start automatically. You will need to call `start()` manually. This is useful if you want to do some additional setup before the module controller starts. You can also use this to change the default port that the controller listens on.
|
|
67
|
+
|
|
68
|
+
- `beforeHook` - an optional callback that will be called before every request is processed. This is useful if you want to do some additional logging or validation before the request is processed.
|
|
69
|
+
|
|
70
|
+
- `afterHook` - an optional callback that will be called after every request is processed. This is useful if you want to do some additional logging or validation after the request is processed.
|
|
71
|
+
|
|
72
|
+
You can configure each of these by modifying the `pepr.ts` file in your module. Here's an example of how you would configure each of these options:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const module = new PeprModule(
|
|
76
|
+
cfg,
|
|
77
|
+
[
|
|
78
|
+
// Your capabilities go here
|
|
79
|
+
],
|
|
80
|
+
{
|
|
81
|
+
deferStart: true,
|
|
82
|
+
|
|
83
|
+
beforeHook: req => {
|
|
84
|
+
// Any actions you want to perform before the request is processed, including modifying the request.
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
afterHook: res => {
|
|
88
|
+
// Any actions you want to perform after the request is processed, including modifying the response.
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// Do any additional setup before starting the controller
|
|
94
|
+
module.start();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
# Capabilities
|
|
98
|
+
|
|
99
|
+
A capability is set of related [actions](./actions.md) 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.
|
|
100
|
+
|
|
101
|
+
When you [`pepr init`](./cli.md#pepr-init), a `capabilities` directory is created for you. This directory is where you will define your capabilities. You can create as many capabilities as you need, and each capability can contain one or more actions. Pepr also automatically creates a `HelloPepr` capability with a number of example actions to help you get started.
|
|
102
|
+
|
|
103
|
+
## Creating a Capability
|
|
104
|
+
|
|
105
|
+
Define a new capability can be done via a [VSCode Snippet](https://code.visualstudio.com/docs/editor/userdefinedsnippets) generated during [`pepr init`](./cli.md#pepr-init).
|
|
106
|
+
|
|
107
|
+
1. Create a new file in the `capabilities` directory with the name of your capability. For example, `capabilities/my-capability.ts`.
|
|
108
|
+
|
|
109
|
+
1. Open the new file in VSCode and type `create` in the file. A suggestion should prompt you to generate the content from there.
|
|
110
|
+
|
|
111
|
+
https://user-images.githubusercontent.com/882485/230897379-0bb57dff-9832-479f-8733-79e103703135.mp4
|
|
112
|
+
|
|
113
|
+
_If you prefer not to use VSCode, you can also modify or copy the `HelloPepr` capability to meet your needs instead._
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## Reusable Capabilities
|
|
117
|
+
|
|
118
|
+
Pepr has an NPM org managed by Defense Unicorns, `@pepr`, where capabilities are published for reuse in other Pepr Modules. You can find a list of published capabilities [here](https://www.npmjs.com/search?q=@pepr). You can also publish your own Pepr capabilities to NPM and import them. A couple of things you'll want to be aware of:
|
|
119
|
+
|
|
120
|
+
- Reuseable capability versions should use the format `0.x.x` or `0.12.x` as examples to determine compatibility with other reusable capabilities. Before `1.x.x`, we recommend binding to `0.x.x` if you can for maximum compatibility.
|
|
121
|
+
|
|
122
|
+
- `pepr.ts` will still be used for local development, but you'll need to also publish an `index.ts` that exports your capabilities. When you build & publish the capability to NPM, you can use `npx pepr build -e index.ts` to generate the code needed for reuse by other Pepr modules.
|
|
123
|
+
|
|
124
|
+
- See [Pepr Istio](https://github.com/defenseunicorns/pepr-istio) for an example of a reusable capability.
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# Actions
|
|
128
|
+
|
|
129
|
+
An action is a discrete set of behaviors defined in a single function that acts on a given Kubernetes GroupVersionKind (GVK) passed in during the admission controller lifecycle. Actions are the atomic operations that are performed on Kubernetes resources by Pepr.
|
|
130
|
+
|
|
131
|
+
For example, an action could be responsible for adding a specific label to a Kubernetes resource, or for modifying a specific field in a resource's metadata. Actions can be grouped together within a Capability to provide a more comprehensive set of operations that can be performed on Kubernetes resources.
|
|
132
|
+
|
|
133
|
+
Actions are `Mutate()`, `Validate()`, or `Watch()`. Both Mutate and Validate actions run during the admission controller lifecycle, while Watch actions run in a separate controller that tracks changes to resources, including existing resources.
|
|
134
|
+
|
|
135
|
+
Let's look at some example actions that are included in the `HelloPepr` capability that is created for you when you [`pepr init`](./cli.md#pepr-init):
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
In this first example, Pepr is adding a label and annotation to a ConfigMap with tne name `example-1` when it is created. Comments are added to each line to explain in more detail what is happening.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
// When(a.<Kind>) filters which GroupVersionKind (GVK) this action should act on.
|
|
143
|
+
When(a.ConfigMap)
|
|
144
|
+
// This limits the action to only act on new resources.
|
|
145
|
+
.IsCreated()
|
|
146
|
+
// This limits the action to only act on resources with the name "example-1".
|
|
147
|
+
.WithName("example-1")
|
|
148
|
+
// Mutate() is where we define the actual behavior of this action.
|
|
149
|
+
.Mutate(request => {
|
|
150
|
+
// The request object is a wrapper around the K8s resource that Pepr is acting on.
|
|
151
|
+
request
|
|
152
|
+
// Here we are adding a label to the ConfigMap.
|
|
153
|
+
.SetLabel("pepr", "was-here")
|
|
154
|
+
// And here we are adding an annotation.
|
|
155
|
+
.SetAnnotation("pepr.dev", "annotations-work-too");
|
|
156
|
+
|
|
157
|
+
// Note that we are not returning anything here. This is because Pepr is tracking the changes in each action automatically.
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
In this example, a Validate action rejects any ConfigMap in the `pepr-demo` namespace that has no data.
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
When(a.ConfigMap)
|
|
167
|
+
.IsCreated()
|
|
168
|
+
.InNamespace("pepr-demo")
|
|
169
|
+
// Validate() is where we define the actual behavior of this action.
|
|
170
|
+
.Validate(request => {
|
|
171
|
+
// If data exists, approve the request.
|
|
172
|
+
if (request.Raw.data) {
|
|
173
|
+
return request.Approve();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Otherwise, reject the request with a message and optional code.
|
|
177
|
+
return request.Deny("ConfigMap must have data");
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
In this example, a Watch action on the name and phase of any ConfigMap.Watch actions run in a separate controller that tracks changes to resources, including existing resources so that you can react to changes in real-time. It is important to note that Watch actions are not run during the admission controller lifecycle, so they cannot be used to modify or validate resources. They also may run multiple times for the same resource, so it is important to make sure that your Watch actions are idempotent. In a future release, Pepr will provide a better way to control when a Watch action is run to avoid this issue.
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
When(a.ConfigMap)
|
|
187
|
+
// Watch() is where we define the actual behavior of this action.
|
|
188
|
+
.Watch((cm, phase) => {
|
|
189
|
+
Log.info(cm, `ConfigMap ${cm.metadata.name} was ${phase}`);
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
There are many more examples in the `HelloPepr` capability that you can use as a reference when creating your own actions. Note that each time you run [`pepr update`](./cli.md#pepr-update), Pepr will automatically update the `HelloPepr` capability with the latest examples and best practices for you to reference and test directly in your Pepr Module.
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
# Pepr Store: A Lightweight Key-Value Store for Pepr Modules
|
|
198
|
+
|
|
199
|
+
The nature of admission controllers and general watch operations (the `Mutate`, `Validate` and `Watch` actions in Pepr) make some types of complex and long-running operations difficult. There are also times when you need to share data between different actions. While you could manually create your own K8s resources and manage their cleanup, this can be very hard to track and keep performant at scale.
|
|
200
|
+
|
|
201
|
+
The Pepr Store solves this by exposing a simple, [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Storage)-compatible mechanism for use within capabilities. Additionally, as Pepr runs multiple replicas of the admission controller along with a watch controller, the Pepr Store provides a unique way to share data between these different instances automatically.
|
|
202
|
+
|
|
203
|
+
Each Pepr Capability has a `Store` instance that can be used to get, set and delete data as well as subscribe to any changes to the Store. Behind the scenes, all capability store instances in a single Pepr Module are stored within a single CRD in the cluster. This CRD is automatically created when the Pepr Module is deployed. Care is taken to make the read and write operations as efficient as possible by using K8s watches, batch processing and patch operations for writes.
|
|
204
|
+
|
|
205
|
+
## Key Features
|
|
206
|
+
|
|
207
|
+
- **Asynchronous Key-Value Store**: Provides an asynchronous interface for storing small amounts of data, making it ideal for sharing information between various actions and capabilities.
|
|
208
|
+
- **Web Storage API Compatibility**: The store's API is aligned with the standard [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Storage), simplifying the learning curve.
|
|
209
|
+
- **Real-time Updates**: The `.subscribe()` and `onReady()` methods enable real-time updates, allowing you to react to changes in the data store instantaneously.
|
|
210
|
+
|
|
211
|
+
- **Automatic CRD Management**: Each Pepr Module has its data stored within a single Custom Resource Definition (CRD) that is automatically created upon deployment.
|
|
212
|
+
- **Efficient Operations**: Pepr Store uses Kubernetes watches, batch processing, and patch operations to make read and write operations as efficient as possible.
|
|
213
|
+
|
|
214
|
+
## Quick Start
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
// Example usage for Pepr Store
|
|
218
|
+
Store.setItem("example-1", "was-here");
|
|
219
|
+
Store.setItem("example-1-data", JSON.stringify(request.Raw.data));
|
|
220
|
+
Store.onReady(data => {
|
|
221
|
+
Log.info(data, "Pepr Store Ready");
|
|
222
|
+
});
|
|
223
|
+
const unsubscribe = Store.subscribe(data => {
|
|
224
|
+
Log.info(data, "Pepr Store Updated");
|
|
225
|
+
unsubscribe();
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## API Reference
|
|
230
|
+
|
|
231
|
+
### Methods
|
|
232
|
+
|
|
233
|
+
- `getItem(key: string)`: Retrieves a value by its key. Returns `null` if the key doesn't exist.
|
|
234
|
+
- `setItem(key: string, value: string)`: Sets a value for a given key. Creates a new key-value pair if the key doesn't exist.
|
|
235
|
+
- `removeItem(key: string)`: Deletes a key-value pair by its key.
|
|
236
|
+
- `clear()`: Clears all key-value pairs from the store.
|
|
237
|
+
- `subscribe(listener: DataReceiver)`: Subscribes to store updates.
|
|
238
|
+
- `onReady(callback: DataReceiver)`: Executes a callback when the store is ready.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Custom Resources
|
|
3
|
+
linkTitle: Custom Resources
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Importing Custom Resources
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
The [Kubernetes Fluent Client](https://github.com/defenseunicorns/kubernetes-fluent-client) supports the creation of TypeScript typings directly from Kubernetes Custom Resource Definitions (CRDs). The files it generates can be directly incorporated into Pepr capabilities and provide a way to work with strongly-typed CRDs.
|
|
11
|
+
|
|
12
|
+
For example (below), Istio CRDs can be imported and used as though they were intrinsic Kubernetes resources.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Generating TypeScript Types from CRDs
|
|
16
|
+
|
|
17
|
+
Using the kubernetes-fluent-client to produce a new type looks like this:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx kubernetes-fluent-client crd [source] [directory]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The `crd` command expects a `[source]`, which can be a URL or local file containing the `CustomResourceDefinition(s)`, and a `[directory]` where the generated code will live.
|
|
24
|
+
|
|
25
|
+
The following example creates types for the Istio CRDs:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
user@workstation$ npx kubernetes-fluent-client crd https://raw.githubusercontent.com/istio/istio/master/manifests/charts/base/crds/crd-all.gen.yaml crds
|
|
29
|
+
|
|
30
|
+
Attempting to load https://raw.githubusercontent.com/istio/istio/master/manifests/charts/base/crds/crd-all.gen.yaml as a URL
|
|
31
|
+
|
|
32
|
+
- Generating extensions.istio.io/v1alpha1 types for WasmPlugin
|
|
33
|
+
- Generating networking.istio.io/v1alpha3 types for DestinationRule
|
|
34
|
+
- Generating networking.istio.io/v1beta1 types for DestinationRule
|
|
35
|
+
- Generating networking.istio.io/v1alpha3 types for EnvoyFilter
|
|
36
|
+
- Generating networking.istio.io/v1alpha3 types for Gateway
|
|
37
|
+
- Generating networking.istio.io/v1beta1 types for Gateway
|
|
38
|
+
- Generating networking.istio.io/v1beta1 types for ProxyConfig
|
|
39
|
+
- Generating networking.istio.io/v1alpha3 types for ServiceEntry
|
|
40
|
+
- Generating networking.istio.io/v1beta1 types for ServiceEntry
|
|
41
|
+
- Generating networking.istio.io/v1alpha3 types for Sidecar
|
|
42
|
+
- Generating networking.istio.io/v1beta1 types for Sidecar
|
|
43
|
+
- Generating networking.istio.io/v1alpha3 types for VirtualService
|
|
44
|
+
- Generating networking.istio.io/v1beta1 types for VirtualService
|
|
45
|
+
- Generating networking.istio.io/v1alpha3 types for WorkloadEntry
|
|
46
|
+
- Generating networking.istio.io/v1beta1 types for WorkloadEntry
|
|
47
|
+
- Generating networking.istio.io/v1alpha3 types for WorkloadGroup
|
|
48
|
+
- Generating networking.istio.io/v1beta1 types for WorkloadGroup
|
|
49
|
+
- Generating security.istio.io/v1 types for AuthorizationPolicy
|
|
50
|
+
- Generating security.istio.io/v1beta1 types for AuthorizationPolicy
|
|
51
|
+
- Generating security.istio.io/v1beta1 types for PeerAuthentication
|
|
52
|
+
- Generating security.istio.io/v1 types for RequestAuthentication
|
|
53
|
+
- Generating security.istio.io/v1beta1 types for RequestAuthentication
|
|
54
|
+
- Generating telemetry.istio.io/v1alpha1 types for Telemetry
|
|
55
|
+
|
|
56
|
+
✅ Generated 23 files in the istio directory
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Observe that the `kubernetes-fluent-client` has produced the TypeScript types within the `crds` directory. These types can now be utilized in the Pepr module.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
user@workstation$ cat crds/proxyconfig-v1beta1.ts
|
|
63
|
+
// This file is auto-generated by kubernetes-fluent-client, do not edit manually
|
|
64
|
+
|
|
65
|
+
import { GenericKind, RegisterKind } from "kubernetes-fluent-client";
|
|
66
|
+
|
|
67
|
+
export class ProxyConfig extends GenericKind {
|
|
68
|
+
/**
|
|
69
|
+
* Provides configuration for individual workloads. See more details at:
|
|
70
|
+
* https://istio.io/docs/reference/config/networking/proxy-config.html
|
|
71
|
+
*/
|
|
72
|
+
spec?: Spec;
|
|
73
|
+
status?: { [key: string]: any };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Provides configuration for individual workloads. See more details at:
|
|
78
|
+
* https://istio.io/docs/reference/config/networking/proxy-config.html
|
|
79
|
+
*/
|
|
80
|
+
export interface Spec {
|
|
81
|
+
/**
|
|
82
|
+
* The number of worker threads to run.
|
|
83
|
+
*/
|
|
84
|
+
concurrency?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Additional environment variables for the proxy.
|
|
87
|
+
*/
|
|
88
|
+
environmentVariables?: { [key: string]: string };
|
|
89
|
+
/**
|
|
90
|
+
* Specifies the details of the proxy image.
|
|
91
|
+
*/
|
|
92
|
+
image?: Image;
|
|
93
|
+
/**
|
|
94
|
+
* Optional.
|
|
95
|
+
*/
|
|
96
|
+
selector?: Selector;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Specifies the details of the proxy image.
|
|
101
|
+
*/
|
|
102
|
+
export interface Image {
|
|
103
|
+
/**
|
|
104
|
+
* The image type of the image.
|
|
105
|
+
*/
|
|
106
|
+
imageType?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Optional.
|
|
111
|
+
*/
|
|
112
|
+
export interface Selector {
|
|
113
|
+
/**
|
|
114
|
+
* One or more labels that indicate a specific set of pods/VMs on which a policy should be
|
|
115
|
+
* applied.
|
|
116
|
+
*/
|
|
117
|
+
matchLabels?: { [key: string]: string };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
RegisterKind(ProxyConfig, {
|
|
121
|
+
group: "networking.istio.io",
|
|
122
|
+
version: "v1beta1",
|
|
123
|
+
kind: "ProxyConfig",
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Using new types
|
|
128
|
+
|
|
129
|
+
The generated types can be imported into Pepr directly, _there is no additional logic needed to make them to work_.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { Capability, K8s, Log, a, kind } from "pepr";
|
|
133
|
+
|
|
134
|
+
import { Gateway } from "../crds/gateway-v1beta1";
|
|
135
|
+
import {
|
|
136
|
+
PurpleDestination,
|
|
137
|
+
VirtualService,
|
|
138
|
+
} from "../crds/virtualservice-v1beta1";
|
|
139
|
+
|
|
140
|
+
export const IstioVirtualService = new Capability({
|
|
141
|
+
name: "istio-virtual-service",
|
|
142
|
+
description: "Generate Istio VirtualService resources",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Use the 'When' function to create a new action
|
|
146
|
+
const { When, Store } = IstioVirtualService;
|
|
147
|
+
|
|
148
|
+
// Define the configuration keys
|
|
149
|
+
enum config {
|
|
150
|
+
Gateway = "uds/istio-gateway",
|
|
151
|
+
Host = "uds/istio-host",
|
|
152
|
+
Port = "uds/istio-port",
|
|
153
|
+
Domain = "uds/istio-domain",
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Define the valid gateway names
|
|
157
|
+
const validGateway = ["admin", "tenant", "passthrough"];
|
|
158
|
+
|
|
159
|
+
// Watch Gateways to get the HTTPS domain for each gateway
|
|
160
|
+
When(Gateway)
|
|
161
|
+
.IsCreatedOrUpdated()
|
|
162
|
+
.WithLabel(config.Domain)
|
|
163
|
+
.Watch(vs => {
|
|
164
|
+
// Store the domain for the gateway
|
|
165
|
+
Store.setItem(vs.metadata.name, vs.metadata.labels[config.Domain]);
|
|
166
|
+
});
|
|
167
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Mermaid Diagram Samples
|
|
3
|
+
description: Mermaid
|
|
4
|
+
---
|
|
5
|
+
<!--
|
|
6
|
+
In certain instances a markdown viewer may not display due to
|
|
7
|
+
the '---' frontmatter block above. If you're one of those edge
|
|
8
|
+
cases enclose the frontmatter at the top of this file entirely
|
|
9
|
+
within a comment block just like this comment.
|
|
10
|
+
-->
|
|
11
|
+
|
|
12
|
+
```mermaid
|
|
13
|
+
graph TD
|
|
14
|
+
Start --> Need{"Hugo version >= 0.93.0"}
|
|
15
|
+
Need -- No --> Off["Set params.mermaid.enable = true"]
|
|
16
|
+
Off --> Author
|
|
17
|
+
Need -- Yes --> Author[Insert mermaid codeblock]
|
|
18
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Metrics
|
|
3
|
+
linkTitle: Metrics
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# `/metrics` Endpoint Documentation
|
|
7
|
+
|
|
8
|
+
The `/metrics` endpoint provides metrics for the application that are collected via the `MetricsCollector` class. It uses the `prom-client` library and performance hooks from Node.js to gather and expose the metrics data in a format that can be scraped by Prometheus.
|
|
9
|
+
|
|
10
|
+
## Metrics Exposed
|
|
11
|
+
|
|
12
|
+
The `MetricsCollector` exposes the following metrics:
|
|
13
|
+
|
|
14
|
+
- `pepr_errors`: A counter that increments when an error event occurs in the application.
|
|
15
|
+
- `pepr_alerts`: A counter that increments when an alert event is triggered in the application.
|
|
16
|
+
- `pepr_Mutate`: A summary that provides the observed durations of mutation events in the application.
|
|
17
|
+
- `pepr_Validate`: A summary that provides the observed durations of validation events in the application.
|
|
18
|
+
|
|
19
|
+
## API Details
|
|
20
|
+
|
|
21
|
+
**Method:** GET
|
|
22
|
+
|
|
23
|
+
**URL:** `/metrics`
|
|
24
|
+
|
|
25
|
+
**Response Type:** text/plain
|
|
26
|
+
|
|
27
|
+
**Status Codes:**
|
|
28
|
+
- 200 OK: On success, returns the current metrics from the application.
|
|
29
|
+
|
|
30
|
+
**Response Body:**
|
|
31
|
+
The response body is a plain text representation of the metrics data, according to the Prometheus exposition formats. It includes the metrics mentioned above.
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
### Request
|
|
36
|
+
|
|
37
|
+
```plaintext
|
|
38
|
+
GET /metrics
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Response
|
|
42
|
+
```plaintext
|
|
43
|
+
`# HELP pepr_errors Mutation/Validate errors encountered
|
|
44
|
+
# TYPE pepr_errors counter
|
|
45
|
+
pepr_errors 5
|
|
46
|
+
|
|
47
|
+
# HELP pepr_alerts Mutation/Validate bad api token received
|
|
48
|
+
# TYPE pepr_alerts counter
|
|
49
|
+
pepr_alerts 10
|
|
50
|
+
|
|
51
|
+
# HELP pepr_Mutate Mutation operation summary
|
|
52
|
+
# TYPE pepr_Mutate summary
|
|
53
|
+
pepr_Mutate{quantile="0.01"} 100.60707900021225
|
|
54
|
+
pepr_Mutate{quantile="0.05"} 100.60707900021225
|
|
55
|
+
pepr_Mutate{quantile="0.5"} 100.60707900021225
|
|
56
|
+
pepr_Mutate{quantile="0.9"} 100.60707900021225
|
|
57
|
+
pepr_Mutate{quantile="0.95"} 100.60707900021225
|
|
58
|
+
pepr_Mutate{quantile="0.99"} 100.60707900021225
|
|
59
|
+
pepr_Mutate{quantile="0.999"} 100.60707900021225
|
|
60
|
+
pepr_Mutate_sum 100.60707900021225
|
|
61
|
+
pepr_Mutate_count 1
|
|
62
|
+
|
|
63
|
+
# HELP pepr_Validate Validation operation summary
|
|
64
|
+
# TYPE pepr_Validate summary
|
|
65
|
+
pepr_Validate{quantile="0.01"} 201.19413900002837
|
|
66
|
+
pepr_Validate{quantile="0.05"} 201.19413900002837
|
|
67
|
+
pepr_Validate{quantile="0.5"} 201.2137690000236
|
|
68
|
+
pepr_Validate{quantile="0.9"} 201.23339900001884
|
|
69
|
+
pepr_Validate{quantile="0.95"} 201.23339900001884
|
|
70
|
+
pepr_Validate{quantile="0.99"} 201.23339900001884
|
|
71
|
+
pepr_Validate{quantile="0.999"} 201.23339900001884
|
|
72
|
+
pepr_Validate_sum 402.4275380000472
|
|
73
|
+
pepr_Validate_count 2
|
|
74
|
+
```
|