pepr 0.0.0-development

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 (58) hide show
  1. package/.prettierignore +1 -0
  2. package/CODE_OF_CONDUCT.md +133 -0
  3. package/LICENSE +201 -0
  4. package/README.md +151 -0
  5. package/SECURITY.md +18 -0
  6. package/SUPPORT.md +16 -0
  7. package/codecov.yaml +19 -0
  8. package/commitlint.config.js +1 -0
  9. package/package.json +70 -0
  10. package/src/cli.ts +48 -0
  11. package/src/lib/assets/deploy.ts +122 -0
  12. package/src/lib/assets/destroy.ts +33 -0
  13. package/src/lib/assets/helm.ts +219 -0
  14. package/src/lib/assets/index.ts +175 -0
  15. package/src/lib/assets/loader.ts +41 -0
  16. package/src/lib/assets/networking.ts +89 -0
  17. package/src/lib/assets/pods.ts +353 -0
  18. package/src/lib/assets/rbac.ts +111 -0
  19. package/src/lib/assets/store.ts +49 -0
  20. package/src/lib/assets/webhooks.ts +147 -0
  21. package/src/lib/assets/yaml.ts +234 -0
  22. package/src/lib/capability.ts +314 -0
  23. package/src/lib/controller/index.ts +326 -0
  24. package/src/lib/controller/store.ts +219 -0
  25. package/src/lib/errors.ts +20 -0
  26. package/src/lib/filter.ts +110 -0
  27. package/src/lib/helpers.ts +342 -0
  28. package/src/lib/included-files.ts +19 -0
  29. package/src/lib/k8s.ts +169 -0
  30. package/src/lib/logger.ts +27 -0
  31. package/src/lib/metrics.ts +120 -0
  32. package/src/lib/module.ts +136 -0
  33. package/src/lib/mutate-processor.ts +160 -0
  34. package/src/lib/mutate-request.ts +153 -0
  35. package/src/lib/queue.ts +89 -0
  36. package/src/lib/schedule.ts +175 -0
  37. package/src/lib/storage.ts +192 -0
  38. package/src/lib/tls.ts +90 -0
  39. package/src/lib/types.ts +215 -0
  40. package/src/lib/utils.ts +57 -0
  41. package/src/lib/validate-processor.ts +80 -0
  42. package/src/lib/validate-request.ts +102 -0
  43. package/src/lib/watch-processor.ts +124 -0
  44. package/src/lib.ts +27 -0
  45. package/src/runtime/controller.ts +75 -0
  46. package/src/sdk/sdk.ts +116 -0
  47. package/src/templates/.eslintrc.template.json +18 -0
  48. package/src/templates/.prettierrc.json +13 -0
  49. package/src/templates/README.md +21 -0
  50. package/src/templates/capabilities/hello-pepr.samples.json +160 -0
  51. package/src/templates/capabilities/hello-pepr.ts +426 -0
  52. package/src/templates/gitignore +4 -0
  53. package/src/templates/package.json +20 -0
  54. package/src/templates/pepr.code-snippets.json +21 -0
  55. package/src/templates/pepr.ts +17 -0
  56. package/src/templates/settings.json +10 -0
  57. package/src/templates/tsconfig.json +9 -0
  58. package/src/templates/tsconfig.module.json +19 -0
@@ -0,0 +1 @@
1
+ src/cli/init/templates/data.json
@@ -0,0 +1,133 @@
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, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, caste, color, religion, or sexual
11
+ identity and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the overall
27
+ community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or advances of
32
+ any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email address,
36
+ without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official email address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
+ pepr-dev-private@googlegroups.com.
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series of
87
+ actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or permanent
94
+ ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within the
114
+ community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.1, available at
120
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121
+
122
+ Community Impact Guidelines were inspired by
123
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124
+
125
+ For answers to common questions about this code of conduct, see the FAQ at
126
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127
+ [https://www.contributor-covenant.org/translations][translations].
128
+
129
+ [homepage]: https://www.contributor-covenant.org
130
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131
+ [Mozilla CoC]: https://github.com/mozilla/diversity
132
+ [FAQ]: https://www.contributor-covenant.org/faq
133
+ [translations]: https://www.contributor-covenant.org/translations
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # Pepr
2
+
3
+ [![Pepr Documentation](https://img.shields.io/badge/docs--d25ba1)](https://docs.pepr.dev)
4
+ [![Npm package license](https://badgen.net/npm/license/pepr)](https://npmjs.com/package/pepr)
5
+ [![Known Vulnerabilities](https://snyk.io/test/npm/pepr/badge.svg)](https://snyk.io/advisor/npm-package/pepr)
6
+ [![Npm package version](https://badgen.net/npm/v/pepr)](https://npmjs.com/package/pepr)
7
+ [![Npm package total downloads](https://badgen.net/npm/dt/pepr)](https://npmjs.com/package/pepr)
8
+ [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/defenseunicorns/pepr/badge)](https://securityscorecards.dev/viewer/?uri=github.com/defenseunicorns/pepr)
9
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
10
+
11
+ #### **_Type safe Kubernetes middleware for humans_**
12
+
13
+ <img align="right" width="40%" src="_images/pepr.png" />
14
+
15
+ 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 organizational knowledge into code, simplifying documentation, testing, validation, and coordination of changes for a more predictable outcome.
16
+
17
+ ## Features
18
+
19
+ - Zero-config K8s webhook mutations and validations
20
+ - Automatic leader-elected K8s resource watching
21
+ - Lightweight async key-value store backed by K8s for stateful operations with the [Pepr Store](./docs/030_user-guide/050_store.md)
22
+ - Human-readable fluent API for generating [Pepr Capabilities](#capability)
23
+ - 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
+ - Generate new K8s resources based off of cluster resource changes
25
+ - Perform other exec/API calls based off of cluster resources changes or any other arbitrary schedule
26
+ - Out of the box airgap support with [Zarf](https://zarf.dev)
27
+ - Entire NPM ecosystem available for advanced operations
28
+ - Realtime K8s debugging system for testing/reacting to cluster changes
29
+ - Controller network isolation and tamper-resistant module execution
30
+ - Least-privilege [RBAC](./docs/030_user-guide/090_rbac.md) generation
31
+ - AMD64 and ARM64 support
32
+
33
+ ## Example Pepr Action
34
+
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/030_user-guide/030_actions.md) section.
36
+
37
+ ```ts
38
+ When(a.ConfigMap)
39
+ .IsCreatedOrUpdated()
40
+ .InNamespace("pepr-demo")
41
+ .WithLabel("unicorn", "rainbow")
42
+ // Create a Mutate Action for the ConfigMap
43
+ .Mutate(request => {
44
+ // Add a label and annotation to the ConfigMap
45
+ request.SetLabel("pepr", "was-here").SetAnnotation("pepr.dev", "annotations-work-too");
46
+
47
+ // Add some data to the ConfigMap
48
+ request.Raw.data["doug-says"] = "Pepr is awesome!";
49
+
50
+ // Log a message to the Pepr controller logs
51
+ Log.info("A 🦄 ConfigMap was created or updated:");
52
+ })
53
+ // Create a Validate Action for the ConfigMap
54
+ .Validate(request => {
55
+ // Validate the ConfigMap has a specific label
56
+ if (request.HasLabel("pepr")) {
57
+ return request.Approve();
58
+ }
59
+
60
+ // Reject the ConfigMap if it doesn't have the label
61
+ return request.Deny("ConfigMap must have a unicorn label");
62
+ })
63
+ // Watch behaves like controller-runtime's Manager.Watch()
64
+ .Watch(async (cm, phase) => {
65
+ Log.info(cm, `ConfigMap was ${phase}.`);
66
+
67
+ // Apply a ConfigMap using K8s server-side apply (will create or update)
68
+ await K8s(kind.ConfigMap).Apply({
69
+ metadata: {
70
+ name: "pepr-ssa-demo",
71
+ namespace: "pepr-demo-2",
72
+ },
73
+ data: {
74
+ uid: cm.metadata.uid,
75
+ },
76
+ });
77
+ });
78
+ ```
79
+
80
+ ## Prerequisites
81
+
82
+ - [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.
84
+
85
+ - [npm](https://www.npmjs.com/) v10.1.0+
86
+
87
+ - Recommended (optional) tools:
88
+ - [Visual Studio Code](https://code.visualstudio.com/) for inline debugging and [Pepr Capabilities](#capability) creation.
89
+ - A Kubernetes cluster for `npx pepr dev`. Pepr modules include `npm run k3d-setup` if you want to test locally with [K3d](https://k3d.io/) and [Docker](https://www.docker.com/).
90
+
91
+ ## Wow, too many words! tl;dr;
92
+
93
+ ```bash
94
+ # Create a new Pepr Module
95
+ npx pepr init
96
+
97
+ # If you already have a Kind or K3d cluster you want to use, skip this step
98
+ npm run k3d-setup
99
+
100
+ # Start playing with Pepr now
101
+ # If using another local K8s distro instead of k3d, run `npx pepr dev --host host.docker.internal`
102
+ npx pepr dev
103
+ kubectl apply -f capabilities/hello-pepr.samples.yaml
104
+
105
+ # Be amazed and ⭐️ this repo
106
+ ```
107
+
108
+ https://user-images.githubusercontent.com/882485/230895880-c5623077-f811-4870-bb9f-9bb8e5edc118.mp4
109
+
110
+ ## Concepts
111
+
112
+ ### Module
113
+
114
+ 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
+
116
+ See [Module](./docs/030_user-guide/020_pepr-modules.md) for more details.
117
+
118
+ ### Capability
119
+
120
+ 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
+
122
+ See [Capabilities](./docs/030_user-guide/040_capabilities.md) for more details.
123
+
124
+ ### Action
125
+
126
+ 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.
127
+
128
+ 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.
129
+
130
+ 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
+
132
+ See [actions](./docs/030_user-guide/030_actions.md) for more details.
133
+
134
+ ## Logical Pepr Flow
135
+
136
+ ![Arch Diagram](_images/pepr-arch.svg)
137
+ [Source Diagram](_images/pepr-arch.svg)
138
+
139
+ ## TypeScript
140
+
141
+ [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).
142
+
143
+ ## Community
144
+
145
+ To join our channel go to [Kubernetes Slack](https://communityinviter.com/apps/kubernetes/community) and join the `#pepr` channel.
146
+
147
+ <a href="https://github.com/defenseunicorns/pepr/graphs/contributors">
148
+ <img src="https://contrib.rocks/image?repo=defenseunicorns/pepr" />
149
+ </a>
150
+
151
+ Made with [contrib.rocks](https://contrib.rocks).
package/SECURITY.md ADDED
@@ -0,0 +1,18 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ If you discover a security vulnerability in Pepr, please report it to us by sending an email to [pepr@defenseunicorns.com](mailto:pepr@defenseunicorns.com?subject=Vulnerability) or directly through the [GitHub UI](https://github.com/defenseunicorns/pepr/security/advisories/new).
6
+
7
+ Please include the following details in your report:
8
+
9
+ - A clear description of the vulnerability
10
+ - Steps to reproduce the vulnerability
11
+ - Any additional information that may be helpful in understanding and fixing the issue
12
+
13
+ We appreciate your help in making Pepr more secure and will acknowledge your contribution in the remediation PR.
14
+
15
+
16
+ ## Contact
17
+
18
+ If you have any questions or concerns regarding the security of Pepr, please contact us at pepr@defenseunicorns.com.
package/SUPPORT.md ADDED
@@ -0,0 +1,16 @@
1
+ # Support
2
+
3
+ ## Reporting Bugs
4
+
5
+ If you find a bug in Pepr, please report it by opening an issue in the [Pepr GitHub repository](https://github.com/defenseunicorns/pepr/issues). Please include as much information as possible in your bug report, including:
6
+
7
+ * The version of Pepr you are using
8
+ * The version of Kubernetes you are using
9
+
10
+ ## Contact
11
+
12
+ You can contact the Pepr team in the following ways:
13
+
14
+ * [Slack](https://kubernetes.slack.com/archives/C06DGH40UCB)
15
+ * [GitHub](https://github.com/defenseunicorns/pepr)
16
+ * [Email](mailto:pepr@defenseunicorns.com)
package/codecov.yaml ADDED
@@ -0,0 +1,19 @@
1
+ codecov:
2
+ require_ci_to_pass: yes
3
+
4
+ comment:
5
+ layout: "reach, diff, flags, files"
6
+ behavior: default
7
+ require_changes: no
8
+
9
+
10
+ coverage:
11
+ status:
12
+ project:
13
+ default:
14
+ target: auto
15
+ threshold: 10%
16
+ patch: # Settings for PR patches
17
+ default:
18
+ target: auto
19
+ threshold: 10% # Adjust as needed
@@ -0,0 +1 @@
1
+ module.exports = { extends: ["@commitlint/config-conventional"] };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "pepr",
3
+ "description": "Kubernetes application engine",
4
+ "author": "Defense Unicorns",
5
+ "homepage": "https://github.com/defenseunicorns/pepr",
6
+ "license": "Apache-2.0",
7
+ "bin": "dist/cli.js",
8
+ "repository": "defenseunicorns/pepr",
9
+ "engines": {
10
+ "node": ">=18.0.0"
11
+ },
12
+ "version": "0.0.0-development",
13
+ "main": "dist/lib.js",
14
+ "types": "dist/lib.d.ts",
15
+ "scripts": {
16
+ "gen-data-json": "node hack/build-template-data.js",
17
+ "prebuild": "rm -fr dist/* && npm run gen-data-json",
18
+ "build": "tsc && node build.mjs",
19
+ "build:image": "npm run build && docker buildx build --tag pepr:dev .",
20
+ "test": "npm run test:unit && npm run test:journey",
21
+ "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage",
22
+ "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run",
23
+ "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi",
24
+ "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm",
25
+ "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",
26
+ "test:journey:build": "npm run build && npm pack",
27
+ "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev",
28
+ "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade",
29
+ "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts",
30
+ "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts",
31
+ "format:check": "eslint src && prettier src --check",
32
+ "format:fix": "eslint src --fix && prettier src --write"
33
+ },
34
+ "dependencies": {
35
+ "@types/ramda": "0.30.0",
36
+ "express": "4.19.2",
37
+ "fast-json-patch": "3.1.1",
38
+ "kubernetes-fluent-client": "2.6.1",
39
+ "pino": "9.1.0",
40
+ "pino-pretty": "11.2.0",
41
+ "prom-client": "15.1.2",
42
+ "ramda": "0.30.1"
43
+ },
44
+ "devDependencies": {
45
+ "@commitlint/cli": "19.3.0",
46
+ "@commitlint/config-conventional": "19.2.2",
47
+ "@jest/globals": "29.7.0",
48
+ "@types/eslint": "8.56.10",
49
+ "@types/express": "4.17.21",
50
+ "@types/node": "18.x.x",
51
+ "@types/node-forge": "1.3.11",
52
+ "@types/prompts": "2.4.9",
53
+ "@types/uuid": "9.0.8",
54
+ "jest": "29.7.0",
55
+ "nock": "13.5.4",
56
+ "ts-jest": "29.1.4"
57
+ },
58
+ "peerDependencies": {
59
+ "@typescript-eslint/eslint-plugin": "6.15.0",
60
+ "@typescript-eslint/parser": "6.15.0",
61
+ "commander": "11.1.0",
62
+ "esbuild": "0.19.10",
63
+ "eslint": "8.56.0",
64
+ "node-forge": "1.3.1",
65
+ "prettier": "3.1.1",
66
+ "prompts": "2.4.2",
67
+ "typescript": "5.3.3",
68
+ "uuid": "9.0.1"
69
+ }
70
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
5
+
6
+ import { banner } from "./cli/banner";
7
+ import build from "./cli/build";
8
+ import deploy from "./cli/deploy";
9
+ import dev from "./cli/dev";
10
+ import format from "./cli/format";
11
+ import monitor from "./cli/monitor";
12
+ import init from "./cli/init/index";
13
+ import uuid from "./cli/uuid";
14
+ import { version } from "./cli/init/templates";
15
+ import { RootCmd } from "./cli/root";
16
+ import update from "./cli/update";
17
+ import kfc from "./cli/kfc";
18
+
19
+ if (process.env.npm_lifecycle_event !== "npx") {
20
+ console.warn("Pepr should be run via `npx pepr <command>` instead of `pepr <command>`.");
21
+ }
22
+
23
+ const program = new RootCmd();
24
+
25
+ program
26
+ .version(version)
27
+ .description(`Pepr (v${version}) - Type safe K8s middleware for humans`)
28
+ .action(() => {
29
+ if (program.args.length < 1) {
30
+ console.log(banner);
31
+ program.help();
32
+ } else {
33
+ console.error(`Invalid command '${program.args.join(" ")}'\n`);
34
+ program.outputHelp();
35
+ process.exitCode = 1;
36
+ }
37
+ });
38
+
39
+ init(program);
40
+ build(program);
41
+ deploy(program);
42
+ dev(program);
43
+ update(program);
44
+ format(program);
45
+ monitor(program);
46
+ uuid(program);
47
+ kfc(program);
48
+ program.parse();