pepr 0.21.0 → 0.22.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.
Files changed (60) hide show
  1. package/README.md +13 -3
  2. package/codecov.yaml +19 -0
  3. package/dist/cli.js +118 -46
  4. package/dist/controller.js +1 -1
  5. package/dist/lib/assets/deploy.d.ts +1 -1
  6. package/dist/lib/assets/deploy.d.ts.map +1 -1
  7. package/dist/lib/assets/index.d.ts +1 -1
  8. package/dist/lib/assets/index.d.ts.map +1 -1
  9. package/dist/lib/assets/pods.d.ts +18 -0
  10. package/dist/lib/assets/pods.d.ts.map +1 -1
  11. package/dist/lib/helpers.d.ts +2 -0
  12. package/dist/lib/helpers.d.ts.map +1 -1
  13. package/package.json +10 -8
  14. package/src/lib/assets/deploy.ts +22 -22
  15. package/src/lib/assets/index.ts +2 -2
  16. package/src/lib/assets/pods.ts +36 -0
  17. package/src/lib/helpers.ts +42 -0
  18. package/website/.linkinator.config.json +0 -8
  19. package/website/.markdownlint.json +0 -6
  20. package/website/.prettierignore +0 -12
  21. package/website/LICENSE +0 -201
  22. package/website/README.md +0 -50
  23. package/website/archetypes/default.md +0 -6
  24. package/website/assets/img/Pepr.Horizontal.white.svg +0 -144
  25. package/website/assets/img/doug.svg +0 -345
  26. package/website/assets/img/pepr.svg +0 -212
  27. package/website/assets/scss/_styles_project.scss +0 -7
  28. package/website/assets/scss/_variables_project.scss +0 -1
  29. package/website/content/en/docs/OnSchedule.md +0 -86
  30. package/website/content/en/docs/_index.md +0 -9
  31. package/website/content/en/docs/cli.md +0 -83
  32. package/website/content/en/docs/codeSample.txt +0 -31
  33. package/website/content/en/docs/concepts.md +0 -238
  34. package/website/content/en/docs/customresources.md +0 -167
  35. package/website/content/en/docs/diagrams.txt +0 -18
  36. package/website/content/en/docs/metrics.md +0 -113
  37. package/website/content/en/docs/rbac.md +0 -153
  38. package/website/content/en/docs/store.md +0 -48
  39. package/website/content/en/docs/webassembly.md +0 -189
  40. package/website/go.mod +0 -8
  41. package/website/go.sum +0 -4
  42. package/website/package-lock.json +0 -3907
  43. package/website/package.json +0 -30
  44. package/website/renovate.json +0 -16
  45. package/website/static/favicons/android-144x144.png +0 -0
  46. package/website/static/favicons/android-192x192.png +0 -0
  47. package/website/static/favicons/android-36x36.png +0 -0
  48. package/website/static/favicons/android-48x48.png +0 -0
  49. package/website/static/favicons/android-72x72.png +0 -0
  50. package/website/static/favicons/android-96x96.png +0 -0
  51. package/website/static/favicons/android-chrome-192x192.png +0 -0
  52. package/website/static/favicons/android-chrome-512x512.png +0 -0
  53. package/website/static/favicons/android-chrome-maskable-192x192.png +0 -0
  54. package/website/static/favicons/android-chrome-maskable-512x512.png +0 -0
  55. package/website/static/favicons/apple-touch-icon-180x180.png +0 -0
  56. package/website/static/favicons/apple-touch-icon.png +0 -0
  57. package/website/static/favicons/favicon-16x16.png +0 -0
  58. package/website/static/favicons/favicon-32x32.png +0 -0
  59. package/website/static/favicons/favicon.ico +0 -0
  60. package/website/static/img/how-to-use.png +0 -0
@@ -1,7 +0,0 @@
1
- code {
2
- --bs-code-color: #{$secondary};
3
- }
4
-
5
- .td-navbar .navbar-brand svg {
6
- width: fit-content;
7
- }
@@ -1 +0,0 @@
1
- $secondary: #EFCA81;
@@ -1,86 +0,0 @@
1
- ---
2
- title: OnSchedule
3
- linkTitle: OnSchedule
4
- ---
5
-
6
- # OnSchedule
7
-
8
- The `OnSchedule` feature allows you to schedule and automate the execution of specific code at predefined intervals or schedules. This feature is designed to simplify recurring tasks and can serve as an alternative to traditional CronJobs. This code is designed to be run at the top level on a Capability, not within a function like `When`.
9
-
10
- > **Note -** To use this feature in dev mode you MUST set `PEPR_WATCH_MODE="true"`. This is because the scheduler only runs on the watch controller and the watch controller is not started by default in dev mode.
11
-
12
- For example: `PEPR_WATCH_MODE="true" npx pepr dev`
13
-
14
- ## Best Practices
15
-
16
- `OnSchedule` is designed for targeting intervals equal to or larger than 30 seconds due to the storage mechanism used to archive schedule info.
17
-
18
- ## Usage
19
-
20
- Create a recurring task execution by calling the OnSchedule function with the following parameters:
21
-
22
- **name** - The unique name of the schedule.
23
-
24
- **every** - An integer that represents the frequency of the schedule in number of _units_.
25
-
26
- **unit** - A string specifying the time unit for the schedule (e.g., `seconds`, `minute`, `minutes`, `hour`, `hours`).
27
-
28
- **startTime** - (Optional) A UTC timestamp indicating when the schedule should start. All date times must be provided in GMT. If not specified the schedule will start when the schedule store reports ready.
29
-
30
- **run** - A function that contains the code you want to execute on the defined schedule.
31
-
32
- **completions** - (Optional) An integer indicating the maximum number of times the schedule should run to completion. If not specified the schedule will run indefinitely.
33
-
34
-
35
- ## Examples
36
-
37
- Update the curr ConfigMap every 15 seconds and use the store to track the current count:
38
-
39
- ```typescript
40
- OnSchedule({
41
- name: "hello-interval",
42
- every: 30,
43
- unit: "seconds",
44
- run: async () => {
45
- Log.info("Wait 30 seconds and create/update a ConfigMap");
46
-
47
- try {
48
- await K8s(kind.ConfigMap).Apply({
49
- metadata: {
50
- name: "last-updated",
51
- namespace: "default",
52
- },
53
- data: {
54
- count: `${new Date()}`,
55
- },
56
- });
57
-
58
- } catch (error) {
59
- Log.error(error, "Failed to apply ConfigMap using server-side apply.");
60
- }
61
- },
62
- });
63
- ```
64
-
65
- Refresh an AWSToken every 24 hours, with a delayed start of 30 seconds, running a total of 3 times:
66
-
67
- ```typescript
68
-
69
- OnSchedule({
70
- name: "refresh-aws-token",
71
- every: 24,
72
- unit: "hours",
73
- startTime: new Date(new Date().getTime() + 1000 * 30),
74
- run: async () => {
75
- await RefreshAWSToken();
76
- },
77
- completions: 3,
78
- });
79
- ```
80
-
81
- ## Advantages
82
-
83
- - Simplifies scheduling recurring tasks without the need for complex CronJob configurations.
84
- - Provides flexibility to define schedules in a human-readable format.
85
- - Allows you to execute code with precision at specified intervals.
86
- - Supports limiting the number of schedule completions for finite tasks.
@@ -1,9 +0,0 @@
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.
@@ -1,83 +0,0 @@
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 monitor
57
-
58
- Monitor Validations for a given Pepr Module.
59
-
60
- Usage:
61
- ```bash
62
- npx pepr monitor [options] <module-uuid>
63
- ```
64
-
65
- **Options:**
66
- - `-l, --log-level [level]` - Log level: debug, info, warn, error (default: "info")
67
- - `-h, --help` - Display help for command
68
-
69
- ---
70
-
71
- ## pepr build
72
-
73
- 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.
74
-
75
-
76
- **Options:**
77
-
78
- - `-l, --log-level [level]` - Log level: debug, info, warn, error (default: "info")
79
- - `-e, --entry-point [file]` - Specify the entry point file to build with. (default: "pepr.ts")
80
- - `-n, --no-embed` - Disables embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM
81
- - `-r, --registry-info [<registry>/<username>]` - Registry Info: Image registry and username. Note: You must be signed into the registry
82
- - `-o, --output-dir [output directory]` - Define where to place build output
83
- - `--rbac-mode [admin|scoped]` - Rbac Mode: admin, scoped (default: admin) (choices: "admin", "scoped", default: "admin")
@@ -1,31 +0,0 @@
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
- ```
@@ -1,238 +0,0 @@
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.
@@ -1,167 +0,0 @@
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
- ```
@@ -1,18 +0,0 @@
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
- ```