pepr 0.12.2 → 0.13.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 (88) hide show
  1. package/CODE_OF_CONDUCT.md +83 -0
  2. package/CONTRIBUTING.md +70 -0
  3. package/README.md +28 -30
  4. package/dist/cli.js +644 -679
  5. package/dist/controller.js +13 -81
  6. package/dist/lib/assets/deploy.d.ts +3 -0
  7. package/dist/lib/assets/deploy.d.ts.map +1 -0
  8. package/dist/lib/assets/index.d.ts +18 -0
  9. package/dist/lib/assets/index.d.ts.map +1 -0
  10. package/dist/lib/assets/loader.d.ts +14 -0
  11. package/dist/lib/assets/loader.d.ts.map +1 -0
  12. package/dist/lib/assets/networking.d.ts +6 -0
  13. package/dist/lib/assets/networking.d.ts.map +1 -0
  14. package/dist/lib/assets/pods.d.ts +8 -0
  15. package/dist/lib/assets/pods.d.ts.map +1 -0
  16. package/dist/lib/assets/rbac.d.ts +11 -0
  17. package/dist/lib/assets/rbac.d.ts.map +1 -0
  18. package/dist/lib/assets/webhooks.d.ts +6 -0
  19. package/dist/lib/assets/webhooks.d.ts.map +1 -0
  20. package/dist/lib/assets/yaml.d.ts +4 -0
  21. package/dist/lib/assets/yaml.d.ts.map +1 -0
  22. package/dist/lib/capability.d.ts +1 -3
  23. package/dist/lib/capability.d.ts.map +1 -1
  24. package/dist/lib/controller.d.ts +45 -10
  25. package/dist/lib/controller.d.ts.map +1 -1
  26. package/dist/lib/filter.d.ts +1 -1
  27. package/dist/lib/filter.d.ts.map +1 -1
  28. package/dist/lib/k8s/index.d.ts +2 -1
  29. package/dist/lib/k8s/index.d.ts.map +1 -1
  30. package/dist/lib/k8s/kinds.d.ts.map +1 -1
  31. package/dist/lib/k8s/types.d.ts +13 -13
  32. package/dist/lib/k8s/types.d.ts.map +1 -1
  33. package/dist/lib/k8s/upstream.d.ts +2 -2
  34. package/dist/lib/k8s/upstream.d.ts.map +1 -1
  35. package/dist/lib/logger.d.ts +8 -54
  36. package/dist/lib/logger.d.ts.map +1 -1
  37. package/dist/lib/metrics.d.ts +11 -4
  38. package/dist/lib/metrics.d.ts.map +1 -1
  39. package/dist/lib/module.d.ts +2 -2
  40. package/dist/lib/module.d.ts.map +1 -1
  41. package/dist/lib/mutate-processor.d.ts +5 -0
  42. package/dist/lib/mutate-processor.d.ts.map +1 -0
  43. package/dist/lib/{request.d.ts → mutate-request.d.ts} +5 -5
  44. package/dist/lib/mutate-request.d.ts.map +1 -0
  45. package/dist/lib/types.d.ts +45 -46
  46. package/dist/lib/types.d.ts.map +1 -1
  47. package/dist/lib/validate-processor.d.ts +4 -0
  48. package/dist/lib/validate-processor.d.ts.map +1 -0
  49. package/dist/lib/validate-request.d.ts +54 -0
  50. package/dist/lib/validate-request.d.ts.map +1 -0
  51. package/dist/lib.d.ts +3 -2
  52. package/dist/lib.d.ts.map +1 -1
  53. package/dist/lib.js +502 -302
  54. package/dist/lib.js.map +4 -4
  55. package/package.json +15 -12
  56. package/src/cli.ts +2 -11
  57. package/src/lib/assets/deploy.ts +179 -0
  58. package/src/lib/assets/index.ts +46 -0
  59. package/src/lib/assets/loader.ts +49 -0
  60. package/src/lib/assets/networking.ts +58 -0
  61. package/src/lib/assets/pods.ts +148 -0
  62. package/src/lib/assets/rbac.ts +57 -0
  63. package/src/lib/assets/webhooks.ts +139 -0
  64. package/src/lib/assets/yaml.ts +75 -0
  65. package/src/lib/capability.ts +54 -44
  66. package/src/lib/controller.ts +171 -89
  67. package/src/lib/fetch.ts +1 -1
  68. package/src/lib/filter.ts +1 -3
  69. package/src/lib/k8s/index.ts +4 -1
  70. package/src/lib/k8s/kinds.ts +40 -0
  71. package/src/lib/k8s/types.ts +16 -14
  72. package/src/lib/k8s/upstream.ts +5 -1
  73. package/src/lib/logger.ts +14 -125
  74. package/src/lib/metrics.ts +67 -23
  75. package/src/lib/module.ts +13 -11
  76. package/src/lib/{processor.ts → mutate-processor.ts} +37 -28
  77. package/src/lib/{request.ts → mutate-request.ts} +4 -4
  78. package/src/lib/types.ts +51 -51
  79. package/src/lib/validate-processor.ts +68 -0
  80. package/src/lib/validate-request.ts +94 -0
  81. package/src/lib.ts +4 -2
  82. package/src/runtime/controller.ts +1 -1
  83. package/dist/lib/k8s/webhook.d.ts +0 -37
  84. package/dist/lib/k8s/webhook.d.ts.map +0 -1
  85. package/dist/lib/processor.d.ts +0 -5
  86. package/dist/lib/processor.d.ts.map +0 -1
  87. package/dist/lib/request.d.ts.map +0 -1
  88. package/src/lib/k8s/webhook.ts +0 -643
@@ -0,0 +1,83 @@
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
@@ -0,0 +1,70 @@
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
+
package/README.md CHANGED
@@ -6,8 +6,7 @@
6
6
  [![Npm package version](https://badgen.net/npm/v/pepr)](https://npmjs.com/package/pepr)
7
7
  [![Npm package total downloads](https://badgen.net/npm/dt/pepr)](https://npmjs.com/package/pepr)
8
8
 
9
-
10
- #### __*Type safe Kubernetes middleware for humans*__
9
+ #### **_Type safe Kubernetes middleware for humans_**
11
10
 
12
11
  <img align="right" width="40%" src=".images/pepr.png" />
13
12
 
@@ -15,7 +14,7 @@ Pepr is on a mission to save Kubernetes from the tyranny of YAML, intimidating g
15
14
 
16
15
  ## Features
17
16
 
18
- - Zero-config K8s webhook mutations and [validations soon](https://github.com/defenseunicorns/pepr/issues/73).
17
+ - Zero-config K8s webhook mutations and validations.
19
18
  - Human-readable fluent API for generating [Pepr Capabilities](#capability)
20
19
  - Generate new K8s resources based off of cluster resource changes
21
20
  - Perform other exec/API calls based off of cluster resources changes or any other arbitrary schedule
@@ -26,26 +25,35 @@ Pepr is on a mission to save Kubernetes from the tyranny of YAML, intimidating g
26
25
  - Automatic least-privilege RBAC generation [soon](https://github.com/defenseunicorns/pepr/issues/31)
27
26
  - AMD64 and ARM64 support
28
27
 
29
- ## Example Pepr CapabilityAction
28
+ ## Example Pepr Action
30
29
 
31
- 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. Finally, it logs a message to the Pepr controller logs. For more see [CapabilityActions](./docs/actions.md).
30
+ 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. Finally, it logs a message to the Pepr controller logs. For more see [actions](./docs/actions.md).
32
31
 
33
32
  ```ts
34
33
  When(a.ConfigMap)
35
34
  .IsCreatedOrUpdated()
36
35
  .InNamespace("pepr-demo")
37
36
  .WithLabel("unicorn", "rainbow")
38
- .Then(request => {
37
+ // Create a Mutate Action for the ConfigMap
38
+ .Mutate(request => {
39
39
  // Add a label and annotation to the ConfigMap
40
- request
41
- .SetLabel("pepr", "was-here")
42
- .SetAnnotation("pepr.dev", "annotations-work-too");
40
+ request.SetLabel("pepr", "was-here").SetAnnotation("pepr.dev", "annotations-work-too");
43
41
 
44
42
  // Add some data to the ConfigMap
45
43
  request.Raw.data["doug-says"] = "Pepr is awesome!";
46
44
 
47
45
  // Log a message to the Pepr controller logs
48
46
  Log.info("A 🦄 ConfigMap was created or updated:");
47
+ })
48
+ // Create a Validate Action for the ConfigMap
49
+ .Validate(request => {
50
+ // Validate the ConfigMap has a specific label
51
+ if (request.HasLabel("pepr")) {
52
+ return request.Approve();
53
+ }
54
+
55
+ // Reject the ConfigMap if it doesn't have the label
56
+ return request.Deny("ConfigMap must have a unicorn label");
49
57
  });
50
58
  ```
51
59
 
@@ -60,7 +68,7 @@ When(a.ConfigMap)
60
68
  ## Wow too many words! tl;dr;
61
69
 
62
70
  ```bash
63
- # Initialize a new Pepr Module, you can also use `npx pepr@latest init` to make sure you have the latest version
71
+ # Create a new Pepr Module
64
72
  npx pepr init
65
73
 
66
74
  # If you already have a Kind or K3d cluster you want to use, skip this step
@@ -74,48 +82,38 @@ kubectl apply -f capabilities/hello-pepr.samples.yaml
74
82
  # Be amazed and ⭐️ this repo
75
83
  ```
76
84
 
77
- Pepr is an open-source project that helps IT Ops teams of all skill levels manage and modify resources in a Kubernetes (K8s) cluster using TypeScript. Kubernetes simplifies the management of multiple computers working together to run and scale applications. Pepr acts as a smart assistant, automatically changing or validating parts of the system as needed.
78
-
79
- TypeScript is used to create Pepr capabilities, benefiting from its error-catching and clean code features, but without requiring specialized software engineering experience or prior Typescript knowledge. Pepr also provides a user-friendly interface for writing commands in plain English in a [Fluent Interface](https://en.wikipedia.org/wiki/Fluent_interface) style.
80
-
81
- Capabilities are logical groupings of actions, which are the atomic units of change within Pepr. Actions _modify_, _create_, or _interact_ with resources in response to events. Pepr's capabilities and actions work together in the cluster, offering a versatile and customizable tool that enhances Kubernetes by building glue code or plumbing for system interactions. This makes Pepr useful for various tasks such as creating robust policy engines or seamlessly connecting applications.
82
-
83
- Imagine Pepr as a smart home system where different devices communicate with each other. Pepr provides instructions, simplifying the management of the smart home. The project enables both expert and novice capability authors to improve management and interactions within the Kubernetes environment, making its features accessible to everyone.
84
-
85
85
  https://user-images.githubusercontent.com/882485/230895880-c5623077-f811-4870-bb9f-9bb8e5edc118.mp4
86
86
 
87
87
  ## Concepts
88
88
 
89
89
  ### Module
90
90
 
91
- 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 CapabilityActions. 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.
91
+ 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.
92
92
 
93
93
  See [Module](./docs/module.md) for more details.
94
94
 
95
95
  ### Capability
96
96
 
97
- A capability is set of related CapabilityActions that work together to achieve a specific transformation or operation on Kubernetes resources. Capabilities are user-defined and can include one or more CapabilityActions. 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.
97
+ 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.
98
98
 
99
99
  See [Capabilities](./docs/capabilities.md) for more details.
100
100
 
101
- ### CapabilityAction
101
+ ### Action
102
+
103
+ Action is a discrete set of behaviors defined in a single function that acts on a given Kubernetes GroupVersionKind (GVK) passed in from Kubernetes. Actions are the atomic operations that are performed on Kubernetes resources by Pepr.
102
104
 
103
- CapabilityAction is a discrete set of behaviors defined in a single function that acts on a given Kubernetes GroupVersionKind (GVK) passed in from Kubernetes. CapabilityActions are the atomic operations that are performed on Kubernetes resources by Pepr.
105
+ 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.
104
106
 
105
- For example, a CapabilityAction could be responsible for adding a specific label to a Kubernetes resource, or for modifying a specific field in a resource's metadata. CapabilityActions can be grouped together within a Capability to provide a more comprehensive set of operations that can be performed on Kubernetes resources.
107
+ There are both `Mutate()` and `Validate()` Actions that can be used to modify or validate Kubernetes resources.
106
108
 
107
- See [CapabilityActions](./docs/actions.md) for more details.
109
+ See [actions](./docs/actions.md) for more details.
108
110
 
109
111
  ## Logical Pepr Flow
110
112
 
111
- ![Module Diagram](./.images/modules.svg)
113
+ ![Arch Diagram](./.images/pepr-arch.svg)
114
+ [Source Diagram](./.images/pepr-arch.svg)
112
115
 
113
116
  ## TypeScript
114
117
 
115
118
  [TypeScript](https://www.typescriptlang.org/) is a strongly typed, object-oriented programming language built on top of JavaScript. It provides optional static typing and a rich type system, allowing developers to write more robust code. TypeScript is transpiled to JavaScript, enabling it to run in any environment that supports JavaScript. Pepr allows you to use JavaScript or TypeScript to write capabilities, but TypeScript is recommended for its type safety and rich type system. You can learn more about TypeScript [here](https://www.typescriptlang.org/docs/handbook/typescript-from-scratch.html).
116
119
 
117
- ## Kubernetes Mutating Webhooks
118
-
119
- [Kubernetes mutating webhooks](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/) are a powerful feature that allows users to intercept and modify Kubernetes API requests, such as resource creation or updates, before they are persisted to the cluster. They can be used to enforce security policies, default values, or perform custom transformations on resources.
120
-
121
- Pepr uses Kubernetes mutating webhooks to react to cluster resource events and apply user-defined capabilities, which are sets of Kubernetes transformations/actions.