pepr 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +123 -5
- package/dist/controller.js +1 -1
- package/dist/lib/assets/index.d.ts +2 -0
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +6 -0
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/module-helpers.d.ts +5 -0
- package/dist/lib/module-helpers.d.ts.map +1 -0
- package/dist/lib/types.d.ts +10 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +34 -10
- package/dist/lib.js.map +4 -4
- package/package.json +3 -3
- package/src/cli.ts +2 -0
- package/src/lib/assets/index.ts +10 -1
- package/src/lib/controller/index.ts +20 -13
- package/src/lib/controller/store.ts +1 -1
- package/src/lib/helpers.ts +69 -0
- package/src/lib/module-helpers.ts +27 -0
- package/src/lib/types.ts +10 -0
- package/src/lib.ts +2 -0
- package/website/assets/img/Pepr.Horizontal.white.svg +144 -0
- package/website/assets/scss/_styles_project.scss +4 -0
- package/website/content/en/docs/cli.md +16 -0
package/dist/cli.js
CHANGED
|
@@ -564,6 +564,55 @@ async function createDirectoryIfNotExists(path) {
|
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
|
+
function hasEveryOverlap(array1, array2) {
|
|
568
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
return array1.every((element) => array2.includes(element));
|
|
572
|
+
}
|
|
573
|
+
function hasAnyOverlap(array1, array2) {
|
|
574
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
return array1.some((element) => array2.includes(element));
|
|
578
|
+
}
|
|
579
|
+
function ignoredNamespaceConflict(ignoreNamespaces, bindingNamespaces) {
|
|
580
|
+
return hasAnyOverlap(bindingNamespaces, ignoreNamespaces);
|
|
581
|
+
}
|
|
582
|
+
function bindingAndCapabilityNSConflict(bindingNamespaces, capabilityNamespaces) {
|
|
583
|
+
if (!capabilityNamespaces) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
return capabilityNamespaces.length !== 0 && !hasEveryOverlap(bindingNamespaces, capabilityNamespaces);
|
|
587
|
+
}
|
|
588
|
+
function generateWatchNamespaceError(ignoredNamespaces, bindingNamespaces, capabilityNamespaces) {
|
|
589
|
+
let err = "";
|
|
590
|
+
if (ignoredNamespaceConflict(ignoredNamespaces, bindingNamespaces)) {
|
|
591
|
+
err += `Binding uses a Pepr ignored namespace: ignoredNamespaces: [${ignoredNamespaces.join(
|
|
592
|
+
", "
|
|
593
|
+
)}] bindingNamespaces: [${bindingNamespaces.join(", ")}].`;
|
|
594
|
+
}
|
|
595
|
+
if (bindingAndCapabilityNSConflict(bindingNamespaces, capabilityNamespaces)) {
|
|
596
|
+
err += `Binding uses namespace not governed by capability: bindingNamespaces: [${bindingNamespaces.join(
|
|
597
|
+
", "
|
|
598
|
+
)}] capabilityNamespaces:$[${capabilityNamespaces.join(", ")}].`;
|
|
599
|
+
}
|
|
600
|
+
return err.replace(/\.([^ ])/g, ". $1");
|
|
601
|
+
}
|
|
602
|
+
function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
603
|
+
const { namespaces: capabilityNamespaces, bindings, name: name2 } = capability;
|
|
604
|
+
const bindingNamespaces = bindings.flatMap((binding) => binding.filters.namespaces);
|
|
605
|
+
const namespaceError = generateWatchNamespaceError(
|
|
606
|
+
ignoredNamespaces ? ignoredNamespaces : [],
|
|
607
|
+
bindingNamespaces,
|
|
608
|
+
capabilityNamespaces ? capabilityNamespaces : []
|
|
609
|
+
);
|
|
610
|
+
if (namespaceError !== "") {
|
|
611
|
+
throw new Error(
|
|
612
|
+
`Error in ${name2} capability. A binding violates namespace rules. Please check ignoredNamespaces and capability namespaces: ${namespaceError}`
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
567
616
|
|
|
568
617
|
// src/lib/assets/rbac.ts
|
|
569
618
|
function clusterRole(name2, capabilities, rbacMode = "") {
|
|
@@ -725,7 +774,7 @@ async function generateWebhookRules(assets, isMutateWebhook) {
|
|
|
725
774
|
for (const capability of capabilities) {
|
|
726
775
|
console.info(`Module ${config.uuid} has capability: ${capability.name}`);
|
|
727
776
|
for (const binding of capability.bindings) {
|
|
728
|
-
const { event, kind:
|
|
777
|
+
const { event, kind: kind4, isMutate, isValidate } = binding;
|
|
729
778
|
if (isMutateWebhook && !isMutate) {
|
|
730
779
|
continue;
|
|
731
780
|
}
|
|
@@ -738,10 +787,10 @@ async function generateWebhookRules(assets, isMutateWebhook) {
|
|
|
738
787
|
} else {
|
|
739
788
|
operations.push(event);
|
|
740
789
|
}
|
|
741
|
-
const resource =
|
|
790
|
+
const resource = kind4.plural || `${kind4.kind.toLowerCase()}s`;
|
|
742
791
|
const ruleObject = {
|
|
743
|
-
apiGroups: [
|
|
744
|
-
apiVersions: [
|
|
792
|
+
apiGroups: [kind4.group],
|
|
793
|
+
apiVersions: [kind4.version || "*"],
|
|
745
794
|
operations,
|
|
746
795
|
resources: [resource]
|
|
747
796
|
};
|
|
@@ -985,6 +1034,7 @@ var Assets = class {
|
|
|
985
1034
|
this.path = path;
|
|
986
1035
|
this.host = host;
|
|
987
1036
|
this.name = `pepr-${config.uuid}`;
|
|
1037
|
+
this.alwaysIgnore = config.alwaysIgnore;
|
|
988
1038
|
this.image = `ghcr.io/defenseunicorns/pepr/controller:v${config.peprVersion}`;
|
|
989
1039
|
this.tls = genTLS(this.host || `${this.name}.pepr-system.svc`);
|
|
990
1040
|
this.apiToken = import_crypto3.default.randomBytes(32).toString("hex");
|
|
@@ -992,6 +1042,7 @@ var Assets = class {
|
|
|
992
1042
|
name;
|
|
993
1043
|
tls;
|
|
994
1044
|
apiToken;
|
|
1045
|
+
alwaysIgnore;
|
|
995
1046
|
capabilities;
|
|
996
1047
|
image;
|
|
997
1048
|
deploy = async (webhookTimeout) => {
|
|
@@ -1001,6 +1052,9 @@ var Assets = class {
|
|
|
1001
1052
|
zarfYaml = (path) => zarfYaml(this, path);
|
|
1002
1053
|
allYaml = async (rbacMode) => {
|
|
1003
1054
|
this.capabilities = await loadCapabilities(this.path);
|
|
1055
|
+
for (const capability of this.capabilities) {
|
|
1056
|
+
namespaceComplianceValidator(capability, this.alwaysIgnore.namespaces);
|
|
1057
|
+
}
|
|
1004
1058
|
return allYaml(this, rbacMode);
|
|
1005
1059
|
};
|
|
1006
1060
|
};
|
|
@@ -1212,7 +1266,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
1212
1266
|
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';
|
|
1213
1267
|
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';
|
|
1214
1268
|
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';
|
|
1215
|
-
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.
|
|
1269
|
+
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.19.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.9.0", pino: "8.16.2", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.4.3", "@commitlint/config-conventional": "18.4.3", "@jest/globals": "29.7.0", "@types/eslint": "8.44.8", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.10", "@types/prompts": "2.4.9", "@types/uuid": "9.0.7", jest: "29.7.0", nock: "13.4.0", "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" } };
|
|
1216
1270
|
|
|
1217
1271
|
// src/templates/pepr.code-snippets.json
|
|
1218
1272
|
var pepr_code_snippets_default = {
|
|
@@ -1714,6 +1768,69 @@ function dev_default(program2) {
|
|
|
1714
1768
|
});
|
|
1715
1769
|
}
|
|
1716
1770
|
|
|
1771
|
+
// src/cli/monitor.ts
|
|
1772
|
+
var import_client_node3 = require("@kubernetes/client-node");
|
|
1773
|
+
var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
|
|
1774
|
+
var import_stream = __toESM(require("stream"));
|
|
1775
|
+
function monitor_default(program2) {
|
|
1776
|
+
program2.command("monitor <module-uuid>").description("Monitor a Pepr Module").action(async (uuid) => {
|
|
1777
|
+
if (!uuid) {
|
|
1778
|
+
console.error("Module UUID is required");
|
|
1779
|
+
process.exit(1);
|
|
1780
|
+
}
|
|
1781
|
+
const pods = await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Pod).InNamespace("pepr-system").WithLabel("app", `pepr-${uuid}`).Get();
|
|
1782
|
+
const podNames = pods.items.flatMap((pod) => pod.metadata.name);
|
|
1783
|
+
if (podNames.length < 1) {
|
|
1784
|
+
console.error(`No pods found for module ${uuid}`);
|
|
1785
|
+
process.exit(1);
|
|
1786
|
+
}
|
|
1787
|
+
const kc = new import_client_node3.KubeConfig();
|
|
1788
|
+
kc.loadFromDefault();
|
|
1789
|
+
const log = new import_client_node3.Log(kc);
|
|
1790
|
+
const logStream = new import_stream.default.PassThrough();
|
|
1791
|
+
logStream.on("data", (chunk) => {
|
|
1792
|
+
const respMsg = `"msg":"Check response"`;
|
|
1793
|
+
const lines = chunk.toString().split("\n");
|
|
1794
|
+
for (const line of lines) {
|
|
1795
|
+
if (line.includes(respMsg)) {
|
|
1796
|
+
try {
|
|
1797
|
+
const payload = JSON.parse(line);
|
|
1798
|
+
const isMutate = payload.res.patchType || payload.res.warnings;
|
|
1799
|
+
const name2 = `${payload.namespace}${payload.name}`;
|
|
1800
|
+
const uid = payload.uid;
|
|
1801
|
+
if (isMutate) {
|
|
1802
|
+
const allowOrDeny = payload.res.allowed ? "\u2705" : "\u274C";
|
|
1803
|
+
console.log(`
|
|
1804
|
+
${allowOrDeny} MUTATE ${name2} (${uid})`);
|
|
1805
|
+
} else {
|
|
1806
|
+
const failures = Array.isArray(payload.res) ? payload.res : [payload.res];
|
|
1807
|
+
const filteredFailures = failures.filter((r) => !r.allowed).map((r) => r.status.message);
|
|
1808
|
+
if (filteredFailures.length > 0) {
|
|
1809
|
+
console.log(`
|
|
1810
|
+
\u274C VALIDATE ${name2} (${uid})`);
|
|
1811
|
+
console.debug(filteredFailures);
|
|
1812
|
+
} else {
|
|
1813
|
+
console.log(`
|
|
1814
|
+
\u2705 VALIDATE ${name2} (${uid})`);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
} catch {
|
|
1818
|
+
console.warn(`
|
|
1819
|
+
IGNORED - Unable to parse line: ${line}.`);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
});
|
|
1824
|
+
for (const podName of podNames) {
|
|
1825
|
+
await log.log("pepr-system", podName, "server", logStream, {
|
|
1826
|
+
follow: true,
|
|
1827
|
+
pretty: false,
|
|
1828
|
+
timestamps: false
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1717
1834
|
// src/cli/init/index.ts
|
|
1718
1835
|
var import_child_process4 = require("child_process");
|
|
1719
1836
|
var import_path2 = require("path");
|
|
@@ -1953,4 +2070,5 @@ deploy_default(program);
|
|
|
1953
2070
|
dev_default(program);
|
|
1954
2071
|
update_default(program);
|
|
1955
2072
|
format_default(program);
|
|
2073
|
+
monitor_default(program);
|
|
1956
2074
|
program.parse();
|
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.19.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.9.0", pino: "8.16.2", "pino-pretty": "10.2.3", "prom-client": "15.0.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "18.4.3", "@commitlint/config-conventional": "18.4.3", "@jest/globals": "29.7.0", "@types/eslint": "8.44.8", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.10", "@types/prompts": "2.4.9", "@types/uuid": "9.0.7", jest: "29.7.0", nock: "13.4.0", "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,6 +1,7 @@
|
|
|
1
1
|
import { ModuleConfig } from "../module";
|
|
2
2
|
import { TLSOut } from "../tls";
|
|
3
3
|
import { CapabilityExport } from "../types";
|
|
4
|
+
import { WebhookIgnore } from "../k8s";
|
|
4
5
|
export declare class Assets {
|
|
5
6
|
readonly config: ModuleConfig;
|
|
6
7
|
readonly path: string;
|
|
@@ -8,6 +9,7 @@ export declare class Assets {
|
|
|
8
9
|
readonly name: string;
|
|
9
10
|
readonly tls: TLSOut;
|
|
10
11
|
readonly apiToken: string;
|
|
12
|
+
readonly alwaysIgnore: WebhookIgnore;
|
|
11
13
|
capabilities: CapabilityExport[];
|
|
12
14
|
image: string;
|
|
13
15
|
constructor(config: ModuleConfig, path: string, host?: string | undefined);
|
|
@@ -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;
|
|
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;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAMvC,qBAAa,MAAM;IAUf,QAAQ,CAAC,MAAM,EAAE,YAAY;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,IAAI,CAAC;IAXhB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAG,aAAa,CAAC;IACtC,YAAY,EAAG,gBAAgB,EAAE,CAAC;IAElC,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,qBAQ/B;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAoB,MAAM,QAAQ,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/controller/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAoB,MAAM,QAAQ,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAMtD,qBAAa,UAAU;;gBAoBnB,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,UAAU,EAAE,EAC1B,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,EAC5C,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,EACzC,OAAO,CAAC,EAAE,MAAM,IAAI;IAiCtB,+BAA+B;IAC/B,WAAW,SAAU,MAAM,UAqDzB;CA8LH"}
|
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -8,5 +8,11 @@ type RBACMap = {
|
|
|
8
8
|
export declare const addVerbIfNotExists: (verbs: string[], verb: string) => void;
|
|
9
9
|
export declare const createRBACMap: (capabilities: CapabilityExport[]) => RBACMap;
|
|
10
10
|
export declare function createDirectoryIfNotExists(path: string): Promise<void>;
|
|
11
|
+
export declare function hasEveryOverlap<T>(array1: T[], array2: T[]): boolean;
|
|
12
|
+
export declare function hasAnyOverlap<T>(array1: T[], array2: T[]): boolean;
|
|
13
|
+
export declare function ignoredNamespaceConflict(ignoreNamespaces: string[], bindingNamespaces: string[]): boolean;
|
|
14
|
+
export declare function bindingAndCapabilityNSConflict(bindingNamespaces: string[], capabilityNamespaces: string[]): boolean;
|
|
15
|
+
export declare function generateWatchNamespaceError(ignoredNamespaces: string[], bindingNamespaces: string[], capabilityNamespaces: string[]): string;
|
|
16
|
+
export declare function namespaceComplianceValidator(capability: CapabilityExport, ignoredNamespaces?: string[]): void;
|
|
11
17
|
export {};
|
|
12
18
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG3C,KAAK,OAAO,GAAG;IACb,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,MAAM,E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M,EAAE,UAoB/B;AAGD,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,EAAE,MAAM,EAAE,QActG"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PeprValidateRequest } from "./validate-request";
|
|
2
|
+
import { PeprMutateRequest } from "./mutate-request";
|
|
3
|
+
import { a } from "../lib";
|
|
4
|
+
export declare function containers(request: PeprValidateRequest<a.Pod> | PeprMutateRequest<a.Pod>, containerType?: "containers" | "initContainers" | "ephemeralContainers"): import("@kubernetes/client-node").V1Container[];
|
|
5
|
+
//# sourceMappingURL=module-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/module-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAG3B,wBAAgB,UAAU,CACxB,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,EAC9D,aAAa,CAAC,EAAE,YAAY,GAAG,gBAAgB,GAAG,qBAAqB,mDAgBxE"}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -2,6 +2,16 @@ import { GenericClass, GroupVersionKind, KubernetesObject } from "kubernetes-flu
|
|
|
2
2
|
import { WatchAction } from "kubernetes-fluent-client/dist/fluent/types";
|
|
3
3
|
import { PeprMutateRequest } from "./mutate-request";
|
|
4
4
|
import { PeprValidateRequest } from "./validate-request";
|
|
5
|
+
/**
|
|
6
|
+
* Specifically for parsing logs in monitor mode
|
|
7
|
+
*/
|
|
8
|
+
export interface ResponseItem {
|
|
9
|
+
uid?: string;
|
|
10
|
+
allowed: boolean;
|
|
11
|
+
status: {
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
16
|
* Recursively make all properties in T optional.
|
|
7
17
|
*/
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC;AAEF;;GAEG;AACH,oBAAY,KAAK;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,cAAc,mBAAmB;IACjC,GAAG,MAAM;CACV;AAED,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,IAAI;IACjD,0FAA0F;IAC1F,kBAAkB,EAAE,MAAM,UAAU,CAAC,CAAC,CAAC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BAAsB,CAAC;AAE9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC"}
|
package/dist/lib.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ import { PeprModule } from "./lib/module";
|
|
|
6
6
|
import { PeprMutateRequest } from "./lib/mutate-request";
|
|
7
7
|
import * as PeprUtils from "./lib/utils";
|
|
8
8
|
import { PeprValidateRequest } from "./lib/validate-request";
|
|
9
|
-
|
|
9
|
+
import { containers } from "./lib/module-helpers";
|
|
10
|
+
export { Capability, K8s, Log, PeprModule, PeprMutateRequest, PeprUtils, PeprValidateRequest, R, RegisterKind, a, fetch, fetchStatus, kind, containers, };
|
|
10
11
|
//# sourceMappingURL=lib.d.ts.map
|
package/dist/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAClG,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EACL,UAAU,EACV,GAAG,EACH,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,CAAC,EACD,YAAY,EACZ,CAAC,EACD,KAAK,EACL,WAAW,EACX,IAAI,EACJ,UAAU,GACX,CAAC"}
|
package/dist/lib.js
CHANGED
|
@@ -40,6 +40,7 @@ __export(lib_exports, {
|
|
|
40
40
|
R: () => R,
|
|
41
41
|
RegisterKind: () => import_kubernetes_fluent_client5.RegisterKind,
|
|
42
42
|
a: () => import_kubernetes_fluent_client5.kind,
|
|
43
|
+
containers: () => containers,
|
|
43
44
|
fetch: () => import_kubernetes_fluent_client5.fetch,
|
|
44
45
|
fetchStatus: () => import_kubernetes_fluent_client5.fetchStatus,
|
|
45
46
|
kind: () => import_kubernetes_fluent_client5.kind
|
|
@@ -625,7 +626,7 @@ var PeprControllerStore = class {
|
|
|
625
626
|
if (name.includes("schedule")) {
|
|
626
627
|
for (const { name: name2, registerScheduleStore, hasSchedule } of capabilities) {
|
|
627
628
|
if (hasSchedule !== true) {
|
|
628
|
-
|
|
629
|
+
continue;
|
|
629
630
|
}
|
|
630
631
|
const { scheduleStore } = registerScheduleStore();
|
|
631
632
|
scheduleStore.registerSender(this.#send(name2));
|
|
@@ -889,27 +890,32 @@ var Controller = class _Controller {
|
|
|
889
890
|
const responseList = Array.isArray(response) ? response : [response];
|
|
890
891
|
responseList.map((res2) => {
|
|
891
892
|
this.#afterHook && this.#afterHook(res2);
|
|
893
|
+
logger_default.debug({ ...reqMetadata, res: res2 }, "Check response");
|
|
892
894
|
});
|
|
893
|
-
|
|
895
|
+
let kubeAdmissionResponse;
|
|
894
896
|
if (admissionKind === "Mutate") {
|
|
897
|
+
kubeAdmissionResponse = response;
|
|
898
|
+
logger_default.debug({ ...reqMetadata, response }, "Outgoing response");
|
|
895
899
|
res.send({
|
|
896
900
|
apiVersion: "admission.k8s.io/v1",
|
|
897
901
|
kind: "AdmissionReview",
|
|
898
|
-
response
|
|
902
|
+
response: kubeAdmissionResponse
|
|
899
903
|
});
|
|
900
904
|
} else {
|
|
905
|
+
kubeAdmissionResponse = {
|
|
906
|
+
uid: responseList[0].uid,
|
|
907
|
+
allowed: responseList.filter((r) => !r.allowed).length === 0,
|
|
908
|
+
status: {
|
|
909
|
+
message: responseList.filter((rl) => !rl.allowed).map((curr) => curr.status?.message).join("; ")
|
|
910
|
+
}
|
|
911
|
+
};
|
|
901
912
|
res.send({
|
|
902
913
|
apiVersion: "admission.k8s.io/v1",
|
|
903
914
|
kind: "AdmissionReview",
|
|
904
|
-
response:
|
|
905
|
-
uid: responseList[0].uid,
|
|
906
|
-
allowed: responseList.filter((r) => !r.allowed).length === 0,
|
|
907
|
-
status: {
|
|
908
|
-
message: responseList.filter((rl) => !rl.allowed).map((curr) => curr.status?.message).join("; ")
|
|
909
|
-
}
|
|
910
|
-
}
|
|
915
|
+
response: kubeAdmissionResponse
|
|
911
916
|
});
|
|
912
917
|
}
|
|
918
|
+
logger_default.debug({ ...reqMetadata, kubeAdmissionResponse }, "Outgoing response");
|
|
913
919
|
this.#metricsCollector.observeEnd(startTime, admissionKind);
|
|
914
920
|
} catch (err) {
|
|
915
921
|
logger_default.error(err);
|
|
@@ -1484,6 +1490,23 @@ var Capability = class {
|
|
|
1484
1490
|
};
|
|
1485
1491
|
};
|
|
1486
1492
|
};
|
|
1493
|
+
|
|
1494
|
+
// src/lib/module-helpers.ts
|
|
1495
|
+
function containers(request, containerType) {
|
|
1496
|
+
const containers2 = request.Raw.spec?.containers || [];
|
|
1497
|
+
const initContainers = request.Raw.spec?.initContainers || [];
|
|
1498
|
+
const ephemeralContainers = request.Raw.spec?.ephemeralContainers || [];
|
|
1499
|
+
if (containerType === "containers") {
|
|
1500
|
+
return containers2;
|
|
1501
|
+
}
|
|
1502
|
+
if (containerType === "initContainers") {
|
|
1503
|
+
return initContainers;
|
|
1504
|
+
}
|
|
1505
|
+
if (containerType === "ephemeralContainers") {
|
|
1506
|
+
return ephemeralContainers;
|
|
1507
|
+
}
|
|
1508
|
+
return [...containers2, ...initContainers, ...ephemeralContainers];
|
|
1509
|
+
}
|
|
1487
1510
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1488
1511
|
0 && (module.exports = {
|
|
1489
1512
|
Capability,
|
|
@@ -1496,6 +1519,7 @@ var Capability = class {
|
|
|
1496
1519
|
R,
|
|
1497
1520
|
RegisterKind,
|
|
1498
1521
|
a,
|
|
1522
|
+
containers,
|
|
1499
1523
|
fetch,
|
|
1500
1524
|
fetchStatus,
|
|
1501
1525
|
kind
|