pepr 0.14.2 → 0.16.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/BEST_PRACTICES.md +37 -0
- package/dist/cli.js +100 -47
- 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/capability.d.ts +25 -0
- package/dist/lib/capability.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +2 -1
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +12 -0
- package/dist/lib/helpers.d.ts.map +1 -0
- package/dist/lib/module.d.ts.map +1 -1
- package/dist/lib/schedule.d.ts +76 -0
- package/dist/lib/schedule.d.ts.map +1 -0
- package/dist/lib/storage.d.ts +14 -0
- package/dist/lib/storage.d.ts.map +1 -1
- package/dist/lib/types.d.ts +1 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib.d.ts +3 -6
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +236 -9
- package/dist/lib.js.map +4 -4
- package/package.json +16 -16
- 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/capability.ts +72 -0
- package/src/lib/controller/index.ts +5 -1
- package/src/lib/controller/store.ts +29 -11
- package/src/lib/helpers.ts +52 -0
- package/src/lib/module.ts +1 -0
- package/src/lib/schedule.ts +175 -0
- package/src/lib/storage.ts +33 -0
- package/src/lib/types.ts +1 -0
- package/src/lib.ts +9 -16
- package/src/templates/capabilities/hello-pepr.ts +16 -11
- 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/OnSchedule.md +86 -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/store.md +48 -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,37 @@
|
|
|
1
|
+
# Pepr Best Practices (WIP)
|
|
2
|
+
|
|
3
|
+
## TOC
|
|
4
|
+
|
|
5
|
+
- [Store](#pepr-store)
|
|
6
|
+
- [OnSchedule](#onschedule)
|
|
7
|
+
- [Watch](#watch)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Pepr Store
|
|
11
|
+
|
|
12
|
+
The store is backed by ETCD in a `PeprStore` resource, and updates happen at 5-second intervals when an array of patches is sent to the Kubernetes API Server. The store is intentionally not designed to be `transactional`; instead, it is built to be eventually consistent, meaning that the last operation within the interval will be persisted, potentially overwriting other operations. In simpler terms, changes to the data are made without a guarantee that they will occur simultaneously, so caution is needed in managing errors and ensuring consistency.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## OnSchedule
|
|
16
|
+
|
|
17
|
+
`OnSchedule` is supported by a `PeprStore` to safeguard against schedule loss following a pod restart. It is utilized at the top level, distinct from being within a `Validate`, `Mutate`, or `Watch`. Recommended intervals are 30 seconds or longer, and jobs are advised to be idempotent, meaning that if the code is applied or executed multiple times, the outcome should be the same as if it had been executed only once. A major use-case for `OnSchedule` is day 2 operations.
|
|
18
|
+
|
|
19
|
+
## Watch
|
|
20
|
+
|
|
21
|
+
Pepr facilitates efficient change notifications on resources through `Watch`. It is recommended to use `Watch` instead of `Mutate` or `Validate` when longer running operations are needed, as there is no [timeout limitation](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#timeouts). An instance where `Watch` is beneficial is when API calls need to be chained together. `Watch` operations can be sequentially executed after `Mutate` and `Validate`.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
When(a.Pod)
|
|
25
|
+
.IsCreated()
|
|
26
|
+
.InNamespace("my-app")
|
|
27
|
+
.WithName("database")
|
|
28
|
+
.Mutate(pod => // .... )
|
|
29
|
+
.Validate(pod => // .... )
|
|
30
|
+
.Watch(async (pod, phase) => {
|
|
31
|
+
Log.info(pod, `Pod was ${phase}.`);
|
|
32
|
+
|
|
33
|
+
// do consecutive api calls
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
[TOP](#pepr-best-practices)
|
package/dist/cli.js
CHANGED
|
@@ -106,7 +106,7 @@ var banner = `\x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[
|
|
|
106
106
|
// src/cli/build.ts
|
|
107
107
|
var import_child_process2 = require("child_process");
|
|
108
108
|
var import_esbuild = require("esbuild");
|
|
109
|
-
var
|
|
109
|
+
var import_fs7 = require("fs");
|
|
110
110
|
var import_path = require("path");
|
|
111
111
|
|
|
112
112
|
// src/lib/included-files.ts
|
|
@@ -187,7 +187,7 @@ function genCert(key, name2, issuer) {
|
|
|
187
187
|
|
|
188
188
|
// src/lib/assets/deploy.ts
|
|
189
189
|
var import_crypto = __toESM(require("crypto"));
|
|
190
|
-
var
|
|
190
|
+
var import_fs3 = require("fs");
|
|
191
191
|
var import_kubernetes_fluent_client2 = require("kubernetes-fluent-client");
|
|
192
192
|
|
|
193
193
|
// src/lib/logger.ts
|
|
@@ -529,15 +529,57 @@ function moduleSecret(name2, data, hash) {
|
|
|
529
529
|
};
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
+
// src/lib/helpers.ts
|
|
533
|
+
var import_fs2 = require("fs");
|
|
534
|
+
var createRBACMap = (capabilities) => {
|
|
535
|
+
return capabilities.reduce((acc, capability) => {
|
|
536
|
+
capability.bindings.forEach((binding) => {
|
|
537
|
+
const key = `${binding.kind.group}/${binding.kind.version}/${binding.kind.kind}`;
|
|
538
|
+
acc["pepr.dev/v1/peprstore"] = {
|
|
539
|
+
verbs: ["create", "get", "patch", "watch"],
|
|
540
|
+
plural: "peprstores"
|
|
541
|
+
};
|
|
542
|
+
if (!acc[key] && binding.isWatch) {
|
|
543
|
+
acc[key] = {
|
|
544
|
+
verbs: ["watch"],
|
|
545
|
+
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
return acc;
|
|
550
|
+
}, {});
|
|
551
|
+
};
|
|
552
|
+
async function createDirectoryIfNotExists(path) {
|
|
553
|
+
try {
|
|
554
|
+
await import_fs2.promises.access(path);
|
|
555
|
+
} catch (error) {
|
|
556
|
+
if (error.code === "ENOENT") {
|
|
557
|
+
await import_fs2.promises.mkdir(path, { recursive: true });
|
|
558
|
+
} else {
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
532
564
|
// src/lib/assets/rbac.ts
|
|
533
|
-
function clusterRole(name2) {
|
|
565
|
+
function clusterRole(name2, capabilities, rbacMode = "") {
|
|
566
|
+
const rbacMap = createRBACMap(capabilities);
|
|
534
567
|
return {
|
|
535
568
|
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
536
569
|
kind: "ClusterRole",
|
|
537
570
|
metadata: { name: name2 },
|
|
538
|
-
rules: [
|
|
571
|
+
rules: rbacMode === "scoped" ? [
|
|
572
|
+
...Object.keys(rbacMap).map((key) => {
|
|
573
|
+
let group2;
|
|
574
|
+
key.split("/").length < 3 ? group2 = "" : group2 = key.split("/")[0];
|
|
575
|
+
return {
|
|
576
|
+
apiGroups: [group2],
|
|
577
|
+
resources: [rbacMap[key].plural],
|
|
578
|
+
verbs: rbacMap[key].verbs
|
|
579
|
+
};
|
|
580
|
+
})
|
|
581
|
+
] : [
|
|
539
582
|
{
|
|
540
|
-
// @todo: make this configurable
|
|
541
583
|
apiGroups: ["*"],
|
|
542
584
|
resources: ["*"],
|
|
543
585
|
verbs: ["create", "delete", "get", "list", "patch", "update", "watch"]
|
|
@@ -582,7 +624,7 @@ function storeRole(name2) {
|
|
|
582
624
|
metadata: { name: name2, namespace: "pepr-system" },
|
|
583
625
|
rules: [
|
|
584
626
|
{
|
|
585
|
-
apiGroups: ["pepr.dev
|
|
627
|
+
apiGroups: ["pepr.dev"],
|
|
586
628
|
resources: ["peprstores"],
|
|
587
629
|
resourceNames: [""],
|
|
588
630
|
verbs: ["create", "get", "patch", "watch"]
|
|
@@ -785,21 +827,21 @@ async function deploy(assets, webhookTimeout) {
|
|
|
785
827
|
if (host) {
|
|
786
828
|
return;
|
|
787
829
|
}
|
|
788
|
-
const code = await
|
|
830
|
+
const code = await import_fs3.promises.readFile(path);
|
|
789
831
|
const hash = import_crypto.default.createHash("sha256").update(code).digest("hex");
|
|
790
832
|
if (code.length < 1) {
|
|
791
833
|
throw new Error("No code provided");
|
|
792
834
|
}
|
|
793
|
-
await setupRBAC(name2);
|
|
835
|
+
await setupRBAC(name2, assets.capabilities);
|
|
794
836
|
await setupController(assets, code, hash);
|
|
795
837
|
await setupWatcher(assets, hash);
|
|
796
838
|
}
|
|
797
|
-
async function setupRBAC(name2) {
|
|
839
|
+
async function setupRBAC(name2, capabilities) {
|
|
798
840
|
logger_default.info("Applying cluster role binding");
|
|
799
841
|
const crb = clusterRoleBinding(name2);
|
|
800
842
|
await (0, import_kubernetes_fluent_client2.K8s)(import_kubernetes_fluent_client2.kind.ClusterRoleBinding).Apply(crb);
|
|
801
843
|
logger_default.info("Applying cluster role");
|
|
802
|
-
const cr = clusterRole(name2);
|
|
844
|
+
const cr = clusterRole(name2, capabilities);
|
|
803
845
|
await (0, import_kubernetes_fluent_client2.K8s)(import_kubernetes_fluent_client2.kind.ClusterRole).Apply(cr);
|
|
804
846
|
logger_default.info("Applying service account");
|
|
805
847
|
const sa = serviceAccount(name2);
|
|
@@ -867,7 +909,7 @@ function loadCapabilities(path) {
|
|
|
867
909
|
// src/lib/assets/yaml.ts
|
|
868
910
|
var import_client_node = require("@kubernetes/client-node");
|
|
869
911
|
var import_crypto2 = __toESM(require("crypto"));
|
|
870
|
-
var
|
|
912
|
+
var import_fs4 = require("fs");
|
|
871
913
|
function zarfYaml({ name: name2, image, config }, path) {
|
|
872
914
|
const zarfCfg = {
|
|
873
915
|
kind: "ZarfPackageConfig",
|
|
@@ -894,16 +936,16 @@ function zarfYaml({ name: name2, image, config }, path) {
|
|
|
894
936
|
};
|
|
895
937
|
return (0, import_client_node.dumpYaml)(zarfCfg, { noRefs: true });
|
|
896
938
|
}
|
|
897
|
-
async function allYaml(assets) {
|
|
939
|
+
async function allYaml(assets, rbacMode) {
|
|
898
940
|
const { name: name2, tls, apiToken, path } = assets;
|
|
899
|
-
const code = await
|
|
941
|
+
const code = await import_fs4.promises.readFile(path);
|
|
900
942
|
const hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
901
943
|
const mutateWebhook = await webhookConfig(assets, "mutate");
|
|
902
944
|
const validateWebhook = await webhookConfig(assets, "validate");
|
|
903
945
|
const watchDeployment = watcher(assets, hash);
|
|
904
946
|
const resources = [
|
|
905
947
|
namespace,
|
|
906
|
-
clusterRole(name2),
|
|
948
|
+
clusterRole(name2, assets.capabilities, rbacMode),
|
|
907
949
|
clusterRoleBinding(name2),
|
|
908
950
|
serviceAccount(name2),
|
|
909
951
|
apiTokenSecret(name2, apiToken),
|
|
@@ -949,9 +991,9 @@ var Assets = class {
|
|
|
949
991
|
await deploy(this, webhookTimeout);
|
|
950
992
|
};
|
|
951
993
|
zarfYaml = (path) => zarfYaml(this, path);
|
|
952
|
-
allYaml = async () => {
|
|
994
|
+
allYaml = async (rbacMode) => {
|
|
953
995
|
this.capabilities = await loadCapabilities(this.path);
|
|
954
|
-
return allYaml(this);
|
|
996
|
+
return allYaml(this, rbacMode);
|
|
955
997
|
};
|
|
956
998
|
};
|
|
957
999
|
|
|
@@ -1161,8 +1203,8 @@ var hello_pepr_samples_default = [
|
|
|
1161
1203
|
var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\ndist\ninsecure*\n";
|
|
1162
1204
|
var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
|
|
1163
1205
|
var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
|
|
1164
|
-
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://api.chucknorris.io/jokes/random?category=dev");\n * const joke = await fetch("https://api.chucknorris.io/jokes/random?category=dev") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://api.chucknorris.io/jokes/random?category=dev")\n * ```\n */\ninterface TheChuckNorrisJoke {\n icon_url: string;\n id: string;\n url: string;\n value: string;\n}\n\nWhen(a.ConfigMap)\n .IsCreated()\n .WithLabel("chuck-norris")\n .Mutate(async change => {\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(\n "https://api.chucknorris.io/jokes/random?category=dev",\n );\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n // Add the Chuck Norris joke to the configmap\n change.Raw.data["chuck-says"] = response.data.value;\n return;\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
|
|
1165
|
-
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.
|
|
1206
|
+
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://api.chucknorris.io/jokes/random?category=dev");\n * const joke = await fetch("https://api.chucknorris.io/jokes/random?category=dev") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://api.chucknorris.io/jokes/random?category=dev")\n * ```\n */\ninterface TheChuckNorrisJoke {\n icon_url: string;\n id: string;\n url: string;\n value: string;\n}\n\nWhen(a.ConfigMap)\n .IsCreated()\n .WithLabel("chuck-norris")\n .Mutate(async change => {\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(\n "https://api.chucknorris.io/jokes/random?category=dev",\n );\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n // Add the Chuck Norris joke to the configmap\n change.Raw.data["chuck-says"] = response.data.value;\n return;\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
|
|
1207
|
+
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.16.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.29.9", express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.8.2", pino: "8.16.2", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.4.1", "@commitlint/config-conventional": "18.4.0", "@jest/globals": "29.7.0", "@types/eslint": "8.44.7", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.9", "@types/prompts": "2.4.8", "@types/uuid": "9.0.7", jest: "29.7.0", nock: "13.3.8", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
|
|
1166
1208
|
|
|
1167
1209
|
// src/templates/pepr.code-snippets.json
|
|
1168
1210
|
var pepr_code_snippets_default = {
|
|
@@ -1220,7 +1262,7 @@ var tsconfig_module_default = {
|
|
|
1220
1262
|
};
|
|
1221
1263
|
|
|
1222
1264
|
// src/cli/init/utils.ts
|
|
1223
|
-
var
|
|
1265
|
+
var import_fs5 = require("fs");
|
|
1224
1266
|
function sanitizeName(name2) {
|
|
1225
1267
|
let sanitized = name2.toLowerCase().replace(/[^a-z0-9-]+/gi, "-");
|
|
1226
1268
|
sanitized = sanitized.replace(/^-+|-+$/g, "");
|
|
@@ -1229,7 +1271,7 @@ function sanitizeName(name2) {
|
|
|
1229
1271
|
}
|
|
1230
1272
|
async function createDir(dir) {
|
|
1231
1273
|
try {
|
|
1232
|
-
await
|
|
1274
|
+
await import_fs5.promises.mkdir(dir);
|
|
1233
1275
|
} catch (err) {
|
|
1234
1276
|
if (err && err.code === "EEXIST") {
|
|
1235
1277
|
throw new Error(`Directory ${dir} already exists`);
|
|
@@ -1242,7 +1284,7 @@ function write(path, data) {
|
|
|
1242
1284
|
if (typeof data !== "string") {
|
|
1243
1285
|
data = JSON.stringify(data, null, 2);
|
|
1244
1286
|
}
|
|
1245
|
-
return
|
|
1287
|
+
return import_fs5.promises.writeFile(path, data);
|
|
1246
1288
|
}
|
|
1247
1289
|
|
|
1248
1290
|
// src/cli/init/templates.ts
|
|
@@ -1330,7 +1372,7 @@ var eslint = {
|
|
|
1330
1372
|
|
|
1331
1373
|
// src/cli/format.ts
|
|
1332
1374
|
var import_eslint = require("eslint");
|
|
1333
|
-
var
|
|
1375
|
+
var import_fs6 = require("fs");
|
|
1334
1376
|
var import_prettier = require("prettier");
|
|
1335
1377
|
function format_default(program2) {
|
|
1336
1378
|
program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
|
|
@@ -1363,7 +1405,7 @@ async function peprFormat(validateOnly) {
|
|
|
1363
1405
|
await import_eslint.ESLint.outputFixes(results);
|
|
1364
1406
|
}
|
|
1365
1407
|
for (const { filePath } of results) {
|
|
1366
|
-
const content = await
|
|
1408
|
+
const content = await import_fs6.promises.readFile(filePath, "utf8");
|
|
1367
1409
|
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
1368
1410
|
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
1369
1411
|
if (validateOnly) {
|
|
@@ -1372,7 +1414,7 @@ async function peprFormat(validateOnly) {
|
|
|
1372
1414
|
console.error(`File ${filePath} is not formatted correctly`);
|
|
1373
1415
|
}
|
|
1374
1416
|
} else {
|
|
1375
|
-
await
|
|
1417
|
+
await import_fs6.promises.writeFile(filePath, formatted);
|
|
1376
1418
|
}
|
|
1377
1419
|
}
|
|
1378
1420
|
return !hasFailure;
|
|
@@ -1384,7 +1426,9 @@ async function peprFormat(validateOnly) {
|
|
|
1384
1426
|
}
|
|
1385
1427
|
|
|
1386
1428
|
// src/cli/build.ts
|
|
1429
|
+
var import_commander = require("commander");
|
|
1387
1430
|
var peprTS2 = "pepr.ts";
|
|
1431
|
+
var outputDir = "dist";
|
|
1388
1432
|
function build_default(program2) {
|
|
1389
1433
|
program2.command("build").description("Build a Pepr Module for deployment").option(
|
|
1390
1434
|
"-e, --entry-point [file]",
|
|
@@ -1392,8 +1436,17 @@ function build_default(program2) {
|
|
|
1392
1436
|
peprTS2
|
|
1393
1437
|
).option(
|
|
1394
1438
|
"-r, --registry-info [<registry>/<username>]",
|
|
1395
|
-
"
|
|
1439
|
+
"Registry Info: Image registry and username. Note: You must be signed into the registry"
|
|
1440
|
+
).option("-o, --output-dir [output directory]", "Define where to place build output").addOption(
|
|
1441
|
+
new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(["admin", "scoped"]).default("admin")
|
|
1396
1442
|
).action(async (opts) => {
|
|
1443
|
+
if (opts.outputDir) {
|
|
1444
|
+
outputDir = opts.outputDir;
|
|
1445
|
+
createDirectoryIfNotExists(outputDir).catch((error) => {
|
|
1446
|
+
console.error(`Error creating output directory: ${error}`);
|
|
1447
|
+
process.exit(1);
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1397
1450
|
const { cfg, path, uuid } = await buildModule(void 0, opts.entryPoint);
|
|
1398
1451
|
const { includedFiles } = cfg.pepr;
|
|
1399
1452
|
let image = "";
|
|
@@ -1422,12 +1475,12 @@ function build_default(program2) {
|
|
|
1422
1475
|
assets.image = image;
|
|
1423
1476
|
}
|
|
1424
1477
|
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
1425
|
-
const yamlPath = (0, import_path.resolve)(
|
|
1426
|
-
const yaml = await assets.allYaml();
|
|
1427
|
-
const zarfPath = (0, import_path.resolve)(
|
|
1478
|
+
const yamlPath = (0, import_path.resolve)(outputDir, yamlFile);
|
|
1479
|
+
const yaml = await assets.allYaml(opts.rbacMode);
|
|
1480
|
+
const zarfPath = (0, import_path.resolve)(outputDir, "zarf.yaml");
|
|
1428
1481
|
const zarf = assets.zarfYaml(yamlFile);
|
|
1429
|
-
await
|
|
1430
|
-
await
|
|
1482
|
+
await import_fs7.promises.writeFile(yamlPath, yaml);
|
|
1483
|
+
await import_fs7.promises.writeFile(zarfPath, zarf);
|
|
1431
1484
|
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
1432
1485
|
});
|
|
1433
1486
|
}
|
|
@@ -1438,15 +1491,15 @@ async function loadModule(entryPoint = peprTS2) {
|
|
|
1438
1491
|
const cfgPath = (0, import_path.resolve)(".", "package.json");
|
|
1439
1492
|
const input = (0, import_path.resolve)(".", entryPoint);
|
|
1440
1493
|
try {
|
|
1441
|
-
await
|
|
1442
|
-
await
|
|
1494
|
+
await import_fs7.promises.access(cfgPath);
|
|
1495
|
+
await import_fs7.promises.access(input);
|
|
1443
1496
|
} catch (e) {
|
|
1444
1497
|
console.error(
|
|
1445
1498
|
`Could not find ${cfgPath} or ${input} in the current directory. Please run this command from the root of your module's directory.`
|
|
1446
1499
|
);
|
|
1447
1500
|
process.exit(1);
|
|
1448
1501
|
}
|
|
1449
|
-
const moduleText = await
|
|
1502
|
+
const moduleText = await import_fs7.promises.readFile(cfgPath, { encoding: "utf-8" });
|
|
1450
1503
|
const cfg = JSON.parse(moduleText);
|
|
1451
1504
|
const { uuid } = cfg.pepr;
|
|
1452
1505
|
const name2 = `pepr-${uuid}.js`;
|
|
@@ -1458,7 +1511,7 @@ async function loadModule(entryPoint = peprTS2) {
|
|
|
1458
1511
|
cfg,
|
|
1459
1512
|
input,
|
|
1460
1513
|
name: name2,
|
|
1461
|
-
path: (0, import_path.resolve)(
|
|
1514
|
+
path: (0, import_path.resolve)(outputDir, name2),
|
|
1462
1515
|
uuid
|
|
1463
1516
|
};
|
|
1464
1517
|
}
|
|
@@ -1507,7 +1560,7 @@ async function buildModule(reloader, entryPoint = peprTS2) {
|
|
|
1507
1560
|
}
|
|
1508
1561
|
if (entryPoint !== peprTS2) {
|
|
1509
1562
|
ctxCfg.minify = false;
|
|
1510
|
-
ctxCfg.outfile = (0, import_path.resolve)(
|
|
1563
|
+
ctxCfg.outfile = (0, import_path.resolve)(outputDir, (0, import_path.basename)(entryPoint, (0, import_path.extname)(entryPoint))) + ".js";
|
|
1511
1564
|
ctxCfg.packages = "external";
|
|
1512
1565
|
ctxCfg.treeShaking = false;
|
|
1513
1566
|
}
|
|
@@ -1589,7 +1642,7 @@ function deploy_default(program2) {
|
|
|
1589
1642
|
|
|
1590
1643
|
// src/cli/dev.ts
|
|
1591
1644
|
var import_child_process3 = require("child_process");
|
|
1592
|
-
var
|
|
1645
|
+
var import_fs8 = require("fs");
|
|
1593
1646
|
var import_prompts2 = __toESM(require("prompts"));
|
|
1594
1647
|
function dev_default(program2) {
|
|
1595
1648
|
program2.command("dev").description("Setup a local webhook development environment").option("-h, --host [host]", "Host to listen on", "host.k3d.internal").option("--confirm", "Skip confirmation prompt").action(async (opts) => {
|
|
@@ -1612,8 +1665,8 @@ function dev_default(program2) {
|
|
|
1612
1665
|
path,
|
|
1613
1666
|
opts.host
|
|
1614
1667
|
);
|
|
1615
|
-
await
|
|
1616
|
-
await
|
|
1668
|
+
await import_fs8.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
|
|
1669
|
+
await import_fs8.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
|
|
1617
1670
|
try {
|
|
1618
1671
|
let program3;
|
|
1619
1672
|
const runFork = async () => {
|
|
@@ -1657,7 +1710,7 @@ var import_path2 = require("path");
|
|
|
1657
1710
|
var import_prompts4 = __toESM(require("prompts"));
|
|
1658
1711
|
|
|
1659
1712
|
// src/cli/init/walkthrough.ts
|
|
1660
|
-
var
|
|
1713
|
+
var import_fs9 = require("fs");
|
|
1661
1714
|
var import_prompts3 = __toESM(require("prompts"));
|
|
1662
1715
|
|
|
1663
1716
|
// src/lib/errors.ts
|
|
@@ -1677,7 +1730,7 @@ function walkthrough() {
|
|
|
1677
1730
|
validate: async (val) => {
|
|
1678
1731
|
try {
|
|
1679
1732
|
const name2 = sanitizeName(val);
|
|
1680
|
-
await
|
|
1733
|
+
await import_fs9.promises.access(name2, import_fs9.promises.constants.F_OK);
|
|
1681
1734
|
return "A directory with this name already exists";
|
|
1682
1735
|
} catch (e) {
|
|
1683
1736
|
return val.length > 2 || "The name must be at least 3 characters long";
|
|
@@ -1797,11 +1850,11 @@ function init_default(program2) {
|
|
|
1797
1850
|
}
|
|
1798
1851
|
|
|
1799
1852
|
// src/cli/root.ts
|
|
1800
|
-
var
|
|
1801
|
-
var RootCmd = class extends
|
|
1853
|
+
var import_commander2 = require("commander");
|
|
1854
|
+
var RootCmd = class extends import_commander2.Command {
|
|
1802
1855
|
// eslint-disable-next-line class-methods-use-this
|
|
1803
1856
|
createCommand(name2) {
|
|
1804
|
-
const cmd = new
|
|
1857
|
+
const cmd = new import_commander2.Command(name2);
|
|
1805
1858
|
cmd.option("-l, --log-level [level]", "Log level: debug, info, warn, error", "info");
|
|
1806
1859
|
cmd.hook("preAction", (run) => {
|
|
1807
1860
|
logger_default.level = run.opts().logLevel;
|
|
@@ -1812,7 +1865,7 @@ var RootCmd = class extends import_commander.Command {
|
|
|
1812
1865
|
|
|
1813
1866
|
// src/cli/update.ts
|
|
1814
1867
|
var import_child_process5 = require("child_process");
|
|
1815
|
-
var
|
|
1868
|
+
var import_fs10 = __toESM(require("fs"));
|
|
1816
1869
|
var import_path3 = require("path");
|
|
1817
1870
|
var import_prompts5 = __toESM(require("prompts"));
|
|
1818
1871
|
function update_default(program2) {
|
|
@@ -1852,12 +1905,12 @@ function update_default(program2) {
|
|
|
1852
1905
|
await write((0, import_path3.resolve)(".vscode", snippet.path), snippet.data);
|
|
1853
1906
|
await write((0, import_path3.resolve)(".vscode", codeSettings.path), codeSettings.data);
|
|
1854
1907
|
const samplePath = (0, import_path3.resolve)("capabilities", samplesYaml.path);
|
|
1855
|
-
if (
|
|
1856
|
-
|
|
1908
|
+
if (import_fs10.default.existsSync(samplePath)) {
|
|
1909
|
+
import_fs10.default.unlinkSync(samplePath);
|
|
1857
1910
|
await write(samplePath, samplesYaml.data);
|
|
1858
1911
|
}
|
|
1859
1912
|
const tsPath = (0, import_path3.resolve)("capabilities", helloPepr.path);
|
|
1860
|
-
if (
|
|
1913
|
+
if (import_fs10.default.existsSync(tsPath)) {
|
|
1861
1914
|
await write(tsPath, helloPepr.data);
|
|
1862
1915
|
}
|
|
1863
1916
|
}
|
package/dist/controller.js
CHANGED
|
@@ -48,7 +48,7 @@ if (process.env.LOG_LEVEL) {
|
|
|
48
48
|
var logger_default = Log;
|
|
49
49
|
|
|
50
50
|
// src/templates/data.json
|
|
51
|
-
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.
|
|
51
|
+
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.16.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.29.9", express: "4.18.2", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "1.8.2", pino: "8.16.2", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.4.1", "@commitlint/config-conventional": "18.4.0", "@jest/globals": "29.7.0", "@types/eslint": "8.44.7", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.9", "@types/prompts": "2.4.8", "@types/uuid": "9.0.7", jest: "29.7.0", nock: "13.3.8", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.7.3", "@typescript-eslint/parser": "6.7.3", commander: "11.0.0", esbuild: "0.19.4", eslint: "8.50.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.1" } };
|
|
52
52
|
|
|
53
53
|
// src/runtime/controller.ts
|
|
54
54
|
var { version } = packageJSON;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/deploy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/deploy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAS3B,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,iBA8CnE"}
|
|
@@ -13,6 +13,6 @@ export declare class Assets {
|
|
|
13
13
|
constructor(config: ModuleConfig, path: string, host?: string | undefined);
|
|
14
14
|
deploy: (webhookTimeout?: number) => Promise<void>;
|
|
15
15
|
zarfYaml: (path: string) => string;
|
|
16
|
-
allYaml: () => Promise<string>;
|
|
16
|
+
allYaml: (rbacMode: string) => Promise<string>;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAK5C,qBAAa,MAAM;IAQf,QAAQ,CAAC,MAAM,EAAE,YAAY;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,CAAC;IAThB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAG,gBAAgB,EAAE,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;gBAGH,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,oBAAQ;IAaxB,MAAM,oBAA2B,MAAM,mBAGrC;IAEF,QAAQ,SAAU,MAAM,YAA0B;IAElD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAK5C,qBAAa,MAAM;IAQf,QAAQ,CAAC,MAAM,EAAE,YAAY;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,CAAC;IAThB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAG,gBAAgB,EAAE,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;gBAGH,MAAM,EAAE,YAAY,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,oBAAQ;IAaxB,MAAM,oBAA2B,MAAM,mBAGrC;IAEF,QAAQ,SAAU,MAAM,YAA0B;IAElD,OAAO,aAAoB,MAAM,qBAG/B;CACH"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { kind } from "kubernetes-fluent-client";
|
|
2
|
+
import { CapabilityExport } from "../types";
|
|
2
3
|
/**
|
|
3
4
|
* Grants the controller access to cluster resources beyond the mutating webhook.
|
|
4
5
|
*
|
|
5
6
|
* @todo: should dynamically generate this based on resources used by the module. will also need to explore how this should work for multiple modules.
|
|
6
7
|
* @returns
|
|
7
8
|
*/
|
|
8
|
-
export declare function clusterRole(name: string): kind.ClusterRole;
|
|
9
|
+
export declare function clusterRole(name: string, capabilities: CapabilityExport[], rbacMode?: string): kind.ClusterRole;
|
|
9
10
|
export declare function clusterRoleBinding(name: string): kind.ClusterRoleBinding;
|
|
10
11
|
export declare function serviceAccount(name: string): kind.ServiceAccount;
|
|
11
12
|
export declare function storeRole(name: string): kind.Role;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rbac.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/rbac.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"rbac.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/rbac.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,EAAE,QAAQ,GAAE,MAAW,GAAG,IAAI,CAAC,WAAW,CA6BnH;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAkBxE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,cAAc,CAShE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,CAejD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,WAAW,CAmB/D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Assets } from ".";
|
|
2
2
|
export declare function zarfYaml({ name, image, config }: Assets, path: string): string;
|
|
3
|
-
export declare function allYaml(assets: Assets): Promise<string>;
|
|
3
|
+
export declare function allYaml(assets: Assets, rbacMode: string): Promise<string>;
|
|
4
4
|
//# sourceMappingURL=yaml.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/yaml.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAO3B,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UA0BrE;AAED,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../../../src/lib/assets/yaml.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAO3B,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UA0BrE;AAED,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBA0C7D"}
|
package/dist/lib/capability.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { GenericClass, GroupVersionKind } from "kubernetes-fluent-client";
|
|
2
2
|
import { PeprStore, Storage } from "./storage";
|
|
3
|
+
import { Schedule } from "./schedule";
|
|
3
4
|
import { Binding, CapabilityCfg, CapabilityExport, WhenSelector } from "./types";
|
|
4
5
|
/**
|
|
5
6
|
* A capability is a unit of functionality that can be registered with the Pepr runtime.
|
|
6
7
|
*/
|
|
7
8
|
export declare class Capability implements CapabilityExport {
|
|
8
9
|
#private;
|
|
10
|
+
hasSchedule: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Run code on a schedule with the capability.
|
|
13
|
+
*
|
|
14
|
+
* @param schedule The schedule to run the code on
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
OnSchedule: (schedule: Schedule) => void;
|
|
9
18
|
/**
|
|
10
19
|
* Store is a key-value data store that can be used to persist data that should be shared
|
|
11
20
|
* between requests. Each capability has its own store, and the data is persisted in Kubernetes
|
|
@@ -14,11 +23,27 @@ export declare class Capability implements CapabilityExport {
|
|
|
14
23
|
* Note: You should only access the store from within an action.
|
|
15
24
|
*/
|
|
16
25
|
Store: PeprStore;
|
|
26
|
+
/**
|
|
27
|
+
* ScheduleStore is a key-value data store used to persist schedule data that should be shared
|
|
28
|
+
* between intervals. Each Schedule shares store, and the data is persisted in Kubernetes
|
|
29
|
+
* in the `pepr-system` namespace.
|
|
30
|
+
*
|
|
31
|
+
* Note: There is no direct access to schedule store
|
|
32
|
+
*/
|
|
33
|
+
ScheduleStore: PeprStore;
|
|
17
34
|
get bindings(): Binding[];
|
|
18
35
|
get name(): string;
|
|
19
36
|
get description(): string;
|
|
20
37
|
get namespaces(): string[];
|
|
21
38
|
constructor(cfg: CapabilityCfg);
|
|
39
|
+
/**
|
|
40
|
+
* Register the store with the capability. This is called automatically by the Pepr controller.
|
|
41
|
+
*
|
|
42
|
+
* @param store
|
|
43
|
+
*/
|
|
44
|
+
registerScheduleStore: () => {
|
|
45
|
+
scheduleStore: Storage;
|
|
46
|
+
};
|
|
22
47
|
/**
|
|
23
48
|
* Register the store with the capability. This is called automatically by the Pepr controller.
|
|
24
49
|
*
|