pepr 0.50.0-nightly.1 → 0.50.0-nightly.10

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.
@@ -1,3 +1,5 @@
1
+ import { CapabilityExport } from "../lib/types";
2
+ import { Assets } from "../lib/assets/assets";
1
3
  import { RootCmd } from "./root";
2
4
  export interface ImagePullSecretDetails {
3
5
  pullSecret?: string;
@@ -15,4 +17,5 @@ export declare function getUserConfirmation(opts: {
15
17
  confirm: boolean;
16
18
  }): Promise<boolean>;
17
19
  export default function (program: RootCmd): void;
20
+ export declare function validateNamespaces(capability: CapabilityExport, webhook: Assets): void;
18
21
  //# sourceMappingURL=deploy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAQjC,MAAM,WAAW,sBAAsB;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,GAAG;IAC/E,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAmCA;AAED,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC,sBAAsB,CAAC,CAAC;AAkB/E,wBAAsB,mBAAmB,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAatF;AAwCD,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,CA8B/C"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAQjC,MAAM,WAAW,sBAAsB;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,GAAG;IAC/E,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAmCA;AAED,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC,sBAAsB,CAAC,CAAC;AAkB/E,wBAAsB,mBAAmB,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAatF;AAkCD,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,CA8B/C;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAQtF"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/update/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,CAsG/C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/update/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,OAAO,GAAG,IAAI,CA2E/C"}
package/dist/cli.js CHANGED
@@ -450,8 +450,7 @@ var require_anchors = __commonJS({
450
450
  return {
451
451
  onAnchor: (source) => {
452
452
  aliasObjects.push(source);
453
- if (!prevAnchors)
454
- prevAnchors = anchorNames(doc);
453
+ prevAnchors ?? (prevAnchors = anchorNames(doc));
455
454
  const anchor = findNewAnchor(prefix, prevAnchors);
456
455
  prevAnchors.add(anchor);
457
456
  return anchor;
@@ -627,23 +626,35 @@ var require_Alias = __commonJS({
627
626
  * Resolve the value of this alias within `doc`, finding the last
628
627
  * instance of the `source` anchor before this node.
629
628
  */
630
- resolve(doc) {
629
+ resolve(doc, ctx) {
630
+ let nodes;
631
+ if (ctx?.aliasResolveCache) {
632
+ nodes = ctx.aliasResolveCache;
633
+ } else {
634
+ nodes = [];
635
+ visit.visit(doc, {
636
+ Node: (_key, node) => {
637
+ if (identity.isAlias(node) || identity.hasAnchor(node))
638
+ nodes.push(node);
639
+ }
640
+ });
641
+ if (ctx)
642
+ ctx.aliasResolveCache = nodes;
643
+ }
631
644
  let found = void 0;
632
- visit.visit(doc, {
633
- Node: (_key, node) => {
634
- if (node === this)
635
- return visit.visit.BREAK;
636
- if (node.anchor === this.source)
637
- found = node;
638
- }
639
- });
645
+ for (const node of nodes) {
646
+ if (node === this)
647
+ break;
648
+ if (node.anchor === this.source)
649
+ found = node;
650
+ }
640
651
  return found;
641
652
  }
642
653
  toJSON(_arg, ctx) {
643
654
  if (!ctx)
644
655
  return { source: this.source };
645
656
  const { anchors: anchors2, doc, maxAliasCount } = ctx;
646
- const source = this.resolve(doc);
657
+ const source = this.resolve(doc, ctx);
647
658
  if (!source) {
648
659
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
649
660
  throw new ReferenceError(msg);
@@ -772,8 +783,7 @@ var require_createNode = __commonJS({
772
783
  if (aliasDuplicateObjects && value && typeof value === "object") {
773
784
  ref = sourceObjects.get(value);
774
785
  if (ref) {
775
- if (!ref.anchor)
776
- ref.anchor = onAnchor(value);
786
+ ref.anchor ?? (ref.anchor = onAnchor(value));
777
787
  return new Alias.Alias(ref.anchor);
778
788
  } else {
779
789
  ref = { anchor: null, node: null };
@@ -1330,7 +1340,7 @@ ${indent}${start}${value}${end}`;
1330
1340
  if (implicitKey && value.includes("\n") || inFlow && /[[\]{},]/.test(value)) {
1331
1341
  return quotedString(value, ctx);
1332
1342
  }
1333
- if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
1343
+ if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
1334
1344
  return implicitKey || inFlow || !value.includes("\n") ? quotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
1335
1345
  }
1336
1346
  if (!implicitKey && !inFlow && type !== Scalar.Scalar.PLAIN && value.includes("\n")) {
@@ -1462,7 +1472,7 @@ var require_stringify = __commonJS({
1462
1472
  tagObj = tags.find((t) => t.nodeClass && obj instanceof t.nodeClass);
1463
1473
  }
1464
1474
  if (!tagObj) {
1465
- const name2 = obj?.constructor?.name ?? typeof obj;
1475
+ const name2 = obj?.constructor?.name ?? (obj === null ? "null" : typeof obj);
1466
1476
  throw new Error(`Tag not resolved for ${name2} value`);
1467
1477
  }
1468
1478
  return tagObj;
@@ -1476,7 +1486,7 @@ var require_stringify = __commonJS({
1476
1486
  anchors$1.add(anchor);
1477
1487
  props.push(`&${anchor}`);
1478
1488
  }
1479
- const tag = node.tag ? node.tag : tagObj.default ? null : tagObj.tag;
1489
+ const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);
1480
1490
  if (tag)
1481
1491
  props.push(doc.directives.tagString(tag));
1482
1492
  return props.join(" ");
@@ -1499,8 +1509,7 @@ var require_stringify = __commonJS({
1499
1509
  }
1500
1510
  let tagObj = void 0;
1501
1511
  const node = identity.isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
1502
- if (!tagObj)
1503
- tagObj = getTagObject(ctx.doc.schema.tags, node);
1512
+ tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
1504
1513
  const props = stringifyProps(node, tagObj, ctx);
1505
1514
  if (props.length > 0)
1506
1515
  ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
@@ -1652,7 +1661,7 @@ ${ctx.indent}`;
1652
1661
  var require_log = __commonJS({
1653
1662
  "node_modules/yaml/dist/log.js"(exports2) {
1654
1663
  "use strict";
1655
- var node_process = require("node:process");
1664
+ var node_process = require("process");
1656
1665
  function debug(logLevel, ...messages) {
1657
1666
  if (logLevel === "debug")
1658
1667
  console.log(...messages);
@@ -2557,7 +2566,7 @@ var require_schema2 = __commonJS({
2557
2566
  var require_binary = __commonJS({
2558
2567
  "node_modules/yaml/dist/schema/yaml-1.1/binary.js"(exports2) {
2559
2568
  "use strict";
2560
- var node_buffer = require("node:buffer");
2569
+ var node_buffer = require("buffer");
2561
2570
  var Scalar = require_Scalar();
2562
2571
  var stringifyString = require_stringifyString();
2563
2572
  var binary = {
@@ -2602,8 +2611,7 @@ var require_binary = __commonJS({
2602
2611
  } else {
2603
2612
  throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");
2604
2613
  }
2605
- if (!type)
2606
- type = Scalar.Scalar.BLOCK_LITERAL;
2614
+ type ?? (type = Scalar.Scalar.BLOCK_LITERAL);
2607
2615
  if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
2608
2616
  const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
2609
2617
  const n = Math.ceil(str.length / lineWidth);
@@ -3807,8 +3815,7 @@ var require_resolve_props = __commonJS({
3807
3815
  if (token.source.endsWith(":"))
3808
3816
  onError(token.offset + token.source.length - 1, "BAD_ALIAS", "Anchor ending in : is ambiguous", true);
3809
3817
  anchor = token;
3810
- if (start === null)
3811
- start = token.offset;
3818
+ start ?? (start = token.offset);
3812
3819
  atNewline = false;
3813
3820
  hasSpace = false;
3814
3821
  reqSpace = true;
@@ -3817,8 +3824,7 @@ var require_resolve_props = __commonJS({
3817
3824
  if (tag)
3818
3825
  onError(token, "MULTIPLE_TAGS", "A node can have at most one tag");
3819
3826
  tag = token;
3820
- if (start === null)
3821
- start = token.offset;
3827
+ start ?? (start = token.offset);
3822
3828
  atNewline = false;
3823
3829
  hasSpace = false;
3824
3830
  reqSpace = true;
@@ -4899,8 +4905,7 @@ var require_util_empty_scalar_position = __commonJS({
4899
4905
  "use strict";
4900
4906
  function emptyScalarPosition(offset, before, pos) {
4901
4907
  if (before) {
4902
- if (pos === null)
4903
- pos = before.length;
4908
+ pos ?? (pos = before.length);
4904
4909
  for (let i = pos - 1; i >= 0; --i) {
4905
4910
  let st = before[i];
4906
4911
  switch (st.type) {
@@ -5072,7 +5077,7 @@ var require_compose_doc = __commonJS({
5072
5077
  var require_composer = __commonJS({
5073
5078
  "node_modules/yaml/dist/compose/composer.js"(exports2) {
5074
5079
  "use strict";
5075
- var node_process = require("node:process");
5080
+ var node_process = require("process");
5076
5081
  var directives = require_directives();
5077
5082
  var Document = require_Document();
5078
5083
  var errors = require_errors();
@@ -6298,7 +6303,7 @@ var require_line_counter = __commonJS({
6298
6303
  var require_parser = __commonJS({
6299
6304
  "node_modules/yaml/dist/parse/parser.js"(exports2) {
6300
6305
  "use strict";
6301
- var node_process = require("node:process");
6306
+ var node_process = require("process");
6302
6307
  var cst = require_cst();
6303
6308
  var lexer = require_lexer();
6304
6309
  function includesToken(list, type) {
@@ -8836,7 +8841,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
8836
8841
  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';
8837
8842
  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';
8838
8843
  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, "Failed to apply ConfigMap using server-side apply.", {\n cm,\n });\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';
8839
- 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" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*", "!src/cli/docs/**"], version: "0.50.0-nightly.1", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) .", "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && jest src/build-artifact.test.ts", "test:docs": "jest --verbose src/cli/docs/*.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "jest --maxWorkers=4 integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr:dev -c pepr-dev", "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:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && npm run test:journey:run", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "test:unit": 'npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns="build-artifact.test.ts|src/cli/docs/.*\\.test\\.ts"', "format:check": "eslint --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --check", "format:fix": "eslint --fix --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "5.1.0", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.5.3", pino: "9.6.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.1.0", "ts-morph": "^25.0.1" }, devDependencies: { "@commitlint/cli": "19.8.1", "@commitlint/config-conventional": "19.8.1", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.1", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", "ts-jest": "29.3.2", undici: "^7.0.1" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.32.1", "@typescript-eslint/parser": "8.32.1", commander: "13.1.0", esbuild: "0.25.0", eslint: "^9.26.0", "node-forge": "1.3.1", prettier: "3.5.3", prompts: "2.4.2", typescript: "5.8.3", uuid: "11.1.0" } };
8844
+ 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" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*", "!src/cli/docs/**"], version: "0.50.0-nightly.10", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) .", "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && jest src/build-artifact.test.ts", "test:docs": "jest --verbose src/cli/docs/*.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "jest --maxWorkers=4 integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr:dev -c pepr-dev", "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:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && npm run test:journey:run", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "test:unit": 'npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns="build-artifact.test.ts|src/cli/docs/.*\\.test\\.ts"', "format:check": "eslint --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --check", "format:fix": "eslint --fix --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "5.1.0", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.5.4", pino: "9.6.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.1.0", "ts-morph": "^25.0.1" }, devDependencies: { "@commitlint/cli": "19.8.1", "@commitlint/config-conventional": "19.8.1", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.1", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", "ts-jest": "29.3.4", undici: "^7.0.1" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.32.1", "@typescript-eslint/parser": "8.32.1", commander: "13.1.0", esbuild: "0.25.0", eslint: "^9.26.0", "node-forge": "1.3.1", prettier: "3.5.3", prompts: "2.4.2", typescript: "5.8.3", uuid: "11.1.0" } };
8840
8845
 
8841
8846
  // src/cli/init/utils.ts
8842
8847
  var import_fs4 = require("fs");
@@ -10049,25 +10054,23 @@ async function setupWatcher(assets, hash, force) {
10049
10054
  var import_kubernetes_fluent_client4 = require("kubernetes-fluent-client");
10050
10055
  async function checkDeploymentStatus(namespace) {
10051
10056
  const deployments = await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.Deployment).InNamespace(namespace).Get();
10052
- let status = false;
10053
- let readyCount = 0;
10057
+ let allReady = true;
10054
10058
  for (const deployment of deployments.items) {
10055
- const readyReplicas = deployment.status?.readyReplicas ? deployment.status?.readyReplicas : 0;
10056
- if (deployment.status?.readyReplicas !== deployment.spec?.replicas) {
10059
+ const name2 = deployment.metadata?.name ?? "unknown";
10060
+ const specReplicas = deployment.spec?.replicas ?? 0;
10061
+ const readyReplicas = deployment.status?.readyReplicas ?? 0;
10062
+ if (readyReplicas !== specReplicas) {
10057
10063
  logger_default.info(
10058
- `Waiting for deployment ${deployment.metadata?.name} rollout to finish: ${readyReplicas} of ${deployment.spec?.replicas} replicas are available`
10064
+ `Waiting for deployment ${name2} rollout to finish: ${readyReplicas} of ${specReplicas} replicas are available`
10059
10065
  );
10066
+ allReady = false;
10060
10067
  } else {
10061
10068
  logger_default.info(
10062
- `Deployment ${deployment.metadata?.name} rolled out: ${readyReplicas} of ${deployment.spec?.replicas} replicas are available`
10069
+ `Deployment ${name2} rolled out: ${readyReplicas} of ${specReplicas} replicas are available`
10063
10070
  );
10064
- readyCount++;
10065
10071
  }
10066
10072
  }
10067
- if (readyCount === deployments.items.length) {
10068
- status = true;
10069
- }
10070
- return status;
10073
+ return allReady;
10071
10074
  }
10072
10075
  async function namespaceDeploymentsReady(namespace = "pepr-system") {
10073
10076
  logger_default.info(`Checking ${namespace} deployments status...`);
@@ -10153,13 +10156,7 @@ async function buildAndDeployModule(image, force) {
10153
10156
  webhook.image = image ?? webhook.image;
10154
10157
  const capabilities = await loadCapabilities(webhook.path);
10155
10158
  for (const capability of capabilities) {
10156
- namespaceComplianceValidator(capability, webhook.alwaysIgnore?.namespaces);
10157
- namespaceComplianceValidator(
10158
- capability,
10159
- webhook.config.admission?.alwaysIgnore?.namespaces,
10160
- false
10161
- );
10162
- namespaceComplianceValidator(capability, webhook.config.watch?.alwaysIgnore?.namespaces, true);
10159
+ validateNamespaces(capability, webhook);
10163
10160
  }
10164
10161
  try {
10165
10162
  await webhook.deploy(deployWebhook, force, builtModule.cfg.pepr.webhookTimeout ?? 10);
@@ -10188,6 +10185,15 @@ function deploy_default(program2) {
10188
10185
  await buildAndDeployModule(opts.image, opts.force);
10189
10186
  });
10190
10187
  }
10188
+ function validateNamespaces(capability, webhook) {
10189
+ namespaceComplianceValidator(capability, webhook.alwaysIgnore?.namespaces);
10190
+ namespaceComplianceValidator(
10191
+ capability,
10192
+ webhook.config.admission?.alwaysIgnore?.namespaces,
10193
+ false
10194
+ );
10195
+ namespaceComplianceValidator(capability, webhook.config.watch?.alwaysIgnore?.namespaces, true);
10196
+ }
10191
10197
 
10192
10198
  // src/cli/dev.ts
10193
10199
  var import_prompts2 = __toESM(require("prompts"));
@@ -10660,22 +10666,6 @@ function update_default(program2) {
10660
10666
  }
10661
10667
  console.log("Updating the Pepr module...");
10662
10668
  try {
10663
- let packageLockContent = "";
10664
- let foundPackageLock = false;
10665
- try {
10666
- if (import_fs14.default.existsSync("./package-lock.json")) {
10667
- packageLockContent = import_fs14.default.readFileSync("./package-lock.json", "utf-8");
10668
- foundPackageLock = true;
10669
- }
10670
- } catch {
10671
- }
10672
- if (foundPackageLock && packageLockContent) {
10673
- if (packageLockContent.indexOf('"eslint":') >= 0 && packageLockContent.match(/"eslint":\s*"[~^]?8\.[0-9]+\.[0-9]+"/)) {
10674
- console.warn(
10675
- "\nWarning: This Pepr module uses ESLint v8. Pepr will be upgraded to use v9 in a future release.\nSee eslint@9.0.0 release notes for more details: https://eslint.org/blog/2024/04/eslint-v9.0.0-released/"
10676
- );
10677
- }
10678
- }
10679
10669
  (0, import_child_process6.execSync)("npm install pepr@latest", {
10680
10670
  stdio: "inherit"
10681
10671
  });
@@ -51,7 +51,7 @@ if (process.env.LOG_LEVEL) {
51
51
  var logger_default = Log;
52
52
 
53
53
  // src/templates/data.json
54
- 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" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*", "!src/cli/docs/**"], version: "0.50.0-nightly.1", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) .", "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && jest src/build-artifact.test.ts", "test:docs": "jest --verbose src/cli/docs/*.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "jest --maxWorkers=4 integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr:dev -c pepr-dev", "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:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && npm run test:journey:run", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "test:unit": 'npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns="build-artifact.test.ts|src/cli/docs/.*\\.test\\.ts"', "format:check": "eslint --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --check", "format:fix": "eslint --fix --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "5.1.0", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.5.3", pino: "9.6.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.1.0", "ts-morph": "^25.0.1" }, devDependencies: { "@commitlint/cli": "19.8.1", "@commitlint/config-conventional": "19.8.1", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.1", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", "ts-jest": "29.3.2", undici: "^7.0.1" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.32.1", "@typescript-eslint/parser": "8.32.1", commander: "13.1.0", esbuild: "0.25.0", eslint: "^9.26.0", "node-forge": "1.3.1", prettier: "3.5.3", prompts: "2.4.2", typescript: "5.8.3", uuid: "11.1.0" } };
54
+ 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" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*", "!src/cli/docs/**"], version: "0.50.0-nightly.10", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) .", "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && jest src/build-artifact.test.ts", "test:docs": "jest --verbose src/cli/docs/*.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "jest --maxWorkers=4 integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr:dev -c pepr-dev", "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:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && npm run test:journey:run", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "test:unit": 'npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns="build-artifact.test.ts|src/cli/docs/.*\\.test\\.ts"', "format:check": "eslint --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --check", "format:fix": "eslint --fix --ignore-pattern src/templates/eslint.config.mjs src && prettier --config .prettierrc src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "5.1.0", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.5.4", pino: "9.6.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.1.0", "ts-morph": "^25.0.1" }, devDependencies: { "@commitlint/cli": "19.8.1", "@commitlint/config-conventional": "19.8.1", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.1", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", "ts-jest": "29.3.4", undici: "^7.0.1" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.32.1", "@typescript-eslint/parser": "8.32.1", commander: "13.1.0", esbuild: "0.25.0", eslint: "^9.26.0", "node-forge": "1.3.1", prettier: "3.5.3", prompts: "2.4.2", typescript: "5.8.3", uuid: "11.1.0" } };
55
55
 
56
56
  // src/lib/k8s.ts
57
57
  var import_kubernetes_fluent_client = require("kubernetes-fluent-client");
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Checks whether all deployments in the specified Kubernetes namespace are fully rolled out.
3
+ *
4
+ * A deployment is considered ready when the number of `readyReplicas` equals the desired `replicas`.
5
+ * Logs the rollout status of each deployment.
6
+ *
7
+ * @param {string} namespace - The Kubernetes namespace to check.
8
+ * @returns {Promise<boolean>} - `true` if all deployments are ready, otherwise `false`.
9
+ */
1
10
  export declare function checkDeploymentStatus(namespace: string): Promise<boolean>;
2
11
  export declare function namespaceDeploymentsReady(namespace?: string): Promise<true | undefined>;
3
12
  //# sourceMappingURL=deploymentChecks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deploymentChecks.d.ts","sourceRoot":"","sources":["../../src/lib/deploymentChecks.ts"],"names":[],"mappings":"AAMA,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAsB/E;AAGD,wBAAsB,yBAAyB,CAC7C,SAAS,GAAE,MAAsB,GAChC,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAW3B"}
1
+ {"version":3,"file":"deploymentChecks.d.ts","sourceRoot":"","sources":["../../src/lib/deploymentChecks.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAuB/E;AAGD,wBAAsB,yBAAyB,CAC7C,SAAS,GAAE,MAAsB,GAChC,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAW3B"}
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "!dist/**/*.test.d.ts*",
18
18
  "!src/cli/docs/**"
19
19
  ],
20
- "version": "0.50.0-nightly.1",
20
+ "version": "0.50.0-nightly.10",
21
21
  "main": "dist/lib.js",
22
22
  "types": "dist/lib.d.ts",
23
23
  "scripts": {
@@ -56,7 +56,7 @@
56
56
  "heredoc": "^1.3.1",
57
57
  "http-status-codes": "^2.3.0",
58
58
  "json-pointer": "^0.6.2",
59
- "kubernetes-fluent-client": "3.5.3",
59
+ "kubernetes-fluent-client": "3.5.4",
60
60
  "pino": "9.6.0",
61
61
  "pino-pretty": "13.0.0",
62
62
  "prom-client": "15.1.3",
@@ -81,7 +81,7 @@
81
81
  "jest": "29.7.0",
82
82
  "js-yaml": "^4.1.0",
83
83
  "shellcheck": "^3.0.0",
84
- "ts-jest": "29.3.2",
84
+ "ts-jest": "29.3.4",
85
85
  "undici": "^7.0.1"
86
86
  },
87
87
  "overrides": {
package/src/cli/deploy.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
3
3
 
4
4
  import prompt from "prompts";
5
-
5
+ import { CapabilityExport } from "../lib/types";
6
6
  import { Assets } from "../lib/assets/assets";
7
7
  import { ImagePullSecret } from "../lib/types";
8
8
  import { RootCmd } from "./root";
@@ -109,13 +109,7 @@ async function buildAndDeployModule(image: string, force: boolean): Promise<void
109
109
  webhook.image = image ?? webhook.image;
110
110
  const capabilities = await loadCapabilities(webhook.path);
111
111
  for (const capability of capabilities) {
112
- namespaceComplianceValidator(capability, webhook.alwaysIgnore?.namespaces);
113
- namespaceComplianceValidator(
114
- capability,
115
- webhook.config.admission?.alwaysIgnore?.namespaces,
116
- false,
117
- );
118
- namespaceComplianceValidator(capability, webhook.config.watch?.alwaysIgnore?.namespaces, true);
112
+ validateNamespaces(capability, webhook);
119
113
  }
120
114
  try {
121
115
  await webhook.deploy(deployWebhook, force, builtModule.cfg.pepr.webhookTimeout ?? 10);
@@ -163,3 +157,13 @@ export default function (program: RootCmd): void {
163
157
  await buildAndDeployModule(opts.image, opts.force);
164
158
  });
165
159
  }
160
+
161
+ export function validateNamespaces(capability: CapabilityExport, webhook: Assets): void {
162
+ namespaceComplianceValidator(capability, webhook.alwaysIgnore?.namespaces);
163
+ namespaceComplianceValidator(
164
+ capability,
165
+ webhook.config.admission?.alwaysIgnore?.namespaces,
166
+ false,
167
+ );
168
+ namespaceComplianceValidator(capability, webhook.config.watch?.alwaysIgnore?.namespaces, true);
169
+ }
@@ -41,33 +41,6 @@ export default function (program: RootCmd): void {
41
41
  console.log("Updating the Pepr module...");
42
42
 
43
43
  try {
44
- // Check if eslint v8 is a project dependency and warn about future upgrade
45
- let packageLockContent = "";
46
- let foundPackageLock = false;
47
-
48
- try {
49
- // Try to find package-lock.json in the current directory
50
- if (fs.existsSync("./package-lock.json")) {
51
- packageLockContent = fs.readFileSync("./package-lock.json", "utf-8");
52
- foundPackageLock = true;
53
- }
54
- } catch {
55
- // Ignore errors and continue with installation
56
- }
57
-
58
- // If we found the package-lock.json and could read it, check for eslint v8
59
- if (foundPackageLock && packageLockContent) {
60
- // Look for eslint version 8.x.x pattern in the file content
61
- if (
62
- packageLockContent.indexOf('"eslint":') >= 0 &&
63
- packageLockContent.match(/"eslint":\s*"[~^]?8\.[0-9]+\.[0-9]+"/)
64
- ) {
65
- console.warn(
66
- "\nWarning: This Pepr module uses ESLint v8. Pepr will be upgraded to use v9 in a future release.\nSee eslint@9.0.0 release notes for more details: https://eslint.org/blog/2024/04/eslint-v9.0.0-released/",
67
- );
68
- }
69
- }
70
-
71
44
  // Update Pepr for the module
72
45
  execSync("npm install pepr@latest", {
73
46
  stdio: "inherit",
@@ -3,29 +3,38 @@
3
3
  import { K8s, kind } from "kubernetes-fluent-client";
4
4
  import Log from "./telemetry/logger";
5
5
 
6
- // returns true if all deployments are ready, false otherwise
6
+ /**
7
+ * Checks whether all deployments in the specified Kubernetes namespace are fully rolled out.
8
+ *
9
+ * A deployment is considered ready when the number of `readyReplicas` equals the desired `replicas`.
10
+ * Logs the rollout status of each deployment.
11
+ *
12
+ * @param {string} namespace - The Kubernetes namespace to check.
13
+ * @returns {Promise<boolean>} - `true` if all deployments are ready, otherwise `false`.
14
+ */
7
15
  export async function checkDeploymentStatus(namespace: string): Promise<boolean> {
8
16
  const deployments = await K8s(kind.Deployment).InNamespace(namespace).Get();
9
- let status = false;
10
- let readyCount = 0;
17
+
18
+ let allReady = true;
11
19
 
12
20
  for (const deployment of deployments.items) {
13
- const readyReplicas = deployment.status?.readyReplicas ? deployment.status?.readyReplicas : 0;
14
- if (deployment.status?.readyReplicas !== deployment.spec?.replicas) {
21
+ const name = deployment.metadata?.name ?? "unknown";
22
+ const specReplicas = deployment.spec?.replicas ?? 0;
23
+ const readyReplicas = deployment.status?.readyReplicas ?? 0;
24
+
25
+ if (readyReplicas !== specReplicas) {
15
26
  Log.info(
16
- `Waiting for deployment ${deployment.metadata?.name} rollout to finish: ${readyReplicas} of ${deployment.spec?.replicas} replicas are available`,
27
+ `Waiting for deployment ${name} rollout to finish: ${readyReplicas} of ${specReplicas} replicas are available`,
17
28
  );
29
+ allReady = false;
18
30
  } else {
19
31
  Log.info(
20
- `Deployment ${deployment.metadata?.name} rolled out: ${readyReplicas} of ${deployment.spec?.replicas} replicas are available`,
32
+ `Deployment ${name} rolled out: ${readyReplicas} of ${specReplicas} replicas are available`,
21
33
  );
22
- readyCount++;
23
34
  }
24
35
  }
25
- if (readyCount === deployments.items.length) {
26
- status = true;
27
- }
28
- return status;
36
+
37
+ return allReady;
29
38
  }
30
39
 
31
40
  // wait for all deployments in the pepr-system namespace to be ready