pepr 0.42.1 → 0.42.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/dist/cli/build.helpers.d.ts +1 -1
  2. package/dist/cli/build.helpers.d.ts.map +1 -1
  3. package/dist/cli/deploy.d.ts +15 -0
  4. package/dist/cli/deploy.d.ts.map +1 -1
  5. package/dist/cli/dev.d.ts.map +1 -1
  6. package/dist/cli/format.d.ts.map +1 -1
  7. package/dist/cli/format.helpers.d.ts +3 -0
  8. package/dist/cli/format.helpers.d.ts.map +1 -0
  9. package/dist/cli/init/enums.d.ts +10 -0
  10. package/dist/cli/init/enums.d.ts.map +1 -0
  11. package/dist/cli/init/index.d.ts.map +1 -1
  12. package/dist/cli/init/templates.d.ts +15 -11
  13. package/dist/cli/init/templates.d.ts.map +1 -1
  14. package/dist/cli/init/utils.d.ts.map +1 -1
  15. package/dist/cli/init/walkthrough.d.ts +3 -2
  16. package/dist/cli/init/walkthrough.d.ts.map +1 -1
  17. package/dist/cli/kfc.d.ts.map +1 -1
  18. package/dist/cli/root.d.ts.map +1 -1
  19. package/dist/cli/update.d.ts.map +1 -1
  20. package/dist/cli/uuid.d.ts.map +1 -1
  21. package/dist/cli.js +1073 -1220
  22. package/dist/controller.js +1 -195
  23. package/dist/fixtures/loader.d.ts.map +1 -1
  24. package/dist/lib/assets/assets.d.ts +27 -0
  25. package/dist/lib/assets/assets.d.ts.map +1 -0
  26. package/dist/lib/assets/deploy.d.ts +1 -1
  27. package/dist/lib/assets/deploy.d.ts.map +1 -1
  28. package/dist/lib/assets/index.d.ts +5 -24
  29. package/dist/lib/assets/index.d.ts.map +1 -1
  30. package/dist/lib/assets/pods.d.ts +2 -4
  31. package/dist/lib/assets/pods.d.ts.map +1 -1
  32. package/dist/lib/assets/rbac.d.ts.map +1 -1
  33. package/dist/lib/assets/webhooks.d.ts +1 -1
  34. package/dist/lib/assets/webhooks.d.ts.map +1 -1
  35. package/dist/lib/assets/yaml.d.ts +31 -5
  36. package/dist/lib/assets/yaml.d.ts.map +1 -1
  37. package/dist/lib/controller/index.d.ts +2 -2
  38. package/dist/lib/controller/index.d.ts.map +1 -1
  39. package/dist/lib/controller/store.d.ts +1 -1
  40. package/dist/lib/controller/store.d.ts.map +1 -1
  41. package/dist/lib/controller/storeCache.d.ts +1 -1
  42. package/dist/lib/controller/storeCache.d.ts.map +1 -1
  43. package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
  44. package/dist/lib/core/capability.d.ts.map +1 -0
  45. package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
  46. package/dist/lib/core/module.d.ts.map +1 -0
  47. package/dist/lib/core/queue.d.ts.map +1 -0
  48. package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
  49. package/dist/lib/core/schedule.d.ts.map +1 -0
  50. package/dist/lib/core/storage.d.ts.map +1 -0
  51. package/dist/lib/deploymentChecks.d.ts.map +1 -1
  52. package/dist/lib/errors.d.ts +0 -5
  53. package/dist/lib/errors.d.ts.map +1 -1
  54. package/dist/lib/filesystemService.d.ts.map +1 -1
  55. package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
  56. package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
  57. package/dist/lib/filter/filter.d.ts +33 -1
  58. package/dist/lib/filter/filter.d.ts.map +1 -1
  59. package/dist/lib/finalizer.d.ts.map +1 -1
  60. package/dist/lib/helpers.d.ts +4 -9
  61. package/dist/lib/helpers.d.ts.map +1 -1
  62. package/dist/lib/included-files.d.ts.map +1 -1
  63. package/dist/lib/mutate-request.d.ts.map +1 -1
  64. package/dist/lib/processors/mutate-processor.d.ts +28 -0
  65. package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
  66. package/dist/lib/{validate-processor.d.ts → processors/validate-processor.d.ts} +5 -5
  67. package/dist/lib/processors/validate-processor.d.ts.map +1 -0
  68. package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
  69. package/dist/lib/processors/watch-processor.d.ts.map +1 -0
  70. package/dist/lib/telemetry/logger.d.ts.map +1 -1
  71. package/dist/lib/telemetry/metrics.d.ts.map +1 -1
  72. package/dist/lib/validate-request.d.ts +2 -2
  73. package/dist/lib/validate-request.d.ts.map +1 -1
  74. package/dist/lib.d.ts +2 -2
  75. package/dist/lib.d.ts.map +1 -1
  76. package/dist/lib.js +383 -243
  77. package/dist/lib.js.map +4 -4
  78. package/dist/sdk/heredoc.d.ts.map +1 -1
  79. package/package.json +9 -9
  80. package/src/cli/build.helpers.ts +1 -1
  81. package/src/cli/build.ts +1 -1
  82. package/src/cli/deploy.ts +114 -75
  83. package/src/cli/dev.ts +3 -3
  84. package/src/cli/format.helpers.ts +27 -0
  85. package/src/cli/format.ts +4 -18
  86. package/src/cli/init/enums.ts +9 -0
  87. package/src/cli/init/index.ts +4 -3
  88. package/src/cli/init/templates.ts +30 -2
  89. package/src/cli/init/utils.ts +3 -3
  90. package/src/cli/init/walkthrough.ts +7 -8
  91. package/src/cli/kfc.ts +1 -1
  92. package/src/cli/root.ts +1 -1
  93. package/src/cli/update.ts +1 -1
  94. package/src/cli/uuid.ts +1 -1
  95. package/src/fixtures/loader.ts +2 -2
  96. package/src/lib/assets/assets.ts +176 -0
  97. package/src/lib/assets/deploy.ts +6 -6
  98. package/src/lib/assets/index.ts +10 -144
  99. package/src/lib/assets/pods.ts +2 -2
  100. package/src/lib/assets/webhooks.ts +32 -56
  101. package/src/lib/assets/yaml.ts +47 -25
  102. package/src/lib/controller/index.ts +4 -4
  103. package/src/lib/controller/store.ts +2 -2
  104. package/src/lib/controller/storeCache.ts +6 -2
  105. package/src/lib/{capability.ts → core/capability.ts} +4 -4
  106. package/src/lib/{module.ts → core/module.ts} +10 -10
  107. package/src/lib/{queue.ts → core/queue.ts} +1 -1
  108. package/src/lib/deploymentChecks.ts +2 -2
  109. package/src/lib/errors.ts +3 -8
  110. package/src/lib/filesystemService.ts +1 -1
  111. package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
  112. package/src/lib/filter/filter.ts +204 -111
  113. package/src/lib/finalizer.ts +2 -2
  114. package/src/lib/helpers.ts +20 -133
  115. package/src/lib/included-files.ts +1 -1
  116. package/src/lib/processors/mutate-processor.ts +225 -0
  117. package/src/lib/{validate-processor.ts → processors/validate-processor.ts} +8 -8
  118. package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +8 -8
  119. package/src/lib/telemetry/logger.ts +3 -1
  120. package/src/lib/tls.ts +5 -1
  121. package/src/lib/validate-request.ts +4 -4
  122. package/src/lib.ts +2 -2
  123. package/src/runtime/controller.ts +2 -2
  124. package/src/sdk/heredoc.ts +1 -1
  125. package/dist/lib/capability.d.ts.map +0 -1
  126. package/dist/lib/module.d.ts.map +0 -1
  127. package/dist/lib/mutate-processor.d.ts +0 -6
  128. package/dist/lib/mutate-processor.d.ts.map +0 -1
  129. package/dist/lib/queue.d.ts.map +0 -1
  130. package/dist/lib/schedule.d.ts.map +0 -1
  131. package/dist/lib/storage.d.ts.map +0 -1
  132. package/dist/lib/validate-processor.d.ts.map +0 -1
  133. package/dist/lib/watch-processor.d.ts.map +0 -1
  134. package/src/lib/mutate-processor.ts +0 -165
  135. /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
  136. /package/dist/lib/{storage.d.ts → core/storage.d.ts} +0 -0
  137. /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
  138. /package/src/lib/{storage.ts → core/storage.ts} +0 -0
package/dist/lib.js CHANGED
@@ -49,9 +49,9 @@ module.exports = __toCommonJS(lib_exports);
49
49
  var import_kubernetes_fluent_client8 = require("kubernetes-fluent-client");
50
50
  var R = __toESM(require("ramda"));
51
51
 
52
- // src/lib/capability.ts
53
- var import_kubernetes_fluent_client7 = require("kubernetes-fluent-client");
54
- var import_ramda7 = require("ramda");
52
+ // src/lib/core/capability.ts
53
+ var import_kubernetes_fluent_client6 = require("kubernetes-fluent-client");
54
+ var import_ramda8 = require("ramda");
55
55
 
56
56
  // src/lib/telemetry/logger.ts
57
57
  var import_pino = require("pino");
@@ -101,8 +101,8 @@ function redactedPatch(patch = {}) {
101
101
  }
102
102
  var logger_default = Log;
103
103
 
104
- // src/lib/module.ts
105
- var import_ramda5 = require("ramda");
104
+ // src/lib/core/module.ts
105
+ var import_ramda6 = require("ramda");
106
106
 
107
107
  // src/lib/controller/index.ts
108
108
  var import_express = __toESM(require("express"));
@@ -238,21 +238,9 @@ var MetricsCollector = class {
238
238
  };
239
239
  var metricsCollector = new MetricsCollector("pepr");
240
240
 
241
- // src/lib/mutate-processor.ts
241
+ // src/lib/processors/mutate-processor.ts
242
242
  var import_fast_json_patch = __toESM(require("fast-json-patch"));
243
-
244
- // src/lib/errors.ts
245
- var Errors = {
246
- audit: "audit",
247
- ignore: "ignore",
248
- reject: "reject"
249
- };
250
- var ErrorList = Object.values(Errors);
251
- function ValidateError(error = "") {
252
- if (!ErrorList.includes(error)) {
253
- throw new Error(`Invalid error: ${error}. Must be one of: ${ErrorList.join(", ")}`);
254
- }
255
- }
243
+ var import_ramda3 = require("ramda");
256
244
 
257
245
  // src/lib/filter/adjudicators/adjudicators.ts
258
246
  var import_ramda = require("ramda");
@@ -401,8 +389,15 @@ var mismatchedLabels = (0, import_ramda.allPass)([
401
389
  ]);
402
390
  var uncarryableNamespace = (0, import_ramda.allPass)([
403
391
  (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
404
- (0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
405
- (0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)), import_ramda.not)
392
+ (0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => {
393
+ if (kubernetesObject?.kind === "Namespace") {
394
+ return namespaceSelector.includes(kubernetesObject?.metadata?.name);
395
+ }
396
+ if (carriesNamespace(kubernetesObject)) {
397
+ return namespaceSelector.includes(carriedNamespace(kubernetesObject));
398
+ }
399
+ return true;
400
+ }, import_ramda.not)
406
401
  ]);
407
402
  var missingCarriableNamespace = (0, import_ramda.allPass)([
408
403
  (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
@@ -412,8 +407,15 @@ var missingCarriableNamespace = (0, import_ramda.allPass)([
412
407
  ]);
413
408
  var carriesIgnoredNamespace = (0, import_ramda.allPass)([
414
409
  (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
415
- (0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
416
- (0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)))
410
+ (0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => {
411
+ if (kubernetesObject?.kind === "Namespace") {
412
+ return namespaceSelector.includes(kubernetesObject?.metadata?.name);
413
+ }
414
+ if (carriesNamespace(kubernetesObject)) {
415
+ return namespaceSelector.includes(carriedNamespace(kubernetesObject));
416
+ }
417
+ return false;
418
+ })
417
419
  ]);
418
420
  var unbindableNamespaces = (0, import_ramda.allPass)([
419
421
  (0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
@@ -450,9 +452,108 @@ var mismatchedKind = (0, import_ramda.allPass)([
450
452
 
451
453
  // src/lib/filter/filter.ts
452
454
  function shouldSkipRequest(binding, req, capabilityNamespaces, ignoredNamespaces) {
453
- const prefix = "Ignoring Admission Callback:";
454
455
  const obj = req.operation === "DELETE" /* DELETE */ ? req.oldObject : req.object;
455
- return misboundDeleteWithDeletionTimestamp(binding) ? `${prefix} Cannot use deletionTimestamp filter on a DELETE operation.` : mismatchedDeletionTimestamp(binding, obj) ? `${prefix} Binding defines deletionTimestamp but Object does not carry it.` : mismatchedEvent(binding, req) ? `${prefix} Binding defines event '${definedEvent(binding)}' but Request declares '${declaredOperation(req)}'.` : mismatchedName(binding, obj) ? `${prefix} Binding defines name '${definedName(binding)}' but Object carries '${carriedName(obj)}'.` : mismatchedGroup(binding, req) ? `${prefix} Binding defines group '${definedGroup(binding)}' but Request declares '${declaredGroup(req)}'.` : mismatchedVersion(binding, req) ? `${prefix} Binding defines version '${definedVersion(binding)}' but Request declares '${declaredVersion(req)}'.` : mismatchedKind(binding, req) ? `${prefix} Binding defines kind '${definedKind(binding)}' but Request declares '${declaredKind(req)}'.` : unbindableNamespaces(capabilityNamespaces, binding) ? `${prefix} Binding defines namespaces ${JSON.stringify(definedNamespaces(binding))} but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : uncarryableNamespace(capabilityNamespaces, obj) ? `${prefix} Object carries namespace '${carriedNamespace(obj)}' but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : mismatchedNamespace(binding, obj) ? `${prefix} Binding defines namespaces '${JSON.stringify(definedNamespaces(binding))}' but Object carries '${carriedNamespace(obj)}'.` : mismatchedLabels(binding, obj) ? `${prefix} Binding defines labels '${JSON.stringify(definedLabels(binding))}' but Object carries '${JSON.stringify(carriedLabels(obj))}'.` : mismatchedAnnotations(binding, obj) ? `${prefix} Binding defines annotations '${JSON.stringify(definedAnnotations(binding))}' but Object carries '${JSON.stringify(carriedAnnotations(obj))}'.` : mismatchedNamespaceRegex(binding, obj) ? `${prefix} Binding defines namespace regexes '${JSON.stringify(definedNamespaceRegexes(binding))}' but Object carries '${carriedNamespace(obj)}'.` : mismatchedNameRegex(binding, obj) ? `${prefix} Binding defines name regex '${definedNameRegex(binding)}' but Object carries '${carriedName(obj)}'.` : carriesIgnoredNamespace(ignoredNamespaces, obj) ? `${prefix} Object carries namespace '${carriedNamespace(obj)}' but ignored namespaces include '${JSON.stringify(ignoredNamespaces)}'.` : missingCarriableNamespace(capabilityNamespaces, obj) ? `${prefix} Object does not carry a namespace but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : "";
456
+ const prefix = "Ignoring Admission Callback:";
457
+ const adjudicators = [
458
+ () => adjudicateMisboundDeleteWithDeletionTimestamp(binding),
459
+ () => adjudicateMismatchedDeletionTimestamp(binding, obj),
460
+ () => adjudicateMismatchedEvent(binding, req),
461
+ () => adjudicateMismatchedName(binding, obj),
462
+ () => adjudicateMismatchedGroup(binding, req),
463
+ () => adjudicateMismatchedVersion(binding, req),
464
+ () => adjudicateMismatchedKind(binding, req),
465
+ () => adjudicateUnbindableNamespaces(capabilityNamespaces, binding),
466
+ () => adjudicateUncarryableNamespace(capabilityNamespaces, obj),
467
+ () => adjudicateMismatchedNamespace(binding, obj),
468
+ () => adjudicateMismatchedLabels(binding, obj),
469
+ () => adjudicateMismatchedAnnotations(binding, obj),
470
+ () => adjudicateMismatchedNamespaceRegex(binding, obj),
471
+ () => adjudicateMismatchedNameRegex(binding, obj),
472
+ () => adjudicateCarriesIgnoredNamespace(ignoredNamespaces, obj),
473
+ () => adjudicateMissingCarriableNamespace(capabilityNamespaces, obj)
474
+ ];
475
+ for (const adjudicator of adjudicators) {
476
+ const result = adjudicator();
477
+ if (result) {
478
+ return `${prefix} ${result}`;
479
+ }
480
+ }
481
+ return "";
482
+ }
483
+ function filterNoMatchReason(binding, obj, capabilityNamespaces, ignoredNamespaces) {
484
+ const prefix = "Ignoring Watch Callback:";
485
+ const adjudicators = [
486
+ () => adjudicateMismatchedDeletionTimestamp(binding, obj),
487
+ () => adjudicateMismatchedName(binding, obj),
488
+ () => adjudicateMisboundNamespace(binding),
489
+ () => adjudicateMismatchedLabels(binding, obj),
490
+ () => adjudicateMismatchedAnnotations(binding, obj),
491
+ () => adjudicateUncarryableNamespace(capabilityNamespaces, obj),
492
+ () => adjudicateUnbindableNamespaces(capabilityNamespaces, binding),
493
+ () => adjudicateMismatchedNamespace(binding, obj),
494
+ () => adjudicateMismatchedNamespaceRegex(binding, obj),
495
+ () => adjudicateMismatchedNameRegex(binding, obj),
496
+ () => adjudicateCarriesIgnoredNamespace(ignoredNamespaces, obj),
497
+ () => adjudicateMissingCarriableNamespace(capabilityNamespaces, obj)
498
+ ];
499
+ for (const adjudicator of adjudicators) {
500
+ const result = adjudicator();
501
+ if (result) {
502
+ return `${prefix} ${result}`;
503
+ }
504
+ }
505
+ return "";
506
+ }
507
+ function adjudicateMisboundNamespace(binding) {
508
+ return misboundNamespace(binding) ? "Cannot use namespace filter on a namespace object." : null;
509
+ }
510
+ function adjudicateMisboundDeleteWithDeletionTimestamp(binding) {
511
+ return misboundDeleteWithDeletionTimestamp(binding) ? "Cannot use deletionTimestamp filter on a DELETE operation." : null;
512
+ }
513
+ function adjudicateMismatchedDeletionTimestamp(binding, obj) {
514
+ return mismatchedDeletionTimestamp(binding, obj) ? "Binding defines deletionTimestamp but Object does not carry it." : null;
515
+ }
516
+ function adjudicateMismatchedEvent(binding, req) {
517
+ return mismatchedEvent(binding, req) ? `Binding defines event '${definedEvent(binding)}' but Request declares '${declaredOperation(req)}'.` : null;
518
+ }
519
+ function adjudicateMismatchedName(binding, obj) {
520
+ return mismatchedName(binding, obj) ? `Binding defines name '${definedName(binding)}' but Object carries '${carriedName(obj)}'.` : null;
521
+ }
522
+ function adjudicateMismatchedGroup(binding, req) {
523
+ return mismatchedGroup(binding, req) ? `Binding defines group '${definedGroup(binding)}' but Request declares '${declaredGroup(req)}'.` : null;
524
+ }
525
+ function adjudicateMismatchedVersion(binding, req) {
526
+ return mismatchedVersion(binding, req) ? `Binding defines version '${definedVersion(binding)}' but Request declares '${declaredVersion(req)}'.` : null;
527
+ }
528
+ function adjudicateMismatchedKind(binding, req) {
529
+ return mismatchedKind(binding, req) ? `Binding defines kind '${definedKind(binding)}' but Request declares '${declaredKind(req)}'.` : null;
530
+ }
531
+ function adjudicateUnbindableNamespaces(capabilityNamespaces, binding) {
532
+ return unbindableNamespaces(capabilityNamespaces, binding) ? `Binding defines namespaces ${JSON.stringify(definedNamespaces(binding))} but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : null;
533
+ }
534
+ function adjudicateUncarryableNamespace(capabilityNamespaces, obj) {
535
+ return uncarryableNamespace(capabilityNamespaces, obj) ? `Object carries namespace '${obj.kind && obj.kind === "Namespace" ? obj.metadata?.name : carriedNamespace(obj)}' but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : null;
536
+ }
537
+ function adjudicateMismatchedNamespace(binding, obj) {
538
+ return mismatchedNamespace(binding, obj) ? `Binding defines namespaces '${JSON.stringify(definedNamespaces(binding))}' but Object carries '${carriedNamespace(obj)}'.` : null;
539
+ }
540
+ function adjudicateMismatchedLabels(binding, obj) {
541
+ return mismatchedLabels(binding, obj) ? `Binding defines labels '${JSON.stringify(definedLabels(binding))}' but Object carries '${JSON.stringify(carriedLabels(obj))}'.` : null;
542
+ }
543
+ function adjudicateMismatchedAnnotations(binding, obj) {
544
+ return mismatchedAnnotations(binding, obj) ? `Binding defines annotations '${JSON.stringify(definedAnnotations(binding))}' but Object carries '${JSON.stringify(carriedAnnotations(obj))}'.` : null;
545
+ }
546
+ function adjudicateMismatchedNamespaceRegex(binding, obj) {
547
+ return mismatchedNamespaceRegex(binding, obj) ? `Binding defines namespace regexes '${JSON.stringify(definedNamespaceRegexes(binding))}' but Object carries '${carriedNamespace(obj)}'.` : null;
548
+ }
549
+ function adjudicateMismatchedNameRegex(binding, obj) {
550
+ return mismatchedNameRegex(binding, obj) ? `Binding defines name regex '${definedNameRegex(binding)}' but Object carries '${carriedName(obj)}'.` : null;
551
+ }
552
+ function adjudicateCarriesIgnoredNamespace(ignoredNamespaces, obj) {
553
+ return carriesIgnoredNamespace(ignoredNamespaces, obj) ? `Object carries namespace '${obj.kind && obj.kind === "Namespace" ? obj.metadata?.name : carriedNamespace(obj)}' but ignored namespaces include '${JSON.stringify(ignoredNamespaces)}'.` : null;
554
+ }
555
+ function adjudicateMissingCarriableNamespace(capabilityNamespaces, obj) {
556
+ return missingCarriableNamespace(capabilityNamespaces, obj) ? `Object does not carry a namespace but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : null;
456
557
  }
457
558
 
458
559
  // src/lib/mutate-request.ts
@@ -562,80 +663,126 @@ function base64Encode(data) {
562
663
  return Buffer.from(data).toString("base64");
563
664
  }
564
665
 
565
- // src/lib/mutate-processor.ts
666
+ // src/cli/init/enums.ts
667
+ var OnError = /* @__PURE__ */ ((OnError2) => {
668
+ OnError2["AUDIT"] = "audit";
669
+ OnError2["IGNORE"] = "ignore";
670
+ OnError2["REJECT"] = "reject";
671
+ return OnError2;
672
+ })(OnError || {});
673
+
674
+ // src/lib/processors/mutate-processor.ts
675
+ function updateStatus(config, name2, wrapped, status) {
676
+ if (wrapped.Request.operation === "DELETE") {
677
+ return wrapped;
678
+ }
679
+ wrapped.SetAnnotation(`${config.uuid}.pepr.dev/${name2}`, status);
680
+ return wrapped;
681
+ }
682
+ function logMutateErrorMessage(e) {
683
+ try {
684
+ if (e.message && e.message !== "[object Object]") {
685
+ return e.message;
686
+ } else {
687
+ throw new Error("An error occurred in the mutate action.");
688
+ }
689
+ } catch (e2) {
690
+ return "An error occurred with the mutate action.";
691
+ }
692
+ }
693
+ function decodeData(wrapped) {
694
+ let skipped = [];
695
+ const isSecret = wrapped.Request.kind.version === "v1" && wrapped.Request.kind.kind === "Secret";
696
+ if (isSecret) {
697
+ skipped = convertFromBase64Map(wrapped.Raw);
698
+ }
699
+ return { skipped, wrapped };
700
+ }
701
+ function reencodeData(wrapped, skipped) {
702
+ const transformed = (0, import_ramda3.clone)(wrapped.Raw);
703
+ const isSecret = wrapped.Request.kind.version === "v1" && wrapped.Request.kind.kind === "Secret";
704
+ if (isSecret) {
705
+ convertToBase64Map(transformed, skipped);
706
+ }
707
+ return transformed;
708
+ }
709
+ async function processRequest(bindable, wrapped, response) {
710
+ const { binding, actMeta, name: name2, config } = bindable;
711
+ const label = binding.mutateCallback.name;
712
+ logger_default.info(actMeta, `Processing mutation action (${label})`);
713
+ wrapped = updateStatus(config, name2, wrapped, "started");
714
+ try {
715
+ await binding.mutateCallback(wrapped);
716
+ logger_default.info(actMeta, `Mutation action succeeded (${label})`);
717
+ wrapped = updateStatus(config, name2, wrapped, "succeeded");
718
+ } catch (e) {
719
+ wrapped = updateStatus(config, name2, wrapped, "warning");
720
+ response.warnings = response.warnings || [];
721
+ const errorMessage = logMutateErrorMessage(e);
722
+ logger_default.error(actMeta, `Action failed: ${errorMessage}`);
723
+ response.warnings.push(`Action failed: ${errorMessage}`);
724
+ switch (config.onError) {
725
+ case "reject" /* REJECT */:
726
+ response.result = "Pepr module configured to reject on error";
727
+ break;
728
+ case "audit" /* AUDIT */:
729
+ response.auditAnnotations = response.auditAnnotations || {};
730
+ response.auditAnnotations[Date.now()] = `Action failed: ${errorMessage}`;
731
+ break;
732
+ }
733
+ }
734
+ return { wrapped, response };
735
+ }
566
736
  async function mutateProcessor(config, capabilities, req, reqMetadata) {
567
- const wrapped = new PeprMutateRequest(req);
568
- const response = {
737
+ let response = {
569
738
  uid: req.uid,
570
739
  warnings: [],
571
740
  allowed: false
572
741
  };
573
- let matchedAction = false;
574
- let skipDecode = [];
575
- const isSecret = req.kind.version === "v1" && req.kind.kind === "Secret";
576
- if (isSecret) {
577
- skipDecode = convertFromBase64Map(wrapped.Raw);
578
- }
742
+ const decoded = decodeData(new PeprMutateRequest(req));
743
+ let wrapped = decoded.wrapped;
579
744
  logger_default.info(reqMetadata, `Processing request`);
580
- for (const { name: name2, bindings, namespaces } of capabilities) {
581
- const actionMetadata = { ...reqMetadata, name: name2 };
582
- for (const action of bindings) {
583
- if (!action.mutateCallback) {
584
- continue;
585
- }
586
- const shouldSkip = shouldSkipRequest(action, req, namespaces, config?.alwaysIgnore?.namespaces);
587
- if (shouldSkip !== "") {
588
- logger_default.debug(shouldSkip);
589
- continue;
590
- }
591
- const label = action.mutateCallback.name;
592
- logger_default.info(actionMetadata, `Processing mutation action (${label})`);
593
- matchedAction = true;
594
- const updateStatus = (status) => {
595
- if (req.operation === "DELETE") {
596
- return;
597
- }
598
- const identifier = `${config.uuid}.pepr.dev/${name2}`;
599
- wrapped.Raw.metadata = wrapped.Raw.metadata || {};
600
- wrapped.Raw.metadata.annotations = wrapped.Raw.metadata.annotations || {};
601
- wrapped.Raw.metadata.annotations[identifier] = status;
602
- };
603
- updateStatus("started");
604
- try {
605
- await action.mutateCallback(wrapped);
606
- logger_default.info(actionMetadata, `Mutation action succeeded (${label})`);
607
- updateStatus("succeeded");
608
- } catch (e) {
609
- updateStatus("warning");
610
- response.warnings = response.warnings || [];
611
- const errorMessage = logMutateErrorMessage(e);
612
- logger_default.error(actionMetadata, `Action failed: ${errorMessage}`);
613
- response.warnings.push(`Action failed: ${errorMessage}`);
614
- switch (config.onError) {
615
- case Errors.reject:
616
- logger_default.error(actionMetadata, `Action failed: ${errorMessage}`);
617
- response.result = "Pepr module configured to reject on error";
618
- return response;
619
- case Errors.audit:
620
- response.auditAnnotations = response.auditAnnotations || {};
621
- response.auditAnnotations[Date.now()] = `Action failed: ${errorMessage}`;
622
- break;
623
- }
624
- }
745
+ let bindables = capabilities.flatMap(
746
+ (capa) => capa.bindings.map((bind) => ({
747
+ req,
748
+ config,
749
+ name: capa.name,
750
+ namespaces: capa.namespaces,
751
+ binding: bind,
752
+ actMeta: { ...reqMetadata, name: capa.name }
753
+ }))
754
+ );
755
+ bindables = bindables.filter((bind) => {
756
+ if (!bind.binding.mutateCallback) {
757
+ return false;
758
+ }
759
+ const shouldSkip = shouldSkipRequest(
760
+ bind.binding,
761
+ bind.req,
762
+ bind.namespaces,
763
+ bind.config?.alwaysIgnore?.namespaces
764
+ );
765
+ if (shouldSkip !== "") {
766
+ logger_default.debug(shouldSkip);
767
+ return false;
768
+ }
769
+ return true;
770
+ });
771
+ for (const bindable of bindables) {
772
+ ({ wrapped, response } = await processRequest(bindable, wrapped, response));
773
+ if (config.onError === "reject" /* REJECT */ && response?.warnings.length > 0) {
774
+ return response;
625
775
  }
626
776
  }
627
777
  response.allowed = true;
628
- if (!matchedAction) {
778
+ if (bindables.length === 0) {
629
779
  logger_default.info(reqMetadata, `No matching actions found`);
630
780
  return response;
631
781
  }
632
782
  if (req.operation === "DELETE") {
633
783
  return response;
634
784
  }
635
- const transformed = wrapped.Raw;
636
- if (isSecret) {
637
- convertToBase64Map(transformed, skipDecode);
638
- }
785
+ const transformed = reencodeData(wrapped, decoded.skipped);
639
786
  const patches = import_fast_json_patch.default.compare(req.object, transformed);
640
787
  if (patches.length > 0) {
641
788
  response.patchType = "JSONPatch";
@@ -647,20 +794,9 @@ async function mutateProcessor(config, capabilities, req, reqMetadata) {
647
794
  logger_default.debug({ ...reqMetadata, patches }, `Patches generated`);
648
795
  return response;
649
796
  }
650
- var logMutateErrorMessage = (e) => {
651
- try {
652
- if (e.message && e.message !== "[object Object]") {
653
- return e.message;
654
- } else {
655
- throw new Error("An error occurred in the mutate action.");
656
- }
657
- } catch (e2) {
658
- return "An error occurred with the mutate action.";
659
- }
660
- };
661
797
 
662
798
  // src/lib/validate-request.ts
663
- var import_ramda3 = require("ramda");
799
+ var import_ramda4 = require("ramda");
664
800
  var PeprValidateRequest = class {
665
801
  Raw;
666
802
  #input;
@@ -685,9 +821,9 @@ var PeprValidateRequest = class {
685
821
  constructor(input) {
686
822
  this.#input = input;
687
823
  if (input.operation.toUpperCase() === "DELETE" /* DELETE */) {
688
- this.Raw = (0, import_ramda3.clone)(input.oldObject);
824
+ this.Raw = (0, import_ramda4.clone)(input.oldObject);
689
825
  } else {
690
- this.Raw = (0, import_ramda3.clone)(input.object);
826
+ this.Raw = (0, import_ramda4.clone)(input.object);
691
827
  }
692
828
  if (!this.Raw) {
693
829
  throw new Error("unable to load the request object into PeprRequest.Raw");
@@ -737,8 +873,8 @@ var PeprValidateRequest = class {
737
873
  };
738
874
  };
739
875
 
740
- // src/lib/validate-processor.ts
741
- async function processRequest(binding, actionMetadata, peprValidateRequest) {
876
+ // src/lib/processors/validate-processor.ts
877
+ async function processRequest2(binding, actionMetadata, peprValidateRequest) {
742
878
  const label = binding.validateCallback.name;
743
879
  logger_default.info(actionMetadata, `Processing validation action (${label})`);
744
880
  const valResp = {
@@ -786,7 +922,7 @@ async function validateProcessor(config, capabilities, req, reqMetadata) {
786
922
  logger_default.debug(shouldSkip);
787
923
  continue;
788
924
  }
789
- const resp = await processRequest(binding, actionMetadata, wrapped);
925
+ const resp = await processRequest2(binding, actionMetadata, wrapped);
790
926
  response.push(resp);
791
927
  }
792
928
  }
@@ -795,7 +931,7 @@ async function validateProcessor(config, capabilities, req, reqMetadata) {
795
931
 
796
932
  // src/lib/controller/store.ts
797
933
  var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
798
- var import_ramda4 = require("ramda");
934
+ var import_ramda5 = require("ramda");
799
935
 
800
936
  // src/lib/k8s.ts
801
937
  var import_kubernetes_fluent_client = require("kubernetes-fluent-client");
@@ -909,7 +1045,7 @@ var StoreController = class {
909
1045
  for (const name2 of Object.keys(this.#stores)) {
910
1046
  const offset = `${name2}-`.length;
911
1047
  for (const key of Object.keys(data)) {
912
- if ((0, import_ramda4.startsWith)(name2, key) && !(0, import_ramda4.startsWith)(`${name2}-v2`, key)) {
1048
+ if ((0, import_ramda5.startsWith)(name2, key) && !(0, import_ramda5.startsWith)(`${name2}-v2`, key)) {
913
1049
  storeCache = fillStoreCache(storeCache, name2, "remove", {
914
1050
  key: [key.slice(offset)],
915
1051
  value: data[key]
@@ -933,7 +1069,7 @@ var StoreController = class {
933
1069
  const offset = `${name2}-`.length;
934
1070
  const filtered = {};
935
1071
  for (const key of Object.keys(data)) {
936
- if ((0, import_ramda4.startsWith)(name2, key)) {
1072
+ if ((0, import_ramda5.startsWith)(name2, key)) {
937
1073
  filtered[key.slice(offset)] = data[key];
938
1074
  }
939
1075
  }
@@ -1215,123 +1351,18 @@ var Controller = class _Controller {
1215
1351
  }
1216
1352
  };
1217
1353
 
1218
- // src/lib/watch-processor.ts
1219
- var import_kubernetes_fluent_client6 = require("kubernetes-fluent-client");
1220
- var import_types = require("kubernetes-fluent-client/dist/fluent/types");
1221
-
1222
- // src/sdk/sdk.ts
1223
- var sdk_exports = {};
1224
- __export(sdk_exports, {
1225
- containers: () => containers,
1226
- getOwnerRefFrom: () => getOwnerRefFrom,
1227
- sanitizeResourceName: () => sanitizeResourceName,
1228
- writeEvent: () => writeEvent
1229
- });
1230
- var import_kubernetes_fluent_client4 = require("kubernetes-fluent-client");
1231
- function containers(request, containerType) {
1232
- const containers2 = request.Raw.spec?.containers || [];
1233
- const initContainers = request.Raw.spec?.initContainers || [];
1234
- const ephemeralContainers = request.Raw.spec?.ephemeralContainers || [];
1235
- if (containerType === "containers") {
1236
- return containers2;
1237
- }
1238
- if (containerType === "initContainers") {
1239
- return initContainers;
1240
- }
1241
- if (containerType === "ephemeralContainers") {
1242
- return ephemeralContainers;
1354
+ // src/lib/errors.ts
1355
+ var ErrorList = Object.values(OnError);
1356
+ function ValidateError(error = "") {
1357
+ if (!ErrorList.includes(error)) {
1358
+ throw new Error(`Invalid error: ${error}. Must be one of: ${ErrorList.join(", ")}`);
1243
1359
  }
1244
- return [...containers2, ...initContainers, ...ephemeralContainers];
1245
- }
1246
- async function writeEvent(cr, event, eventType, eventReason, reportingComponent, reportingInstance) {
1247
- await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.CoreEvent).Create({
1248
- type: eventType,
1249
- reason: eventReason,
1250
- ...event,
1251
- // Fixed values
1252
- metadata: {
1253
- namespace: cr.metadata.namespace,
1254
- generateName: cr.metadata.name
1255
- },
1256
- involvedObject: {
1257
- apiVersion: cr.apiVersion,
1258
- kind: cr.kind,
1259
- name: cr.metadata.name,
1260
- namespace: cr.metadata.namespace,
1261
- uid: cr.metadata.uid
1262
- },
1263
- firstTimestamp: /* @__PURE__ */ new Date(),
1264
- reportingComponent,
1265
- reportingInstance
1266
- });
1267
- }
1268
- function getOwnerRefFrom(customResource, blockOwnerDeletion, controller) {
1269
- const { apiVersion, kind: kind3, metadata } = customResource;
1270
- const { name: name2, uid } = metadata;
1271
- return [
1272
- {
1273
- apiVersion,
1274
- kind: kind3,
1275
- uid,
1276
- name: name2,
1277
- ...blockOwnerDeletion !== void 0 && { blockOwnerDeletion },
1278
- ...controller !== void 0 && { controller }
1279
- }
1280
- ];
1281
- }
1282
- function sanitizeResourceName(name2) {
1283
- return name2.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
1284
1360
  }
1285
1361
 
1286
- // src/lib/helpers.ts
1287
- function filterNoMatchReason(binding, kubernetesObject, capabilityNamespaces, ignoredNamespaces) {
1288
- const prefix = "Ignoring Watch Callback:";
1289
- return mismatchedDeletionTimestamp(binding, kubernetesObject) ? `${prefix} Binding defines deletionTimestamp but Object does not carry it.` : mismatchedName(binding, kubernetesObject) ? `${prefix} Binding defines name '${definedName(binding)}' but Object carries '${carriedName(kubernetesObject)}'.` : misboundNamespace(binding) ? `${prefix} Cannot use namespace filter on a namespace object.` : mismatchedLabels(binding, kubernetesObject) ? `${prefix} Binding defines labels '${JSON.stringify(definedLabels(binding))}' but Object carries '${JSON.stringify(carriedLabels(kubernetesObject))}'.` : mismatchedAnnotations(binding, kubernetesObject) ? `${prefix} Binding defines annotations '${JSON.stringify(definedAnnotations(binding))}' but Object carries '${JSON.stringify(carriedAnnotations(kubernetesObject))}'.` : uncarryableNamespace(capabilityNamespaces, kubernetesObject) ? `${prefix} Object carries namespace '${carriedNamespace(kubernetesObject)}' but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : unbindableNamespaces(capabilityNamespaces, binding) ? `${prefix} Binding defines namespaces ${JSON.stringify(definedNamespaces(binding))} but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : mismatchedNamespace(binding, kubernetesObject) ? `${prefix} Binding defines namespaces '${JSON.stringify(definedNamespaces(binding))}' but Object carries '${carriedNamespace(kubernetesObject)}'.` : mismatchedNamespaceRegex(binding, kubernetesObject) ? `${prefix} Binding defines namespace regexes '${JSON.stringify(definedNamespaceRegexes(binding))}' but Object carries '${carriedNamespace(kubernetesObject)}'.` : mismatchedNameRegex(binding, kubernetesObject) ? `${prefix} Binding defines name regex '${definedNameRegex(binding)}' but Object carries '${carriedName(kubernetesObject)}'.` : carriesIgnoredNamespace(ignoredNamespaces, kubernetesObject) ? `${prefix} Object carries namespace '${carriedNamespace(kubernetesObject)}' but ignored namespaces include '${JSON.stringify(ignoredNamespaces)}'.` : missingCarriableNamespace(capabilityNamespaces, kubernetesObject) ? `${prefix} Object does not carry a namespace but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` : "";
1290
- }
1291
-
1292
- // src/lib/finalizer.ts
1362
+ // src/lib/processors/watch-processor.ts
1293
1363
  var import_kubernetes_fluent_client5 = require("kubernetes-fluent-client");
1294
- function addFinalizer(request) {
1295
- if (request.Request.operation === "DELETE" /* DELETE */) {
1296
- return;
1297
- }
1298
- if (request.Request.operation === "UPDATE" /* UPDATE */ && request.Raw.metadata?.deletionTimestamp) {
1299
- return;
1300
- }
1301
- const peprFinal = "pepr.dev/finalizer";
1302
- const finalizers = request.Raw.metadata?.finalizers || [];
1303
- if (!finalizers.includes(peprFinal)) {
1304
- finalizers.push(peprFinal);
1305
- }
1306
- request.Merge({ metadata: { finalizers } });
1307
- }
1308
- async function removeFinalizer(binding, obj) {
1309
- const peprFinal = "pepr.dev/finalizer";
1310
- const meta = obj.metadata;
1311
- const resource = `${meta.namespace || "ClusterScoped"}/${meta.name}`;
1312
- logger_default.debug({ obj }, `Removing finalizer '${peprFinal}' from '${resource}'`);
1313
- const { model, kind: kind3 } = binding;
1314
- try {
1315
- (0, import_kubernetes_fluent_client5.RegisterKind)(model, kind3);
1316
- } catch (e) {
1317
- const expected = e.message === `GVK ${model.name} already registered`;
1318
- if (!expected) {
1319
- logger_default.error({ model, kind: kind3, error: e }, `Error registering "${kind3}" during finalization.`);
1320
- return;
1321
- }
1322
- }
1323
- const finalizers = meta.finalizers?.filter((f) => f !== peprFinal) || [];
1324
- obj = await (0, import_kubernetes_fluent_client5.K8s)(model, meta).Patch([
1325
- {
1326
- op: "replace",
1327
- path: `/metadata/finalizers`,
1328
- value: finalizers
1329
- }
1330
- ]);
1331
- logger_default.debug({ obj }, `Removed finalizer '${peprFinal}' from '${resource}'`);
1332
- }
1333
1364
 
1334
- // src/lib/queue.ts
1365
+ // src/lib/core/queue.ts
1335
1366
  var import_node_crypto = require("node:crypto");
1336
1367
  var Queue = class {
1337
1368
  #name;
@@ -1419,7 +1450,52 @@ var Queue = class {
1419
1450
  }
1420
1451
  };
1421
1452
 
1422
- // src/lib/watch-processor.ts
1453
+ // src/lib/processors/watch-processor.ts
1454
+ var import_types = require("kubernetes-fluent-client/dist/fluent/types");
1455
+
1456
+ // src/lib/finalizer.ts
1457
+ var import_kubernetes_fluent_client4 = require("kubernetes-fluent-client");
1458
+ function addFinalizer(request) {
1459
+ if (request.Request.operation === "DELETE" /* DELETE */) {
1460
+ return;
1461
+ }
1462
+ if (request.Request.operation === "UPDATE" /* UPDATE */ && request.Raw.metadata?.deletionTimestamp) {
1463
+ return;
1464
+ }
1465
+ const peprFinal = "pepr.dev/finalizer";
1466
+ const finalizers = request.Raw.metadata?.finalizers || [];
1467
+ if (!finalizers.includes(peprFinal)) {
1468
+ finalizers.push(peprFinal);
1469
+ }
1470
+ request.Merge({ metadata: { finalizers } });
1471
+ }
1472
+ async function removeFinalizer(binding, obj) {
1473
+ const peprFinal = "pepr.dev/finalizer";
1474
+ const meta = obj.metadata;
1475
+ const resource = `${meta.namespace || "ClusterScoped"}/${meta.name}`;
1476
+ logger_default.debug({ obj }, `Removing finalizer '${peprFinal}' from '${resource}'`);
1477
+ const { model, kind: kind3 } = binding;
1478
+ try {
1479
+ (0, import_kubernetes_fluent_client4.RegisterKind)(model, kind3);
1480
+ } catch (e) {
1481
+ const expected = e.message === `GVK ${model.name} already registered`;
1482
+ if (!expected) {
1483
+ logger_default.error({ model, kind: kind3, error: e }, `Error registering "${kind3}" during finalization.`);
1484
+ return;
1485
+ }
1486
+ }
1487
+ const finalizers = meta.finalizers?.filter((f) => f !== peprFinal) || [];
1488
+ obj = await (0, import_kubernetes_fluent_client4.K8s)(model, meta).Patch([
1489
+ {
1490
+ op: "replace",
1491
+ path: `/metadata/finalizers`,
1492
+ value: finalizers
1493
+ }
1494
+ ]);
1495
+ logger_default.debug({ obj }, `Removed finalizer '${peprFinal}' from '${resource}'`);
1496
+ }
1497
+
1498
+ // src/lib/processors/watch-processor.ts
1423
1499
  var queues = {};
1424
1500
  function queueKey(obj) {
1425
1501
  const options = ["kind", "kindNs", "kindNsName", "global"];
@@ -1497,7 +1573,7 @@ async function runBinding(binding, capabilityNamespaces, ignoredNamespaces) {
1497
1573
  shouldRemoveFinalizer === false ? logger_default.debug({ obj: kubernetesObject }, `Skipping removal of finalizer '${peprFinal}' from '${resource}'`) : await removeFinalizer(binding, kubernetesObject);
1498
1574
  }
1499
1575
  };
1500
- const watcher = (0, import_kubernetes_fluent_client6.K8s)(binding.model, binding.filters).Watch(async (obj, phase) => {
1576
+ const watcher = (0, import_kubernetes_fluent_client5.K8s)(binding.model, binding.filters).Watch(async (obj, phase) => {
1501
1577
  logger_default.debug(obj, `Watch event ${phase} received`);
1502
1578
  if (binding.isQueue) {
1503
1579
  const queue = getOrCreateQueue(obj);
@@ -1506,30 +1582,30 @@ async function runBinding(binding, capabilityNamespaces, ignoredNamespaces) {
1506
1582
  await watchCallback(obj, phase);
1507
1583
  }
1508
1584
  }, watchCfg);
1509
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.GIVE_UP, (err) => {
1585
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.GIVE_UP, (err) => {
1510
1586
  logger_default.error(err, "Watch failed after 5 attempts, giving up");
1511
1587
  process.exit(1);
1512
1588
  });
1513
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.CONNECT, (url) => logEvent(import_kubernetes_fluent_client6.WatchEvent.CONNECT, url));
1514
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.DATA_ERROR, (err) => logEvent(import_kubernetes_fluent_client6.WatchEvent.DATA_ERROR, err.message));
1589
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.CONNECT, (url) => logEvent(import_kubernetes_fluent_client5.WatchEvent.CONNECT, url));
1590
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.DATA_ERROR, (err) => logEvent(import_kubernetes_fluent_client5.WatchEvent.DATA_ERROR, err.message));
1515
1591
  watcher.events.on(
1516
- import_kubernetes_fluent_client6.WatchEvent.RECONNECT,
1517
- (retryCount) => logEvent(import_kubernetes_fluent_client6.WatchEvent.RECONNECT, `Reconnecting after ${retryCount} attempt${retryCount === 1 ? "" : "s"}`)
1592
+ import_kubernetes_fluent_client5.WatchEvent.RECONNECT,
1593
+ (retryCount) => logEvent(import_kubernetes_fluent_client5.WatchEvent.RECONNECT, `Reconnecting after ${retryCount} attempt${retryCount === 1 ? "" : "s"}`)
1518
1594
  );
1519
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.RECONNECT_PENDING, () => logEvent(import_kubernetes_fluent_client6.WatchEvent.RECONNECT_PENDING));
1520
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.GIVE_UP, (err) => logEvent(import_kubernetes_fluent_client6.WatchEvent.GIVE_UP, err.message));
1521
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.ABORT, (err) => logEvent(import_kubernetes_fluent_client6.WatchEvent.ABORT, err.message));
1522
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.OLD_RESOURCE_VERSION, (err) => logEvent(import_kubernetes_fluent_client6.WatchEvent.OLD_RESOURCE_VERSION, err));
1523
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.NETWORK_ERROR, (err) => logEvent(import_kubernetes_fluent_client6.WatchEvent.NETWORK_ERROR, err.message));
1524
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.LIST_ERROR, (err) => logEvent(import_kubernetes_fluent_client6.WatchEvent.LIST_ERROR, err.message));
1525
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.LIST, (list) => logEvent(import_kubernetes_fluent_client6.WatchEvent.LIST, JSON.stringify(list, void 0, 2)));
1526
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.CACHE_MISS, (windowName) => {
1595
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.RECONNECT_PENDING, () => logEvent(import_kubernetes_fluent_client5.WatchEvent.RECONNECT_PENDING));
1596
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.GIVE_UP, (err) => logEvent(import_kubernetes_fluent_client5.WatchEvent.GIVE_UP, err.message));
1597
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.ABORT, (err) => logEvent(import_kubernetes_fluent_client5.WatchEvent.ABORT, err.message));
1598
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.OLD_RESOURCE_VERSION, (err) => logEvent(import_kubernetes_fluent_client5.WatchEvent.OLD_RESOURCE_VERSION, err));
1599
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.NETWORK_ERROR, (err) => logEvent(import_kubernetes_fluent_client5.WatchEvent.NETWORK_ERROR, err.message));
1600
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.LIST_ERROR, (err) => logEvent(import_kubernetes_fluent_client5.WatchEvent.LIST_ERROR, err.message));
1601
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.LIST, (list) => logEvent(import_kubernetes_fluent_client5.WatchEvent.LIST, JSON.stringify(list, void 0, 2)));
1602
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.CACHE_MISS, (windowName) => {
1527
1603
  metricsCollector.incCacheMiss(windowName);
1528
1604
  });
1529
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.INIT_CACHE_MISS, (windowName) => {
1605
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.INIT_CACHE_MISS, (windowName) => {
1530
1606
  metricsCollector.initCacheMissWindow(windowName);
1531
1607
  });
1532
- watcher.events.on(import_kubernetes_fluent_client6.WatchEvent.INC_RESYNC_FAILURE_COUNT, (retryCount) => {
1608
+ watcher.events.on(import_kubernetes_fluent_client5.WatchEvent.INC_RESYNC_FAILURE_COUNT, (retryCount) => {
1533
1609
  metricsCollector.incRetryCount(retryCount);
1534
1610
  });
1535
1611
  try {
@@ -1548,7 +1624,7 @@ function logEvent(event, message = "", obj) {
1548
1624
  }
1549
1625
  }
1550
1626
 
1551
- // src/lib/module.ts
1627
+ // src/lib/core/module.ts
1552
1628
  var isWatchMode = () => process.env.PEPR_WATCH_MODE === "true";
1553
1629
  var isBuildMode = () => process.env.PEPR_MODE === "build";
1554
1630
  var isDevMode = () => process.env.PEPR_MODE === "dev";
@@ -1562,7 +1638,7 @@ var PeprModule = class {
1562
1638
  * @param opts Options for the Pepr runtime
1563
1639
  */
1564
1640
  constructor({ description, pepr }, capabilities = [], opts = {}) {
1565
- const config = (0, import_ramda5.clone)(pepr);
1641
+ const config = (0, import_ramda6.clone)(pepr);
1566
1642
  config.description = description;
1567
1643
  ValidateError(config.onError);
1568
1644
  if (isBuildMode()) {
@@ -1608,8 +1684,8 @@ var PeprModule = class {
1608
1684
  };
1609
1685
  };
1610
1686
 
1611
- // src/lib/storage.ts
1612
- var import_ramda6 = require("ramda");
1687
+ // src/lib/core/storage.ts
1688
+ var import_ramda7 = require("ramda");
1613
1689
  var import_json_pointer = __toESM(require("json-pointer"));
1614
1690
  var MAX_WAIT_TIME = 15e3;
1615
1691
  var STORE_VERSION_PREFIX = "v2";
@@ -1632,7 +1708,7 @@ var Storage = class {
1632
1708
  this.#store = data || {};
1633
1709
  this.#onReady();
1634
1710
  for (const idx in this.#subscribers) {
1635
- this.#subscribers[idx]((0, import_ramda6.clone)(this.#store));
1711
+ this.#subscribers[idx]((0, import_ramda7.clone)(this.#store));
1636
1712
  }
1637
1713
  };
1638
1714
  getItem = (key) => {
@@ -1720,7 +1796,7 @@ var Storage = class {
1720
1796
  };
1721
1797
  #onReady = () => {
1722
1798
  for (const handler of this.#readyHandlers) {
1723
- handler((0, import_ramda6.clone)(this.#store));
1799
+ handler((0, import_ramda7.clone)(this.#store));
1724
1800
  }
1725
1801
  this.#onReady = () => {
1726
1802
  };
@@ -1736,7 +1812,7 @@ var Storage = class {
1736
1812
  };
1737
1813
  };
1738
1814
 
1739
- // src/lib/schedule.ts
1815
+ // src/lib/core/schedule.ts
1740
1816
  var OnSchedule = class {
1741
1817
  intervalId = null;
1742
1818
  store;
@@ -1864,7 +1940,7 @@ var OnSchedule = class {
1864
1940
  }
1865
1941
  };
1866
1942
 
1867
- // src/lib/capability.ts
1943
+ // src/lib/core/capability.ts
1868
1944
  var registerAdmission = isBuildMode() || !isWatchMode();
1869
1945
  var registerWatch = isBuildMode() || isWatchMode() || isDevMode();
1870
1946
  var Capability = class {
@@ -1991,7 +2067,7 @@ var Capability = class {
1991
2067
  * @returns
1992
2068
  */
1993
2069
  When = (model, kind3) => {
1994
- const matchedKind = (0, import_kubernetes_fluent_client7.modelToGroupVersionKind)(model.name);
2070
+ const matchedKind = (0, import_kubernetes_fluent_client6.modelToGroupVersionKind)(model.name);
1995
2071
  if (!matchedKind && !kind3) {
1996
2072
  throw new Error(`Kind not specified for ${model.name}`);
1997
2073
  }
@@ -2015,7 +2091,7 @@ var Capability = class {
2015
2091
  const commonChain = { WithLabel, WithAnnotation, WithDeletionTimestamp, Mutate, Validate, Watch, Reconcile, Alias };
2016
2092
  const isNotEmpty = (value) => Object.keys(value).length > 0;
2017
2093
  const log = (message, cbString) => {
2018
- const filteredObj = (0, import_ramda7.pickBy)(isNotEmpty, binding.filters);
2094
+ const filteredObj = (0, import_ramda8.pickBy)(isNotEmpty, binding.filters);
2019
2095
  logger_default.info(`${message} configured for ${binding.event}`, prefix);
2020
2096
  logger_default.info(filteredObj, prefix);
2021
2097
  logger_default.debug(cbString, prefix);
@@ -2168,6 +2244,70 @@ var Capability = class {
2168
2244
  };
2169
2245
  };
2170
2246
  };
2247
+
2248
+ // src/sdk/sdk.ts
2249
+ var sdk_exports = {};
2250
+ __export(sdk_exports, {
2251
+ containers: () => containers,
2252
+ getOwnerRefFrom: () => getOwnerRefFrom,
2253
+ sanitizeResourceName: () => sanitizeResourceName,
2254
+ writeEvent: () => writeEvent
2255
+ });
2256
+ var import_kubernetes_fluent_client7 = require("kubernetes-fluent-client");
2257
+ function containers(request, containerType) {
2258
+ const containers2 = request.Raw.spec?.containers || [];
2259
+ const initContainers = request.Raw.spec?.initContainers || [];
2260
+ const ephemeralContainers = request.Raw.spec?.ephemeralContainers || [];
2261
+ if (containerType === "containers") {
2262
+ return containers2;
2263
+ }
2264
+ if (containerType === "initContainers") {
2265
+ return initContainers;
2266
+ }
2267
+ if (containerType === "ephemeralContainers") {
2268
+ return ephemeralContainers;
2269
+ }
2270
+ return [...containers2, ...initContainers, ...ephemeralContainers];
2271
+ }
2272
+ async function writeEvent(cr, event, eventType, eventReason, reportingComponent, reportingInstance) {
2273
+ await (0, import_kubernetes_fluent_client7.K8s)(import_kubernetes_fluent_client7.kind.CoreEvent).Create({
2274
+ type: eventType,
2275
+ reason: eventReason,
2276
+ ...event,
2277
+ // Fixed values
2278
+ metadata: {
2279
+ namespace: cr.metadata.namespace,
2280
+ generateName: cr.metadata.name
2281
+ },
2282
+ involvedObject: {
2283
+ apiVersion: cr.apiVersion,
2284
+ kind: cr.kind,
2285
+ name: cr.metadata.name,
2286
+ namespace: cr.metadata.namespace,
2287
+ uid: cr.metadata.uid
2288
+ },
2289
+ firstTimestamp: /* @__PURE__ */ new Date(),
2290
+ reportingComponent,
2291
+ reportingInstance
2292
+ });
2293
+ }
2294
+ function getOwnerRefFrom(customResource, blockOwnerDeletion, controller) {
2295
+ const { apiVersion, kind: kind3, metadata } = customResource;
2296
+ const { name: name2, uid } = metadata;
2297
+ return [
2298
+ {
2299
+ apiVersion,
2300
+ kind: kind3,
2301
+ uid,
2302
+ name: name2,
2303
+ ...blockOwnerDeletion !== void 0 && { blockOwnerDeletion },
2304
+ ...controller !== void 0 && { controller }
2305
+ }
2306
+ ];
2307
+ }
2308
+ function sanitizeResourceName(name2) {
2309
+ return name2.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
2310
+ }
2171
2311
  // Annotate the CommonJS export names for ESM import in node:
2172
2312
  0 && (module.exports = {
2173
2313
  Capability,