pepr 1.0.8 → 1.1.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/build/build.helpers.d.ts +7 -0
- package/dist/cli/build/build.helpers.d.ts.map +1 -1
- package/dist/cli/build/buildModule.d.ts +7 -1
- package/dist/cli/build/buildModule.d.ts.map +1 -1
- package/dist/cli/build/index.d.ts.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +1 -0
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli.js +247 -95
- package/dist/controller.js +111 -1
- package/dist/lib/filter/adjudicators/mismatch.d.ts +1 -1
- package/dist/lib/filter/adjudicators/mismatch.d.ts.map +1 -1
- package/dist/lib/processors/watch-processor.d.ts +1 -0
- package/dist/lib/processors/watch-processor.d.ts.map +1 -1
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +2 -2
- package/package.json +9 -8
- package/src/cli/build/build.helpers.ts +26 -1
- package/src/cli/build/buildModule.ts +52 -12
- package/src/cli/build/index.ts +84 -66
- package/src/cli/deploy/buildAndDeploy.ts +1 -1
- package/src/cli/dev.ts +13 -11
- package/src/lib/processors/watch-processor.ts +2 -0
- package/src/templates/tsconfig.module.json +2 -2
- package/src/templates/package.json +0 -30
|
@@ -9,6 +9,13 @@ import { Reloader } from "../types";
|
|
|
9
9
|
* @returns true if the file exists, false otherwise.
|
|
10
10
|
*/
|
|
11
11
|
export declare function fileExists(entryPoint?: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Determine the module format based on package.json "type" field.
|
|
14
|
+
*
|
|
15
|
+
* @param packageJsonPath - Path to the package.json file for auto-detection
|
|
16
|
+
* @returns "cjs" or "esm"
|
|
17
|
+
*/
|
|
18
|
+
export declare function determineModuleFormat(packageJsonPath: string): "cjs" | "esm";
|
|
12
19
|
interface ImageOptions {
|
|
13
20
|
customImage?: string;
|
|
14
21
|
registryInfo?: string;
|
|
@@ -1 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AO,CAAC,IAAI,CAAC,CAiChB"}
|
|
@@ -7,5 +7,11 @@ export type BuildModuleReturn = {
|
|
|
7
7
|
cfg: PeprConfig;
|
|
8
8
|
uuid: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export interface BuildModuleOptions {
|
|
11
|
+
reloader?: Reloader;
|
|
12
|
+
entryPoint?: string;
|
|
13
|
+
embed?: boolean;
|
|
14
|
+
format?: "cjs" | "esm";
|
|
15
|
+
}
|
|
16
|
+
export declare function buildModule(outputDir: string, options?: BuildModuleOptions): Promise<BuildModuleReturn | void>;
|
|
11
17
|
//# sourceMappingURL=buildModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildModule.d.ts","sourceRoot":"","sources":["../../../src/cli/build/buildModule.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAmB,MAAM,SAAS,CAAC;AAKxD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;
|
|
1
|
+
{"version":3,"file":"buildModule.d.ts","sourceRoot":"","sources":["../../../src/cli/build/buildModule.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAmB,MAAM,SAAS,CAAC;AAKxD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CACxB;AAgCD,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAqFnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/build/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/build/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwFpC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,CAoF/C"}
|
package/dist/cli/dev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,CA+G/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/cli/init/templates.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIrE,eAAO,MAAQ,YAAY;;;;;;;;;;;;;;;;GAAE,eAAe
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/cli/init/templates.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIrE,eAAO,MAAQ,YAAY;;;;;;;;;;;;;;;;GAAE,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAE,gBAAgB;;;;;;;;;;;GAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAE,OAAO,QAAgB,CAAC;AAEjG,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1B,IAAI,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,OAAO,CAAC;YACjB,cAAc,EAAE,MAAM,CAAC;YACvB,YAAY,EAAE,YAAY,CAAC;YAC3B,YAAY,EAAE;gBAAE,UAAU,EAAE,MAA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,7 @@ function helmLayout(basePath, unique) {
|
|
|
8343
8343
|
// src/lib/assets/loader.ts
|
|
8344
8344
|
var import_child_process = require("child_process");
|
|
8345
8345
|
function loadCapabilities(path4) {
|
|
8346
|
-
return new Promise((
|
|
8346
|
+
return new Promise((resolve9, reject) => {
|
|
8347
8347
|
const program2 = (0, import_child_process.fork)(path4, {
|
|
8348
8348
|
env: {
|
|
8349
8349
|
...process.env,
|
|
@@ -8354,7 +8354,7 @@ function loadCapabilities(path4) {
|
|
|
8354
8354
|
});
|
|
8355
8355
|
program2.on("message", (message) => {
|
|
8356
8356
|
const capabilities = message.valueOf();
|
|
8357
|
-
|
|
8357
|
+
resolve9(capabilities);
|
|
8358
8358
|
});
|
|
8359
8359
|
program2.on("error", (error) => {
|
|
8360
8360
|
reject(error);
|
|
@@ -9236,6 +9236,21 @@ function fileExists(entryPoint = "pepr.ts") {
|
|
|
9236
9236
|
}
|
|
9237
9237
|
return entryPoint;
|
|
9238
9238
|
}
|
|
9239
|
+
function determineModuleFormat(packageJsonPath) {
|
|
9240
|
+
try {
|
|
9241
|
+
const pkg = JSON.parse((0, import_fs6.readFileSync)(packageJsonPath, "utf-8"));
|
|
9242
|
+
if (pkg.type === "module") {
|
|
9243
|
+
return "esm";
|
|
9244
|
+
}
|
|
9245
|
+
if (pkg.type !== "commonjs") {
|
|
9246
|
+
logger_default.warn(
|
|
9247
|
+
`No 'type' field specified in package.json. Defaulting to CommonJS format. To use ES modules, add '"type": "module"' to your tsconfig.json or package.json.`
|
|
9248
|
+
);
|
|
9249
|
+
}
|
|
9250
|
+
} catch {
|
|
9251
|
+
}
|
|
9252
|
+
return "cjs";
|
|
9253
|
+
}
|
|
9239
9254
|
function assignImage(imageOptions) {
|
|
9240
9255
|
const { customImage, registryInfo, peprVersion, registry } = imageOptions;
|
|
9241
9256
|
if (customImage) {
|
|
@@ -9567,8 +9582,8 @@ var tsconfig_module_default = {
|
|
|
9567
9582
|
emitDeclarationOnly: true,
|
|
9568
9583
|
esModuleInterop: true,
|
|
9569
9584
|
lib: ["ES2022"],
|
|
9570
|
-
module: "
|
|
9571
|
-
moduleResolution: "
|
|
9585
|
+
module: "es2022",
|
|
9586
|
+
moduleResolution: "bundler",
|
|
9572
9587
|
outDir: "dist",
|
|
9573
9588
|
resolveJsonModule: true,
|
|
9574
9589
|
rootDir: ".",
|
|
@@ -9584,7 +9599,117 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
9584
9599
|
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```text\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';
|
|
9585
9600
|
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';
|
|
9586
9601
|
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\nimport { MockAgent, setGlobalDispatcher } from "undici";\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.SetLabel("pepr", "was-here").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>): void {\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).IsCreated().InNamespace("pepr-demo-2").WithName("example-4a").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://icanhazdadjoke.com/");\n * const joke = await fetch("https://icanhazdadjoke.com/") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://icanhazdadjoke.com")\n * ```\n */\ninterface TheChuckNorrisJoke {\n id: string;\n joke: string;\n status: number;\n}\n\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("chuck-norris")\n .Mutate(cm => cm.SetLabel("got-jokes", "true"))\n .Watch(async cm => {\n const jokeURL = "https://icanhazdadjoke.com";\n\n const mockAgent: MockAgent = new MockAgent();\n setGlobalDispatcher(mockAgent);\n const mockClient = mockAgent.get(jokeURL);\n mockClient.intercept({ path: "/", method: "GET" }).reply(\n 200,\n {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\n },\n {\n headers: {\n "Content-Type": "application/json; charset=utf-8",\n },\n },\n );\n\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(jokeURL, {\n headers: {\n Accept: "application/json",\n },\n });\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n const { joke } = response.data;\n // Add Joke to the Store\n await Store.setItemAndWait(jokeURL, joke);\n // Add the Chuck Norris joke to the configmap\n try {\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: cm.metadata.name,\n namespace: cm.metadata.namespace,\n },\n data: {\n "chuck-says": Store.getItem(jokeURL),\n },\n });\n } catch (error) {\n Log.error({ error, cm }, "Failed to apply ConfigMap using server-side apply.");\n }\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';
|
|
9587
|
-
var packageJSON = {
|
|
9602
|
+
var packageJSON = {
|
|
9603
|
+
name: "pepr",
|
|
9604
|
+
description: "Kubernetes application engine",
|
|
9605
|
+
author: "Defense Unicorns",
|
|
9606
|
+
homepage: "https://github.com/defenseunicorns/pepr",
|
|
9607
|
+
license: "Apache-2.0",
|
|
9608
|
+
bin: "dist/cli.js",
|
|
9609
|
+
repository: "defenseunicorns/pepr",
|
|
9610
|
+
engines: {
|
|
9611
|
+
node: ">=20.0.0"
|
|
9612
|
+
},
|
|
9613
|
+
files: [
|
|
9614
|
+
"/dist",
|
|
9615
|
+
"/src",
|
|
9616
|
+
"!src/**/*.test.ts",
|
|
9617
|
+
"!src/fixtures/**",
|
|
9618
|
+
"!dist/**/*.test.d.ts*"
|
|
9619
|
+
],
|
|
9620
|
+
version: "1.1.0",
|
|
9621
|
+
main: "dist/lib.js",
|
|
9622
|
+
types: "dist/lib.d.ts",
|
|
9623
|
+
scripts: {
|
|
9624
|
+
build: "tsc -p config/tsconfig.root.json && node build.mjs && npm pack",
|
|
9625
|
+
"build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .",
|
|
9626
|
+
"build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr/private:dev $(node scripts/read-unicorn-build-args.mjs) .",
|
|
9627
|
+
ci: "npm ci",
|
|
9628
|
+
"cluster:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system",
|
|
9629
|
+
"cluster:k3d:import-upstream": "npm run build && docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev",
|
|
9630
|
+
"cluster:k3d:import-unicorn": "npm run build && docker buildx build --output type=docker --tag pepr/private:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr/private:dev -c pepr-dev",
|
|
9631
|
+
"format:check": "npm run format:src && npm run format:tests && npm run format:markdown && npm run format:integration && npm run format:prettier -- --check",
|
|
9632
|
+
"format:fix": "npm run format:src -- --fix && npm run format:markdown -- --fix && npm run format:integration -- --fix && npm run format:prettier -- --write",
|
|
9633
|
+
"format:integration": "eslint --config config/eslint.integration.config.mjs integration/cli integration/helpers",
|
|
9634
|
+
"format:markdown": 'npx -y markdownlint-cli --config config/.markdownlint.json --ignore adr --ignore integration/testroot --ignore pepr-test-module --ignore node_modules --rules config/markdownlint-step-format-rule.js "**/*.md"',
|
|
9635
|
+
"format:prettier": "prettier --config config/.prettierrc src integration/cli/**/*.ts integration/helpers/**/*.ts",
|
|
9636
|
+
"format:src": "eslint --config config/eslint.root.config.mjs 'src/**/*.ts' --ignore-pattern '**/*.test.ts' --ignore-pattern 'src/templates/**'",
|
|
9637
|
+
"format:tests": "eslint --config config/eslint.test.config.mjs 'src/**/*.test.ts'",
|
|
9638
|
+
"gen-data-json": "node hack/build-template-data.mjs",
|
|
9639
|
+
prebuild: "rm -fr dist/* && npm run gen-data-json",
|
|
9640
|
+
prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi`,
|
|
9641
|
+
"set-version": 'bash -lc \'ver=${PEPR_VERSION:-}; if [ -z "$ver" ]; then git fetch --tags --force; ver=$(git describe --tags --abbrev=0); fi; ver=${ver#v}; echo Using version $ver; node ./scripts/set-version.js "$ver"\'',
|
|
9642
|
+
test: "npm run test:unit && npm run test:integration",
|
|
9643
|
+
"test:artifacts": "npm run build && vitest run src/build-artifact.test.ts",
|
|
9644
|
+
"test:docs": "vitest run --config=config/vitest.integration.config.ts integration/cli/docs/*.test.ts",
|
|
9645
|
+
"test:integration": "npm run test:integration:prep && npm run test:integration:run",
|
|
9646
|
+
"test:integration:prep": "./integration/prep.sh",
|
|
9647
|
+
"test:integration:run": "vitest run --config=config/vitest.integration.config.ts integration",
|
|
9648
|
+
"test:unit": "npm run gen-data-json && NODE_OPTIONS=--no-deprecation vitest --config config/vitest.root.config.ts run --coverage",
|
|
9649
|
+
"test:upgrade:unicorn": "npm run cluster:k3d && npm run cluster:k3d:import-unicorn && vitest run integration/cluster/upgrade.test.ts",
|
|
9650
|
+
"test:upgrade:upstream": "npm run cluster:k3d && npm run cluster:k3d:import-upstream && vitest run integration/cluster/upgrade.test.ts"
|
|
9651
|
+
},
|
|
9652
|
+
dependencies: {
|
|
9653
|
+
"@types/ramda": "0.31.1",
|
|
9654
|
+
"command-line-args": "^6.0.1",
|
|
9655
|
+
commander: "14.0.3",
|
|
9656
|
+
express: "5.2.1",
|
|
9657
|
+
"fast-json-patch": "3.1.1",
|
|
9658
|
+
heredoc: "^1.3.1",
|
|
9659
|
+
"http-status-codes": "^2.3.0",
|
|
9660
|
+
"json-pointer": "^0.6.2",
|
|
9661
|
+
"kubernetes-fluent-client": "3.11.2",
|
|
9662
|
+
pino: "10.3.1",
|
|
9663
|
+
"pino-pretty": "13.1.3",
|
|
9664
|
+
"prom-client": "15.1.3",
|
|
9665
|
+
"quicktype-core": "^23.2.6",
|
|
9666
|
+
ramda: "0.32.0",
|
|
9667
|
+
"ts-morph": "^27.0.0"
|
|
9668
|
+
},
|
|
9669
|
+
devDependencies: {
|
|
9670
|
+
"@commitlint/cli": "20.4.1",
|
|
9671
|
+
"@commitlint/config-conventional": "20.4.1",
|
|
9672
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
9673
|
+
"@semantic-release/git": "^10.0.1",
|
|
9674
|
+
"@semantic-release/npm": "^13.0.0",
|
|
9675
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
9676
|
+
"@types/command-line-args": "^5.2.3",
|
|
9677
|
+
"@types/eslint": "9.6.1",
|
|
9678
|
+
"@types/express": "5.0.6",
|
|
9679
|
+
"@types/json-pointer": "^1.0.34",
|
|
9680
|
+
"@types/json-schema": "^7.0.15",
|
|
9681
|
+
"@types/node": "25.x.x",
|
|
9682
|
+
"@types/node-forge": "1.3.14",
|
|
9683
|
+
"@types/readable-stream": "^4.0.21",
|
|
9684
|
+
"@types/urijs": "^1.19.25",
|
|
9685
|
+
"@types/ws": "^8.18.1",
|
|
9686
|
+
"@vitest/coverage-v8": "^4.0.4",
|
|
9687
|
+
"fast-check": "^4.0.0",
|
|
9688
|
+
globals: "^17.0.0",
|
|
9689
|
+
husky: "^9.1.6",
|
|
9690
|
+
"js-yaml": "^4.1.0",
|
|
9691
|
+
selfsigned: "^5.5.0",
|
|
9692
|
+
shellcheck: "^4.1.0",
|
|
9693
|
+
tsx: "^4.20.3",
|
|
9694
|
+
undici: "7.21.0",
|
|
9695
|
+
vitest: "^4.0.4"
|
|
9696
|
+
},
|
|
9697
|
+
overrides: {
|
|
9698
|
+
glob: "^9.0.0"
|
|
9699
|
+
},
|
|
9700
|
+
peerDependencies: {
|
|
9701
|
+
"@types/prompts": "2.4.9",
|
|
9702
|
+
"@typescript-eslint/eslint-plugin": "8.45.0",
|
|
9703
|
+
"@typescript-eslint/parser": "8.45.0",
|
|
9704
|
+
esbuild: "0.25.10",
|
|
9705
|
+
eslint: "9.36.0",
|
|
9706
|
+
"node-forge": "1.3.2",
|
|
9707
|
+
prettier: "3.6.2",
|
|
9708
|
+
prompts: "2.4.2",
|
|
9709
|
+
typescript: "5.8.3",
|
|
9710
|
+
uuid: "13.0.0"
|
|
9711
|
+
}
|
|
9712
|
+
};
|
|
9588
9713
|
|
|
9589
9714
|
// src/cli/init/utils.ts
|
|
9590
9715
|
var import_fs7 = require("fs");
|
|
@@ -9828,18 +9953,38 @@ async function loadModule(outputDir, entryPoint) {
|
|
|
9828
9953
|
var externalLibs = Object.keys(dependencies);
|
|
9829
9954
|
externalLibs.push("pepr");
|
|
9830
9955
|
externalLibs.push("@kubernetes/client-node");
|
|
9831
|
-
|
|
9956
|
+
function resolveFormatAndPath(embed, requestedFormat, loadedPath) {
|
|
9957
|
+
if (embed) {
|
|
9958
|
+
return {
|
|
9959
|
+
format: "cjs",
|
|
9960
|
+
path: requestedFormat === "esm" ? loadedPath.replace(/\.js$/, ".cjs") : loadedPath
|
|
9961
|
+
};
|
|
9962
|
+
}
|
|
9963
|
+
return { format: requestedFormat, path: loadedPath };
|
|
9964
|
+
}
|
|
9965
|
+
async function buildModule(outputDir, options = {}) {
|
|
9966
|
+
const {
|
|
9967
|
+
reloader,
|
|
9968
|
+
entryPoint = "pepr.ts",
|
|
9969
|
+
embed = true,
|
|
9970
|
+
format: requestedFormat = "cjs"
|
|
9971
|
+
} = options;
|
|
9832
9972
|
try {
|
|
9833
|
-
const { cfg, modulePath, path:
|
|
9973
|
+
const { cfg, modulePath, path: loadedPath, uuid } = await loadModule(outputDir, entryPoint);
|
|
9974
|
+
const { format: format2, path: path4 } = resolveFormatAndPath(embed, requestedFormat, loadedPath);
|
|
9834
9975
|
await checkFormat();
|
|
9835
9976
|
const npmRoot = (0, import_child_process3.execFileSync)("npm", ["root"]).toString().trim();
|
|
9836
|
-
|
|
9837
|
-
|
|
9977
|
+
(0, import_child_process3.execFileSync)(`${npmRoot}/.bin/tsc`, [
|
|
9978
|
+
"--project",
|
|
9979
|
+
`${modulePath}/tsconfig.json`,
|
|
9980
|
+
"--outdir",
|
|
9981
|
+
outputDir
|
|
9982
|
+
]);
|
|
9838
9983
|
const ctxCfg = {
|
|
9839
9984
|
bundle: true,
|
|
9840
9985
|
entryPoints: [entryPoint],
|
|
9841
9986
|
external: externalLibs,
|
|
9842
|
-
format:
|
|
9987
|
+
format: format2,
|
|
9843
9988
|
keepNames: true,
|
|
9844
9989
|
legalComments: "external",
|
|
9845
9990
|
metafile: true,
|
|
@@ -9869,7 +10014,8 @@ async function buildModule(outputDir, reloader, entryPoint = "pepr.ts", embed =
|
|
|
9869
10014
|
}
|
|
9870
10015
|
if (!embed) {
|
|
9871
10016
|
ctxCfg.minify = false;
|
|
9872
|
-
|
|
10017
|
+
const outputExtension = format2 === "esm" ? ".mjs" : ".js";
|
|
10018
|
+
ctxCfg.outfile = (0, import_path4.resolve)(outputDir, (0, import_path4.basename)(entryPoint, (0, import_path4.extname)(entryPoint))) + outputExtension;
|
|
9873
10019
|
ctxCfg.packages = "external";
|
|
9874
10020
|
ctxCfg.treeShaking = false;
|
|
9875
10021
|
}
|
|
@@ -9919,6 +10065,52 @@ async function checkFormat() {
|
|
|
9919
10065
|
}
|
|
9920
10066
|
|
|
9921
10067
|
// src/cli/build/index.ts
|
|
10068
|
+
var import_path5 = require("path");
|
|
10069
|
+
async function generateDeploymentAssets(buildResult, opts, outputDir) {
|
|
10070
|
+
const { cfg, path: path4 } = buildResult;
|
|
10071
|
+
const image = assignImage({
|
|
10072
|
+
customImage: opts.customImage,
|
|
10073
|
+
registryInfo: opts.registryInfo,
|
|
10074
|
+
peprVersion: cfg.pepr.peprVersion,
|
|
10075
|
+
registry: opts.registry
|
|
10076
|
+
});
|
|
10077
|
+
if (opts.timeout !== void 0) {
|
|
10078
|
+
cfg.pepr.webhookTimeout = opts.timeout;
|
|
10079
|
+
}
|
|
10080
|
+
if (opts.registryInfo !== void 0) {
|
|
10081
|
+
logger_default.info(`Including ${cfg.pepr.includedFiles.length} files in controller image.`);
|
|
10082
|
+
await handleCustomImageBuild(
|
|
10083
|
+
cfg.pepr.includedFiles,
|
|
10084
|
+
cfg.pepr.peprVersion,
|
|
10085
|
+
cfg.description,
|
|
10086
|
+
image
|
|
10087
|
+
);
|
|
10088
|
+
}
|
|
10089
|
+
const assets = new Assets(
|
|
10090
|
+
{
|
|
10091
|
+
...cfg.pepr,
|
|
10092
|
+
appVersion: cfg.version,
|
|
10093
|
+
description: cfg.description,
|
|
10094
|
+
alwaysIgnore: { namespaces: cfg.pepr.alwaysIgnore?.namespaces },
|
|
10095
|
+
rbacMode: determineRbacMode(opts, cfg)
|
|
10096
|
+
},
|
|
10097
|
+
path4,
|
|
10098
|
+
opts.withPullSecret === "" ? [] : [opts.withPullSecret]
|
|
10099
|
+
);
|
|
10100
|
+
if (image !== "") assets.image = image;
|
|
10101
|
+
if (!validImagePullSecret(opts.withPullSecret)) {
|
|
10102
|
+
throw new Error("Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123.");
|
|
10103
|
+
}
|
|
10104
|
+
handleValidCapabilityNames(assets.capabilities);
|
|
10105
|
+
await generateYamlAndWriteToDisk({
|
|
10106
|
+
uuid: cfg.pepr.uuid,
|
|
10107
|
+
outputDir,
|
|
10108
|
+
imagePullSecret: opts.withPullSecret,
|
|
10109
|
+
zarf: opts.zarf,
|
|
10110
|
+
assets
|
|
10111
|
+
});
|
|
10112
|
+
return assets;
|
|
10113
|
+
}
|
|
9922
10114
|
function build_default(program2) {
|
|
9923
10115
|
program2.command("build").description("Build a Pepr Module for deployment").addOption(
|
|
9924
10116
|
new import_commander.Option("-M, --rbac-mode <mode>", "Override module config and set RBAC mode.").choices([
|
|
@@ -9960,66 +10152,24 @@ function build_default(program2) {
|
|
|
9960
10152
|
new import_commander.Option("-z, --zarf <manifest|chart>", "Set Zarf package type").choices(["manifest", "chart"]).default("manifest")
|
|
9961
10153
|
).action(async (opts) => {
|
|
9962
10154
|
const outputDir = await createOutputDirectory(opts.output);
|
|
9963
|
-
const
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
opts.
|
|
9967
|
-
|
|
9968
|
-
);
|
|
9969
|
-
|
|
10155
|
+
const format2 = determineModuleFormat((0, import_path5.resolve)(process.cwd(), "package.json"));
|
|
10156
|
+
const buildModuleResult = await buildModule(outputDir, {
|
|
10157
|
+
entryPoint: opts.entryPoint,
|
|
10158
|
+
embed: opts.embed,
|
|
10159
|
+
format: format2
|
|
10160
|
+
});
|
|
10161
|
+
if (!buildModuleResult) {
|
|
10162
|
+
return;
|
|
10163
|
+
}
|
|
10164
|
+
const { path: path4 } = buildModuleResult;
|
|
9970
10165
|
if (opts.customName) {
|
|
9971
10166
|
process.env.PEPR_CUSTOM_BUILD_NAME = opts.customName;
|
|
9972
10167
|
}
|
|
9973
|
-
const image = assignImage({
|
|
9974
|
-
customImage: opts.customImage,
|
|
9975
|
-
registryInfo: opts.registryInfo,
|
|
9976
|
-
peprVersion: cfg.pepr.peprVersion,
|
|
9977
|
-
registry: opts.registry
|
|
9978
|
-
});
|
|
9979
|
-
if (opts.timeout !== void 0) {
|
|
9980
|
-
cfg.pepr.webhookTimeout = opts.timeout;
|
|
9981
|
-
}
|
|
9982
|
-
if (opts.registryInfo !== void 0) {
|
|
9983
|
-
logger_default.info(`Including ${cfg.pepr.includedFiles.length} files in controller image.`);
|
|
9984
|
-
await handleCustomImageBuild(
|
|
9985
|
-
cfg.pepr.includedFiles,
|
|
9986
|
-
cfg.pepr.peprVersion,
|
|
9987
|
-
cfg.description,
|
|
9988
|
-
image
|
|
9989
|
-
);
|
|
9990
|
-
}
|
|
9991
10168
|
if (!opts.embed) {
|
|
9992
10169
|
logger_default.info(`Module built successfully at ${path4}`);
|
|
9993
10170
|
return;
|
|
9994
10171
|
}
|
|
9995
|
-
|
|
9996
|
-
{
|
|
9997
|
-
...cfg.pepr,
|
|
9998
|
-
appVersion: cfg.version,
|
|
9999
|
-
description: cfg.description,
|
|
10000
|
-
alwaysIgnore: {
|
|
10001
|
-
namespaces: cfg.pepr.alwaysIgnore?.namespaces
|
|
10002
|
-
},
|
|
10003
|
-
// Can override the rbacMode with the CLI option
|
|
10004
|
-
rbacMode: determineRbacMode(opts, cfg)
|
|
10005
|
-
},
|
|
10006
|
-
path4,
|
|
10007
|
-
opts.withPullSecret === "" ? [] : [opts.withPullSecret]
|
|
10008
|
-
);
|
|
10009
|
-
if (image !== "") assets.image = image;
|
|
10010
|
-
if (!validImagePullSecret(opts.withPullSecret)) {
|
|
10011
|
-
throw new Error(
|
|
10012
|
-
"Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123."
|
|
10013
|
-
);
|
|
10014
|
-
}
|
|
10015
|
-
handleValidCapabilityNames(assets.capabilities);
|
|
10016
|
-
await generateYamlAndWriteToDisk({
|
|
10017
|
-
uuid: cfg.pepr.uuid,
|
|
10018
|
-
outputDir,
|
|
10019
|
-
imagePullSecret: opts.withPullSecret,
|
|
10020
|
-
zarf: opts.zarf,
|
|
10021
|
-
assets
|
|
10022
|
-
});
|
|
10172
|
+
await generateDeploymentAssets(buildModuleResult, opts, outputDir);
|
|
10023
10173
|
});
|
|
10024
10174
|
}
|
|
10025
10175
|
|
|
@@ -10288,14 +10438,14 @@ async function namespaceDeploymentsReady(namespace = "pepr-system") {
|
|
|
10288
10438
|
if (ready) {
|
|
10289
10439
|
return ready;
|
|
10290
10440
|
}
|
|
10291
|
-
await new Promise((
|
|
10441
|
+
await new Promise((resolve9) => setTimeout(resolve9, 1e3));
|
|
10292
10442
|
}
|
|
10293
10443
|
logger_default.info(`All ${namespace} deployments are ready`);
|
|
10294
10444
|
}
|
|
10295
10445
|
|
|
10296
10446
|
// src/cli/deploy/buildAndDeploy.ts
|
|
10297
10447
|
async function buildAndDeployModule(image, force) {
|
|
10298
|
-
const builtModule = await buildModule("dist");
|
|
10448
|
+
const builtModule = await buildModule("dist", {});
|
|
10299
10449
|
if (!builtModule) {
|
|
10300
10450
|
return;
|
|
10301
10451
|
}
|
|
@@ -10419,16 +10569,18 @@ ${error}`
|
|
|
10419
10569
|
logger_default.debug(`Received SIGINT, removing webhooks`);
|
|
10420
10570
|
});
|
|
10421
10571
|
};
|
|
10422
|
-
await buildModule("dist",
|
|
10423
|
-
|
|
10424
|
-
|
|
10425
|
-
|
|
10426
|
-
|
|
10427
|
-
|
|
10428
|
-
program3
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
|
|
10572
|
+
await buildModule("dist", {
|
|
10573
|
+
reloader: async (r) => {
|
|
10574
|
+
if (r.errors.length > 0) {
|
|
10575
|
+
logger_default.error(`Error compiling module: ${r.errors}`);
|
|
10576
|
+
return;
|
|
10577
|
+
}
|
|
10578
|
+
if (program3) {
|
|
10579
|
+
program3.once("exit", runFork);
|
|
10580
|
+
program3.kill("SIGKILL");
|
|
10581
|
+
} else {
|
|
10582
|
+
await runFork();
|
|
10583
|
+
}
|
|
10432
10584
|
}
|
|
10433
10585
|
});
|
|
10434
10586
|
} catch (e) {
|
|
@@ -10677,11 +10829,11 @@ ${packageJSON2.print.replace(/^/gm, " \u2502 ")}
|
|
|
10677
10829
|
var import_commander3 = require("commander");
|
|
10678
10830
|
|
|
10679
10831
|
// src/cli/init/setupProjectStructure.ts
|
|
10680
|
-
var
|
|
10832
|
+
var import_path6 = require("path");
|
|
10681
10833
|
async function setupProjectStructure(dirName) {
|
|
10682
10834
|
await createDir(dirName);
|
|
10683
|
-
await createDir((0,
|
|
10684
|
-
await createDir((0,
|
|
10835
|
+
await createDir((0, import_path6.resolve)(dirName, ".vscode"));
|
|
10836
|
+
await createDir((0, import_path6.resolve)(dirName, "capabilities"));
|
|
10685
10837
|
}
|
|
10686
10838
|
|
|
10687
10839
|
// src/cli/init/doPostInitActions.ts
|
|
@@ -10825,7 +10977,7 @@ var import_commander7 = require("commander");
|
|
|
10825
10977
|
// src/cli/update/index.ts
|
|
10826
10978
|
var import_child_process6 = require("child_process");
|
|
10827
10979
|
var import_fs13 = __toESM(require("fs"));
|
|
10828
|
-
var
|
|
10980
|
+
var import_path7 = require("path");
|
|
10829
10981
|
var import_prompts4 = __toESM(require("prompts"));
|
|
10830
10982
|
function update_default(program2) {
|
|
10831
10983
|
program2.command("update").description("Update this Pepr module. Not recommended for prod as it may change files.").option("-s, --skip-template-update", "Do not update template files").option("-y, --yes", "Skip confirmation prompt").action(async (opts) => {
|
|
@@ -10859,16 +11011,16 @@ function update_default(program2) {
|
|
|
10859
11011
|
logger_default.info("Updating Pepr config and template files...");
|
|
10860
11012
|
try {
|
|
10861
11013
|
if (!opts.skipTemplateUpdate) {
|
|
10862
|
-
await write((0,
|
|
10863
|
-
await write((0,
|
|
10864
|
-
await write((0,
|
|
10865
|
-
await write((0,
|
|
10866
|
-
const samplePath = (0,
|
|
11014
|
+
await write((0, import_path7.resolve)(prettier.path), prettier.data);
|
|
11015
|
+
await write((0, import_path7.resolve)(tsConfig.path), tsConfig.data);
|
|
11016
|
+
await write((0, import_path7.resolve)(".vscode", snippet.path), snippet.data);
|
|
11017
|
+
await write((0, import_path7.resolve)(".vscode", codeSettings.path), codeSettings.data);
|
|
11018
|
+
const samplePath = (0, import_path7.resolve)("capabilities", samplesYaml.path);
|
|
10867
11019
|
if (import_fs13.default.existsSync(samplePath)) {
|
|
10868
11020
|
import_fs13.default.unlinkSync(samplePath);
|
|
10869
11021
|
await write(samplePath, samplesYaml.data);
|
|
10870
11022
|
}
|
|
10871
|
-
const tsPath = (0,
|
|
11023
|
+
const tsPath = (0, import_path7.resolve)("capabilities", helloPepr.path);
|
|
10872
11024
|
if (import_fs13.default.existsSync(tsPath)) {
|
|
10873
11025
|
await write(tsPath, helloPepr.data);
|
|
10874
11026
|
}
|
|
@@ -10918,7 +11070,7 @@ var import_commander4 = require("commander");
|
|
|
10918
11070
|
|
|
10919
11071
|
// src/cli/crd/generate/generators.ts
|
|
10920
11072
|
var import_fs14 = __toESM(require("fs"));
|
|
10921
|
-
var
|
|
11073
|
+
var import_path8 = __toESM(require("path"));
|
|
10922
11074
|
var import_yaml = __toESM(require_dist());
|
|
10923
11075
|
var import_ts_morph = require("ts-morph");
|
|
10924
11076
|
|
|
@@ -10947,24 +11099,24 @@ function extractCRDDetails(content, sourceFile) {
|
|
|
10947
11099
|
}
|
|
10948
11100
|
async function generateCRDs(options) {
|
|
10949
11101
|
logger_default.warn("This feature is currently in alpha.\n");
|
|
10950
|
-
const outputDir =
|
|
11102
|
+
const outputDir = import_path8.default.resolve(options.output);
|
|
10951
11103
|
await createDirectoryIfNotExists(outputDir);
|
|
10952
11104
|
const project = new import_ts_morph.Project();
|
|
10953
|
-
const apiRoot =
|
|
11105
|
+
const apiRoot = import_path8.default.resolve("api");
|
|
10954
11106
|
const versions = getAPIVersions(apiRoot);
|
|
10955
11107
|
for (const version3 of versions) {
|
|
10956
|
-
const sourceFiles = loadVersionFiles(project,
|
|
11108
|
+
const sourceFiles = loadVersionFiles(project, import_path8.default.join(apiRoot, version3));
|
|
10957
11109
|
for (const sourceFile of sourceFiles) {
|
|
10958
11110
|
processSourceFile(sourceFile, version3, outputDir);
|
|
10959
11111
|
}
|
|
10960
11112
|
}
|
|
10961
11113
|
}
|
|
10962
11114
|
function getAPIVersions(apiRoot) {
|
|
10963
|
-
return import_fs14.default.readdirSync(apiRoot).filter((v) => import_fs14.default.statSync(
|
|
11115
|
+
return import_fs14.default.readdirSync(apiRoot).filter((v) => import_fs14.default.statSync(import_path8.default.join(apiRoot, v)).isDirectory());
|
|
10964
11116
|
}
|
|
10965
11117
|
function loadVersionFiles(project, versionDir) {
|
|
10966
11118
|
const files = import_fs14.default.readdirSync(versionDir).filter((f) => f.endsWith(".ts"));
|
|
10967
|
-
const filePaths = files.map((f) =>
|
|
11119
|
+
const filePaths = files.map((f) => import_path8.default.join(versionDir, f));
|
|
10968
11120
|
return project.addSourceFilesAtPaths(filePaths);
|
|
10969
11121
|
}
|
|
10970
11122
|
function processSourceFile(sourceFile, version3, outputDir) {
|
|
@@ -10992,7 +11144,7 @@ function processSourceFile(sourceFile, version3, outputDir) {
|
|
|
10992
11144
|
specSchema,
|
|
10993
11145
|
conditionSchema
|
|
10994
11146
|
});
|
|
10995
|
-
const outPath =
|
|
11147
|
+
const outPath = import_path8.default.join(outputDir, `${kind8.toLowerCase()}.yaml`);
|
|
10996
11148
|
import_fs14.default.writeFileSync(outPath, (0, import_yaml.stringify)(crd), "utf8");
|
|
10997
11149
|
logger_default.info(`\u2714 Created ${outPath}`);
|
|
10998
11150
|
}
|
|
@@ -11241,7 +11393,7 @@ type ${kind8}StatusCondition = {
|
|
|
11241
11393
|
};
|
|
11242
11394
|
|
|
11243
11395
|
// src/cli/crd/create/index.ts
|
|
11244
|
-
var
|
|
11396
|
+
var import_path9 = __toESM(require("path"));
|
|
11245
11397
|
function create_default() {
|
|
11246
11398
|
return new import_commander5.Command("create").description("Create a new CRD TypeScript definition").addOption(
|
|
11247
11399
|
new import_commander5.Option(
|
|
@@ -11250,7 +11402,7 @@ function create_default() {
|
|
|
11250
11402
|
).choices(["Namespaced", "Cluster"]).default("Namespaced")
|
|
11251
11403
|
).option("-d, --domain <domain>", "Optional domain for CRD (e.g. pepr.dev)", "pepr.dev").requiredOption("-g, --group <group>", "API group (e.g. cache)").requiredOption("-k, --kind <kind>", "Kind name (e.g. memcached)").option("-p, --plural <plural>", "Plural name for CRD (e.g. memcacheds)").requiredOption("-s, --short-name <name>", "Short name for CRD (e.g. mc)").requiredOption("-v, --version <version>", "API version (e.g. v1alpha1)").action(async ({ group: group2, version: version3, kind: kind8, domain, scope, plural: plural2, shortName }) => {
|
|
11252
11404
|
logger_default.warn("This feature is currently in alpha.");
|
|
11253
|
-
const outputDir =
|
|
11405
|
+
const outputDir = import_path9.default.resolve(`./api/${version3}`);
|
|
11254
11406
|
await createDirectoryIfNotExists(outputDir);
|
|
11255
11407
|
await import_fs15.promises.writeFile(
|
|
11256
11408
|
`./api/${version3}/${kind8.toLowerCase()}_types.ts`,
|