pepr 0.38.3 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/build.d.ts +1 -1
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.helpers.d.ts +19 -0
- package/dist/cli/build.helpers.d.ts.map +1 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +6 -2
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/monitor.d.ts.map +1 -1
- package/dist/cli.js +278 -225
- package/dist/controller.js +37 -27
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/helm.d.ts +1 -0
- package/dist/lib/assets/helm.d.ts.map +1 -1
- package/dist/lib/assets/index.d.ts +1 -1
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/rbac.d.ts +31 -4
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts +2 -2
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/capability.d.ts +2 -8
- package/dist/lib/capability.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +1 -5
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts +11 -0
- package/dist/lib/controller/storeCache.d.ts.map +1 -0
- package/dist/lib/enums.d.ts +17 -0
- package/dist/lib/enums.d.ts.map +1 -0
- package/dist/lib/{adjudicators.d.ts → filter/adjudicators.d.ts} +15 -13
- package/dist/lib/filter/adjudicators.d.ts.map +1 -0
- package/dist/lib/{filter.d.ts → filter/filter.d.ts} +1 -1
- package/dist/lib/filter/filter.d.ts.map +1 -0
- package/dist/lib/helpers.d.ts +1 -2
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/k8s.d.ts +1 -1
- package/dist/lib/k8s.d.ts.map +1 -1
- package/dist/lib/logger.d.ts +4 -0
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/metrics.d.ts.map +1 -1
- package/dist/lib/module.d.ts +5 -0
- package/dist/lib/module.d.ts.map +1 -1
- package/dist/lib/mutate-processor.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts +1 -60
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/types.d.ts +8 -24
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/dist/lib/watch-processor.d.ts.map +1 -1
- package/dist/lib.js +220 -295
- package/dist/lib.js.map +4 -4
- package/dist/sdk/cosign.d.ts +18 -0
- package/dist/sdk/cosign.d.ts.map +1 -0
- package/dist/sdk/heredoc.d.ts +2 -0
- package/dist/sdk/heredoc.d.ts.map +1 -0
- package/dist/sdk/sdk.d.ts +1 -2
- package/dist/sdk/sdk.d.ts.map +1 -1
- package/package.json +11 -7
- package/src/cli/build.helpers.ts +28 -0
- package/src/cli/build.ts +124 -121
- package/src/cli/deploy.ts +27 -24
- package/src/cli/dev.ts +3 -3
- package/src/cli/format.ts +3 -6
- package/src/cli/init/index.ts +23 -19
- package/src/cli/monitor.ts +34 -36
- package/src/lib/assets/deploy.ts +12 -3
- package/src/lib/assets/helm.ts +14 -0
- package/src/lib/assets/index.ts +12 -8
- package/src/lib/assets/rbac.ts +69 -17
- package/src/lib/assets/webhooks.ts +1 -1
- package/src/lib/assets/yaml.ts +8 -4
- package/src/lib/capability.ts +7 -12
- package/src/lib/controller/index.ts +3 -3
- package/src/lib/controller/store.ts +42 -202
- package/src/lib/controller/storeCache.ts +63 -0
- package/src/lib/enums.ts +21 -0
- package/src/lib/{adjudicators.ts → filter/adjudicators.ts} +39 -28
- package/src/lib/{filter.ts → filter/filter.ts} +3 -2
- package/src/lib/finalizer.ts +1 -1
- package/src/lib/helpers.ts +19 -15
- package/src/lib/k8s.ts +2 -2
- package/src/lib/logger.ts +41 -0
- package/src/lib/metrics.ts +3 -1
- package/src/lib/module.ts +5 -0
- package/src/lib/mutate-processor.ts +14 -12
- package/src/lib/mutate-request.ts +4 -69
- package/src/lib/types.ts +9 -28
- package/src/lib/validate-processor.ts +1 -1
- package/src/lib/validate-request.ts +2 -1
- package/src/lib/watch-processor.ts +34 -20
- package/src/sdk/cosign.ts +327 -0
- package/src/sdk/heredoc.ts +36 -0
- package/src/sdk/sdk.ts +1 -2
- package/dist/lib/adjudicators.d.ts.map +0 -1
- package/dist/lib/filter.d.ts.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -287,23 +287,28 @@ function sanitizeResourceName(name2) {
|
|
|
287
287
|
return name2.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
// src/lib/adjudicators.ts
|
|
290
|
+
// src/lib/filter/adjudicators.ts
|
|
291
291
|
var import_ramda = require("ramda");
|
|
292
292
|
var declaredOperation = (0, import_ramda.pipe)((request) => request?.operation, (0, import_ramda.defaultTo)(""));
|
|
293
293
|
var declaredGroup = (0, import_ramda.pipe)((request) => request?.kind?.group, (0, import_ramda.defaultTo)(""));
|
|
294
294
|
var declaredVersion = (0, import_ramda.pipe)((request) => request?.kind?.version, (0, import_ramda.defaultTo)(""));
|
|
295
295
|
var declaredKind = (0, import_ramda.pipe)((request) => request?.kind?.kind, (0, import_ramda.defaultTo)(""));
|
|
296
296
|
var declaredUid = (0, import_ramda.pipe)((request) => request?.uid, (0, import_ramda.defaultTo)(""));
|
|
297
|
-
var carriesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
297
|
+
var carriesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
298
|
+
(kubernetesObject) => !!kubernetesObject.metadata?.deletionTimestamp,
|
|
299
|
+
(0, import_ramda.defaultTo)(false)
|
|
300
|
+
);
|
|
298
301
|
var missingDeletionTimestamp = (0, import_ramda.complement)(carriesDeletionTimestamp);
|
|
299
|
-
var
|
|
302
|
+
var carriedKind = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.kind, (0, import_ramda.defaultTo)("not set"));
|
|
303
|
+
var carriedVersion = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.version, (0, import_ramda.defaultTo)("not set"));
|
|
304
|
+
var carriedName = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.name, (0, import_ramda.defaultTo)(""));
|
|
300
305
|
var carriesName = (0, import_ramda.pipe)(carriedName, (0, import_ramda.equals)(""), import_ramda.not);
|
|
301
306
|
var missingName = (0, import_ramda.complement)(carriesName);
|
|
302
|
-
var carriedNamespace = (0, import_ramda.pipe)((
|
|
307
|
+
var carriedNamespace = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.namespace, (0, import_ramda.defaultTo)(""));
|
|
303
308
|
var carriesNamespace = (0, import_ramda.pipe)(carriedNamespace, (0, import_ramda.equals)(""), import_ramda.not);
|
|
304
|
-
var carriedAnnotations = (0, import_ramda.pipe)((
|
|
309
|
+
var carriedAnnotations = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.annotations, (0, import_ramda.defaultTo)({}));
|
|
305
310
|
var carriesAnnotations = (0, import_ramda.pipe)(carriedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
|
|
306
|
-
var carriedLabels = (0, import_ramda.pipe)((
|
|
311
|
+
var carriedLabels = (0, import_ramda.pipe)((kubernetesObject) => kubernetesObject?.metadata?.labels, (0, import_ramda.defaultTo)({}));
|
|
307
312
|
var carriesLabels = (0, import_ramda.pipe)(carriedLabels, (0, import_ramda.equals)({}), import_ramda.not);
|
|
308
313
|
var definesDeletionTimestamp = (0, import_ramda.pipe)((binding) => binding?.filters?.deletionTimestamp, (0, import_ramda.defaultTo)(false));
|
|
309
314
|
var ignoresDeletionTimestamp = (0, import_ramda.complement)(definesDeletionTimestamp);
|
|
@@ -334,46 +339,46 @@ var definedCategory = (0, import_ramda.pipe)((binding) => {
|
|
|
334
339
|
var definedCallback = (0, import_ramda.pipe)((binding) => {
|
|
335
340
|
return binding.isFinalize ? binding.finalizeCallback : binding.isWatch ? binding.watchCallback : binding.isMutate ? binding.mutateCallback : binding.isValidate ? binding.validateCallback : null;
|
|
336
341
|
});
|
|
337
|
-
var definedCallbackName = (0, import_ramda.pipe)(definedCallback, (0, import_ramda.defaultTo)({ name: "" }), (
|
|
342
|
+
var definedCallbackName = (0, import_ramda.pipe)(definedCallback, (0, import_ramda.defaultTo)({ name: "" }), (callback) => callback.name);
|
|
338
343
|
var mismatchedDeletionTimestamp = (0, import_ramda.allPass)([
|
|
339
344
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesDeletionTimestamp),
|
|
340
345
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), missingDeletionTimestamp)
|
|
341
346
|
]);
|
|
342
347
|
var mismatchedName = (0, import_ramda.allPass)([
|
|
343
348
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesName),
|
|
344
|
-
(0, import_ramda.pipe)((
|
|
349
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => definedName(binding) !== carriedName(kubernetesObject))
|
|
345
350
|
]);
|
|
346
351
|
var mismatchedNameRegex = (0, import_ramda.allPass)([
|
|
347
352
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNameRegex),
|
|
348
|
-
(0, import_ramda.pipe)((
|
|
353
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => new RegExp(definedNameRegex(binding)).test(carriedName(kubernetesObject)), import_ramda.not)
|
|
349
354
|
]);
|
|
350
355
|
var bindsToKind = (0, import_ramda.curry)(
|
|
351
|
-
(0, import_ramda.allPass)([(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definedKind, (0, import_ramda.equals)(""), import_ramda.not), (0, import_ramda.pipe)((
|
|
356
|
+
(0, import_ramda.allPass)([(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definedKind, (0, import_ramda.equals)(""), import_ramda.not), (0, import_ramda.pipe)((binding, kind8) => definedKind(binding) === kind8)])
|
|
352
357
|
);
|
|
353
358
|
var bindsToNamespace = (0, import_ramda.curry)((0, import_ramda.pipe)(bindsToKind(import_ramda.__, "Namespace")));
|
|
354
359
|
var misboundNamespace = (0, import_ramda.allPass)([bindsToNamespace, definesNamespaces]);
|
|
355
360
|
var mismatchedNamespace = (0, import_ramda.allPass)([
|
|
356
361
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaces),
|
|
357
|
-
(0, import_ramda.pipe)((
|
|
362
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => definedNamespaces(binding).includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
358
363
|
]);
|
|
359
364
|
var mismatchedNamespaceRegex = (0, import_ramda.allPass)([
|
|
360
365
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaceRegexes),
|
|
361
366
|
(0, import_ramda.pipe)(
|
|
362
|
-
(
|
|
363
|
-
(0, import_ramda.any)((
|
|
367
|
+
(binding, kubernetesObject) => (0, import_ramda.pipe)(
|
|
368
|
+
(0, import_ramda.any)((regEx) => new RegExp(regEx).test(carriedNamespace(kubernetesObject))),
|
|
364
369
|
import_ramda.not
|
|
365
|
-
)(definedNamespaceRegexes(
|
|
370
|
+
)(definedNamespaceRegexes(binding))
|
|
366
371
|
)
|
|
367
372
|
]);
|
|
368
373
|
var metasMismatch = (0, import_ramda.pipe)(
|
|
369
374
|
(defined, carried) => {
|
|
370
375
|
const result = { defined, carried, unalike: {} };
|
|
371
|
-
result.unalike = Object.entries(result.defined).map(([key,
|
|
376
|
+
result.unalike = Object.entries(result.defined).map(([key, value]) => {
|
|
372
377
|
const keyMissing = !Object.hasOwn(result.carried, key);
|
|
373
|
-
const noValue = !
|
|
378
|
+
const noValue = !value;
|
|
374
379
|
const valMissing = !result.carried[key];
|
|
375
380
|
const valDiffers = result.carried[key] !== result.defined[key];
|
|
376
|
-
return keyMissing ? { [key]:
|
|
381
|
+
return keyMissing ? { [key]: value } : noValue ? {} : valMissing ? { [key]: value } : valDiffers ? { [key]: value } : {};
|
|
377
382
|
}).reduce((acc, cur) => ({ ...acc, ...cur }), {});
|
|
378
383
|
return result.unalike;
|
|
379
384
|
},
|
|
@@ -381,32 +386,37 @@ var metasMismatch = (0, import_ramda.pipe)(
|
|
|
381
386
|
);
|
|
382
387
|
var mismatchedAnnotations = (0, import_ramda.allPass)([
|
|
383
388
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesAnnotations),
|
|
384
|
-
(0, import_ramda.pipe)((
|
|
389
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedAnnotations(binding), carriedAnnotations(kubernetesObject)))
|
|
385
390
|
]);
|
|
386
391
|
var mismatchedLabels = (0, import_ramda.allPass)([
|
|
387
392
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesLabels),
|
|
388
|
-
(0, import_ramda.pipe)((
|
|
393
|
+
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedLabels(binding), carriedLabels(kubernetesObject)))
|
|
389
394
|
]);
|
|
390
395
|
var uncarryableNamespace = (0, import_ramda.allPass)([
|
|
391
396
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
392
397
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
393
|
-
(0, import_ramda.pipe)((
|
|
398
|
+
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
394
399
|
]);
|
|
395
400
|
var carriesIgnoredNamespace = (0, import_ramda.allPass)([
|
|
396
401
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
397
402
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
398
|
-
(0, import_ramda.pipe)((
|
|
403
|
+
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)))
|
|
399
404
|
]);
|
|
400
405
|
var unbindableNamespaces = (0, import_ramda.allPass)([
|
|
401
406
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
402
407
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), definesNamespaces),
|
|
403
|
-
(0, import_ramda.pipe)(
|
|
408
|
+
(0, import_ramda.pipe)(
|
|
409
|
+
(namespaceSelector, binding) => (0, import_ramda.difference)(definedNamespaces(binding), namespaceSelector),
|
|
410
|
+
import_ramda.length,
|
|
411
|
+
(0, import_ramda.equals)(0),
|
|
412
|
+
import_ramda.not
|
|
413
|
+
)
|
|
404
414
|
]);
|
|
405
415
|
var misboundDeleteWithDeletionTimestamp = (0, import_ramda.allPass)([definesDelete, definesDeletionTimestamp]);
|
|
406
416
|
var operationMatchesEvent = (0, import_ramda.anyPass)([
|
|
407
417
|
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), (0, import_ramda.equals)("*" /* Any */)),
|
|
408
|
-
(0, import_ramda.pipe)((
|
|
409
|
-
(0, import_ramda.pipe)((
|
|
418
|
+
(0, import_ramda.pipe)((operation, event) => operation === event),
|
|
419
|
+
(0, import_ramda.pipe)((operation, event) => operation ? event.includes(operation) : false)
|
|
410
420
|
]);
|
|
411
421
|
var mismatchedEvent = (0, import_ramda.pipe)(
|
|
412
422
|
(binding, request) => operationMatchesEvent(declaredOperation(request), definedEvent(binding)),
|
|
@@ -462,6 +472,12 @@ function createRBACMap(capabilities) {
|
|
|
462
472
|
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
463
473
|
};
|
|
464
474
|
}
|
|
475
|
+
if (binding.isFinalize) {
|
|
476
|
+
acc[key] = {
|
|
477
|
+
verbs: ["patch"],
|
|
478
|
+
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
479
|
+
};
|
|
480
|
+
}
|
|
465
481
|
});
|
|
466
482
|
return acc;
|
|
467
483
|
}, {});
|
|
@@ -529,12 +545,7 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
529
545
|
if (bindingRegexNamespaces && bindingRegexNamespaces.length > 0 && capabilityNamespaces && capabilityNamespaces.length > 0) {
|
|
530
546
|
for (const regexNamespace of bindingRegexNamespaces) {
|
|
531
547
|
let matches = false;
|
|
532
|
-
|
|
533
|
-
if (regexNamespace !== "" && matchesRegex(regexNamespace, capabilityNamespace)) {
|
|
534
|
-
matches = true;
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
548
|
+
matches = regexNamespace !== "" && capabilityNamespaces.some((capabilityNamespace) => matchesRegex(regexNamespace, capabilityNamespace));
|
|
538
549
|
if (!matches) {
|
|
539
550
|
throw new Error(
|
|
540
551
|
`Ignoring Watch Callback: Object namespace does not match any capability namespace with regex ${regexNamespace}.`
|
|
@@ -544,12 +555,11 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
544
555
|
}
|
|
545
556
|
if (bindingRegexNamespaces && bindingRegexNamespaces.length > 0 && ignoredNamespaces && ignoredNamespaces.length > 0) {
|
|
546
557
|
for (const regexNamespace of bindingRegexNamespaces) {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}
|
|
558
|
+
const matchedNS = ignoredNamespaces.find((ignoredNS) => matchesRegex(regexNamespace, ignoredNS));
|
|
559
|
+
if (matchedNS) {
|
|
560
|
+
throw new Error(
|
|
561
|
+
`Ignoring Watch Callback: Regex namespace: ${regexNamespace}, is an ignored namespace: ${matchedNS}.`
|
|
562
|
+
);
|
|
553
563
|
}
|
|
554
564
|
}
|
|
555
565
|
}
|
|
@@ -973,23 +983,33 @@ function genEnv(config, watchMode = false, ignoreWatchMode = false) {
|
|
|
973
983
|
}
|
|
974
984
|
|
|
975
985
|
// src/lib/assets/rbac.ts
|
|
976
|
-
function clusterRole(name2, capabilities, rbacMode = "") {
|
|
986
|
+
function clusterRole(name2, capabilities, rbacMode = "admin", customRbac) {
|
|
977
987
|
const rbacMap = createRBACMap(capabilities);
|
|
988
|
+
const scopedRules = Object.keys(rbacMap).map((key) => {
|
|
989
|
+
let group2;
|
|
990
|
+
key.split("/").length < 3 ? group2 = "" : group2 = key.split("/")[0];
|
|
991
|
+
return {
|
|
992
|
+
apiGroups: [group2],
|
|
993
|
+
resources: [rbacMap[key].plural],
|
|
994
|
+
verbs: rbacMap[key].verbs
|
|
995
|
+
};
|
|
996
|
+
});
|
|
997
|
+
const mergedRBAC = [...Array.isArray(customRbac) ? customRbac : [], ...scopedRules];
|
|
998
|
+
const deduper = {};
|
|
999
|
+
mergedRBAC.forEach((rule) => {
|
|
1000
|
+
const key = `${rule.apiGroups}/${rule.resources}`;
|
|
1001
|
+
if (deduper[key]) {
|
|
1002
|
+
deduper[key].verbs = Array.from(/* @__PURE__ */ new Set([...deduper[key].verbs, ...rule.verbs]));
|
|
1003
|
+
} else {
|
|
1004
|
+
deduper[key] = { ...rule, verbs: rule.verbs || [] };
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
const deduplicatedRules = Object.values(deduper);
|
|
978
1008
|
return {
|
|
979
1009
|
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
980
1010
|
kind: "ClusterRole",
|
|
981
1011
|
metadata: { name: name2 },
|
|
982
|
-
rules: rbacMode === "scoped" ? [
|
|
983
|
-
...Object.keys(rbacMap).map((key) => {
|
|
984
|
-
let group2;
|
|
985
|
-
key.split("/").length < 3 ? group2 = "" : group2 = key.split("/")[0];
|
|
986
|
-
return {
|
|
987
|
-
apiGroups: [group2],
|
|
988
|
-
resources: [rbacMap[key].plural],
|
|
989
|
-
verbs: rbacMap[key].verbs
|
|
990
|
-
};
|
|
991
|
-
})
|
|
992
|
-
] : [
|
|
1012
|
+
rules: rbacMode === "scoped" ? deduplicatedRules : [
|
|
993
1013
|
{
|
|
994
1014
|
apiGroups: ["*"],
|
|
995
1015
|
resources: ["*"],
|
|
@@ -1066,14 +1086,14 @@ function storeRoleBinding(name2) {
|
|
|
1066
1086
|
|
|
1067
1087
|
// src/lib/k8s.ts
|
|
1068
1088
|
var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
|
|
1069
|
-
var
|
|
1089
|
+
var Store = class extends import_kubernetes_fluent_client3.GenericKind {
|
|
1070
1090
|
};
|
|
1071
1091
|
var peprStoreGVK = {
|
|
1072
1092
|
kind: "PeprStore",
|
|
1073
1093
|
version: "v1",
|
|
1074
1094
|
group: "pepr.dev"
|
|
1075
1095
|
};
|
|
1076
|
-
(0, import_kubernetes_fluent_client3.RegisterKind)(
|
|
1096
|
+
(0, import_kubernetes_fluent_client3.RegisterKind)(Store, peprStoreGVK);
|
|
1077
1097
|
|
|
1078
1098
|
// src/lib/assets/store.ts
|
|
1079
1099
|
var { group, version, kind: kind3 } = peprStoreGVK;
|
|
@@ -1273,16 +1293,17 @@ async function deploy(assets, force, webhookTimeout) {
|
|
|
1273
1293
|
if (code.length < 1) {
|
|
1274
1294
|
throw new Error("No code provided");
|
|
1275
1295
|
}
|
|
1276
|
-
await setupRBAC(name2, assets.capabilities, force);
|
|
1296
|
+
await setupRBAC(name2, assets.capabilities, force, assets.config);
|
|
1277
1297
|
await setupController(assets, code, hash, force);
|
|
1278
1298
|
await setupWatcher(assets, hash, force);
|
|
1279
1299
|
}
|
|
1280
|
-
async function setupRBAC(name2, capabilities, force) {
|
|
1300
|
+
async function setupRBAC(name2, capabilities, force, config) {
|
|
1301
|
+
const { rbacMode, rbac } = config;
|
|
1281
1302
|
logger_default.info("Applying cluster role binding");
|
|
1282
1303
|
const crb = clusterRoleBinding(name2);
|
|
1283
1304
|
await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.ClusterRoleBinding).Apply(crb, { force });
|
|
1284
1305
|
logger_default.info("Applying cluster role");
|
|
1285
|
-
const cr = clusterRole(name2, capabilities);
|
|
1306
|
+
const cr = clusterRole(name2, capabilities, rbacMode, rbac);
|
|
1286
1307
|
await (0, import_kubernetes_fluent_client4.K8s)(import_kubernetes_fluent_client4.kind.ClusterRole).Apply(cr, { force });
|
|
1287
1308
|
logger_default.info("Applying service account");
|
|
1288
1309
|
const sa = serviceAccount(name2);
|
|
@@ -1352,8 +1373,10 @@ function loadCapabilities(path) {
|
|
|
1352
1373
|
var import_client_node = require("@kubernetes/client-node");
|
|
1353
1374
|
var import_crypto2 = __toESM(require("crypto"));
|
|
1354
1375
|
var import_fs4 = require("fs");
|
|
1355
|
-
async function overridesFile({ hash, name: name2, image, config, apiToken }, path) {
|
|
1376
|
+
async function overridesFile({ hash, name: name2, image, config, apiToken, capabilities }, path) {
|
|
1377
|
+
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
1356
1378
|
const overrides = {
|
|
1379
|
+
rbac: rbacOverrides,
|
|
1357
1380
|
secrets: {
|
|
1358
1381
|
apiToken: Buffer.from(apiToken).toString("base64")
|
|
1359
1382
|
},
|
|
@@ -1555,8 +1578,8 @@ function zarfYamlChart({ name: name2, image, config }, path) {
|
|
|
1555
1578
|
};
|
|
1556
1579
|
return (0, import_client_node.dumpYaml)(zarfCfg, { noRefs: true });
|
|
1557
1580
|
}
|
|
1558
|
-
async function allYaml(assets,
|
|
1559
|
-
const { name: name2, tls, apiToken, path } = assets;
|
|
1581
|
+
async function allYaml(assets, imagePullSecret) {
|
|
1582
|
+
const { name: name2, tls, apiToken, path, config } = assets;
|
|
1560
1583
|
const code = await import_fs4.promises.readFile(path);
|
|
1561
1584
|
assets.hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
1562
1585
|
const mutateWebhook = await webhookConfig(assets, "mutate", assets.config.webhookTimeout);
|
|
@@ -1564,7 +1587,7 @@ async function allYaml(assets, rbacMode, imagePullSecret) {
|
|
|
1564
1587
|
const watchDeployment = watcher(assets, assets.hash, assets.buildTimestamp, imagePullSecret);
|
|
1565
1588
|
const resources = [
|
|
1566
1589
|
namespace(assets.config.customLabels?.namespace),
|
|
1567
|
-
clusterRole(name2, assets.capabilities, rbacMode),
|
|
1590
|
+
clusterRole(name2, assets.capabilities, config.rbacMode, config.rbac),
|
|
1568
1591
|
clusterRoleBinding(name2),
|
|
1569
1592
|
serviceAccount(name2),
|
|
1570
1593
|
apiTokenSecret(name2, apiToken),
|
|
@@ -1592,6 +1615,19 @@ async function allYaml(assets, rbacMode, imagePullSecret) {
|
|
|
1592
1615
|
var import_path = require("path");
|
|
1593
1616
|
|
|
1594
1617
|
// src/lib/assets/helm.ts
|
|
1618
|
+
function clusterRoleTemplate() {
|
|
1619
|
+
return `
|
|
1620
|
+
apiVersion: rbac.authorization.k8s.io/v1
|
|
1621
|
+
kind: ClusterRole
|
|
1622
|
+
metadata:
|
|
1623
|
+
name: {{ .Values.uuid }}
|
|
1624
|
+
namespace: pepr-system
|
|
1625
|
+
rules:
|
|
1626
|
+
{{- if .Values.rbac }}
|
|
1627
|
+
{{- toYaml .Values.rbac | nindent 2 }}
|
|
1628
|
+
{{- end }}
|
|
1629
|
+
`;
|
|
1630
|
+
}
|
|
1595
1631
|
function nsTemplate() {
|
|
1596
1632
|
return `
|
|
1597
1633
|
apiVersion: v1
|
|
@@ -1860,12 +1896,12 @@ var Assets = class {
|
|
|
1860
1896
|
};
|
|
1861
1897
|
zarfYaml = (path) => zarfYaml(this, path);
|
|
1862
1898
|
zarfYamlChart = (path) => zarfYamlChart(this, path);
|
|
1863
|
-
allYaml = async (
|
|
1899
|
+
allYaml = async (imagePullSecret) => {
|
|
1864
1900
|
this.capabilities = await loadCapabilities(this.path);
|
|
1865
1901
|
for (const capability of this.capabilities) {
|
|
1866
1902
|
namespaceComplianceValidator(capability, this.alwaysIgnore?.namespaces);
|
|
1867
1903
|
}
|
|
1868
|
-
return allYaml(this,
|
|
1904
|
+
return allYaml(this, imagePullSecret);
|
|
1869
1905
|
};
|
|
1870
1906
|
generateHelmChart = async (basePath) => {
|
|
1871
1907
|
const CHART_DIR = `${basePath}/${this.config.uuid}-chart`;
|
|
@@ -1904,10 +1940,7 @@ var Assets = class {
|
|
|
1904
1940
|
await import_fs5.promises.writeFile(moduleSecretPath, (0, import_client_node2.dumpYaml)(moduleSecret(this.name, code, this.hash), { noRefs: true }));
|
|
1905
1941
|
await import_fs5.promises.writeFile(storeRolePath, (0, import_client_node2.dumpYaml)(storeRole(this.name), { noRefs: true }));
|
|
1906
1942
|
await import_fs5.promises.writeFile(storeRoleBindingPath, (0, import_client_node2.dumpYaml)(storeRoleBinding(this.name), { noRefs: true }));
|
|
1907
|
-
await import_fs5.promises.writeFile(
|
|
1908
|
-
clusterRolePath,
|
|
1909
|
-
(0, import_client_node2.dumpYaml)(clusterRole(this.name, this.capabilities, "rbac"), { noRefs: true })
|
|
1910
|
-
);
|
|
1943
|
+
await import_fs5.promises.writeFile(clusterRolePath, dedent(clusterRoleTemplate()));
|
|
1911
1944
|
await import_fs5.promises.writeFile(clusterRoleBindingPath, (0, import_client_node2.dumpYaml)(clusterRoleBinding(this.name), { noRefs: true }));
|
|
1912
1945
|
await import_fs5.promises.writeFile(serviceAccountPath, (0, import_client_node2.dumpYaml)(serviceAccount(this.name), { noRefs: true }));
|
|
1913
1946
|
const mutateWebhook = await webhookConfig(this, "mutate", this.config.webhookTimeout);
|
|
@@ -2161,7 +2194,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
2161
2194
|
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';
|
|
2162
2195
|
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';
|
|
2163
2196
|
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 nock from "nock";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://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 // Set up Nock to mock the API calls globally with header matching\n nock(jokeURL).get("/").reply(200, {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\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';
|
|
2164
|
-
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", "!dist/**/*.test.d.ts*"], version: "0.
|
|
2197
|
+
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", "!dist/**/*.test.d.ts*"], version: "0.39.0", 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", version: "node scripts/set-version.js", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns='cosign.e2e.test.ts'", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "4.21.1", "fast-json-patch": "3.1.1", "follow-redirects": "1.15.9", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.3.0", pino: "9.5.0", "pino-pretty": "11.3.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.0.0" }, devDependencies: { "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.0", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.0", "@types/follow-redirects": "1.14.4", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^3.19.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", nock: "^13.5.4", "ts-jest": "29.2.5" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", commander: "12.1.0", esbuild: "0.23.0", eslint: "8.57.0", "node-forge": "1.3.1", prettier: "3.3.3", prompts: "2.4.2", typescript: "5.3.3", uuid: "10.0.0" } };
|
|
2165
2198
|
|
|
2166
2199
|
// src/templates/pepr.code-snippets.json
|
|
2167
2200
|
var pepr_code_snippets_default = {
|
|
@@ -2381,11 +2414,9 @@ async function peprFormat(validateOnly) {
|
|
|
2381
2414
|
const content = await import_fs7.promises.readFile(filePath, "utf8");
|
|
2382
2415
|
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
2383
2416
|
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
2384
|
-
if (validateOnly) {
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
console.error(`File ${filePath} is not formatted correctly`);
|
|
2388
|
-
}
|
|
2417
|
+
if (validateOnly && formatted !== content) {
|
|
2418
|
+
hasFailure = true;
|
|
2419
|
+
console.error(`File ${filePath} is not formatted correctly`);
|
|
2389
2420
|
} else {
|
|
2390
2421
|
await import_fs7.promises.writeFile(filePath, formatted);
|
|
2391
2422
|
}
|
|
@@ -2400,6 +2431,19 @@ async function peprFormat(validateOnly) {
|
|
|
2400
2431
|
|
|
2401
2432
|
// src/cli/build.ts
|
|
2402
2433
|
var import_commander = require("commander");
|
|
2434
|
+
|
|
2435
|
+
// src/cli/build.helpers.ts
|
|
2436
|
+
function determineRbacMode(opts, cfg) {
|
|
2437
|
+
if (opts.rbacMode) {
|
|
2438
|
+
return opts.rbacMode;
|
|
2439
|
+
}
|
|
2440
|
+
if (cfg.pepr.rbacMode && cfg.pepr.rbacMode !== "scoped") {
|
|
2441
|
+
return "admin";
|
|
2442
|
+
}
|
|
2443
|
+
return cfg.pepr.rbacMode || "admin";
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
// src/cli/build.ts
|
|
2403
2447
|
var peprTS2 = "pepr.ts";
|
|
2404
2448
|
var outputDir = "dist";
|
|
2405
2449
|
function build_default(program2) {
|
|
@@ -2433,7 +2477,9 @@ function build_default(program2) {
|
|
|
2433
2477
|
"Zarf package type: manifest, chart (default: manifest)"
|
|
2434
2478
|
).choices(["manifest", "chart"]).default("manifest")
|
|
2435
2479
|
).addOption(
|
|
2436
|
-
new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(
|
|
2480
|
+
new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(
|
|
2481
|
+
["admin", "scoped"]
|
|
2482
|
+
)
|
|
2437
2483
|
).action(async (opts) => {
|
|
2438
2484
|
if (opts.outputDir) {
|
|
2439
2485
|
outputDir = opts.outputDir;
|
|
@@ -2442,83 +2488,90 @@ function build_default(program2) {
|
|
|
2442
2488
|
process.exit(1);
|
|
2443
2489
|
});
|
|
2444
2490
|
}
|
|
2445
|
-
const
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2491
|
+
const buildModuleResult = await buildModule(void 0, opts.entryPoint, opts.embed);
|
|
2492
|
+
if (buildModuleResult?.cfg && buildModuleResult.path && buildModuleResult.uuid) {
|
|
2493
|
+
const { cfg, path, uuid } = buildModuleResult;
|
|
2494
|
+
const { includedFiles } = cfg.pepr;
|
|
2495
|
+
let image = "";
|
|
2496
|
+
if (opts.customImage) {
|
|
2497
|
+
if (opts.registry) {
|
|
2498
|
+
console.error(`Custom Image and registry cannot be used together.`);
|
|
2499
|
+
process.exit(1);
|
|
2500
|
+
}
|
|
2501
|
+
image = opts.customImage;
|
|
2452
2502
|
}
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
if (opts.timeout !== void 0) {
|
|
2456
|
-
cfg.pepr.webhookTimeout = opts.timeout;
|
|
2457
|
-
}
|
|
2458
|
-
if (opts.registryInfo !== void 0) {
|
|
2459
|
-
console.info(`Including ${includedFiles.length} files in controller image.`);
|
|
2460
|
-
image = `${opts.registryInfo}/custom-pepr-controller:${cfg.pepr.peprVersion}`;
|
|
2461
|
-
if (includedFiles.length > 0) {
|
|
2462
|
-
await createDockerfile(cfg.pepr.peprVersion, cfg.description, includedFiles);
|
|
2463
|
-
(0, import_child_process2.execSync)(`docker build --tag ${image} -f Dockerfile.controller .`, { stdio: "inherit" });
|
|
2464
|
-
(0, import_child_process2.execSync)(`docker push ${image}`, { stdio: "inherit" });
|
|
2503
|
+
if (opts.timeout !== void 0) {
|
|
2504
|
+
cfg.pepr.webhookTimeout = opts.timeout;
|
|
2465
2505
|
}
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2506
|
+
if (opts.registryInfo !== void 0) {
|
|
2507
|
+
console.info(`Including ${includedFiles.length} files in controller image.`);
|
|
2508
|
+
image = `${opts.registryInfo}/custom-pepr-controller:${cfg.pepr.peprVersion}`;
|
|
2509
|
+
if (includedFiles.length > 0) {
|
|
2510
|
+
await createDockerfile(cfg.pepr.peprVersion, cfg.description, includedFiles);
|
|
2511
|
+
(0, import_child_process2.execSync)(`docker build --tag ${image} -f Dockerfile.controller .`, {
|
|
2512
|
+
stdio: "inherit"
|
|
2513
|
+
});
|
|
2514
|
+
(0, import_child_process2.execSync)(`docker push ${image}`, { stdio: "inherit" });
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
if (!opts.embed) {
|
|
2518
|
+
console.info(`\u2705 Module built successfully at ${path}`);
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
if (opts.version) {
|
|
2522
|
+
cfg.pepr.peprVersion = opts.version;
|
|
2523
|
+
}
|
|
2524
|
+
const assets = new Assets(
|
|
2525
|
+
{
|
|
2526
|
+
...cfg.pepr,
|
|
2527
|
+
appVersion: cfg.version,
|
|
2528
|
+
description: cfg.description,
|
|
2529
|
+
// Can override the rbacMode with the CLI option
|
|
2530
|
+
rbacMode: determineRbacMode(opts, cfg)
|
|
2531
|
+
},
|
|
2532
|
+
path
|
|
2533
|
+
);
|
|
2534
|
+
if (opts?.registry === "Iron Bank") {
|
|
2535
|
+
console.info(
|
|
2536
|
+
`
|
|
2485
2537
|
This command assumes the latest release. Pepr's Iron Bank image release cycle is dictated by renovate and is typically released a few days after the GitHub release.
|
|
2486
2538
|
As an alternative you may consider custom --custom-image to target a specific image and version.`
|
|
2487
|
-
);
|
|
2488
|
-
image = `registry1.dso.mil/ironbank/opensource/defenseunicorns/pepr/controller:v${cfg.pepr.peprVersion}`;
|
|
2489
|
-
}
|
|
2490
|
-
if (image !== "") {
|
|
2491
|
-
assets.image = image;
|
|
2492
|
-
}
|
|
2493
|
-
if (opts.withPullSecret) {
|
|
2494
|
-
if (sanitizeResourceName(opts.withPullSecret) !== opts.withPullSecret) {
|
|
2495
|
-
console.error(
|
|
2496
|
-
"Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123."
|
|
2497
2539
|
);
|
|
2540
|
+
image = `registry1.dso.mil/ironbank/opensource/defenseunicorns/pepr/controller:v${cfg.pepr.peprVersion}`;
|
|
2541
|
+
}
|
|
2542
|
+
if (image !== "") {
|
|
2543
|
+
assets.image = image;
|
|
2544
|
+
}
|
|
2545
|
+
if (opts.withPullSecret) {
|
|
2546
|
+
if (sanitizeResourceName(opts.withPullSecret) !== opts.withPullSecret) {
|
|
2547
|
+
console.error(
|
|
2548
|
+
"Invalid imagePullSecret. Please provide a valid name as defined in RFC 1123."
|
|
2549
|
+
);
|
|
2550
|
+
process.exit(1);
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
2554
|
+
const chartPath = `${uuid}-chart`;
|
|
2555
|
+
const yamlPath = (0, import_path2.resolve)(outputDir, yamlFile);
|
|
2556
|
+
const yaml = await assets.allYaml(opts.withPullSecret);
|
|
2557
|
+
try {
|
|
2558
|
+
validateCapabilityNames(assets.capabilities);
|
|
2559
|
+
} catch (e) {
|
|
2560
|
+
console.error(`Error loading capability:`, e);
|
|
2498
2561
|
process.exit(1);
|
|
2499
2562
|
}
|
|
2563
|
+
const zarfPath = (0, import_path2.resolve)(outputDir, "zarf.yaml");
|
|
2564
|
+
let zarf = "";
|
|
2565
|
+
if (opts.zarf === "chart") {
|
|
2566
|
+
zarf = assets.zarfYamlChart(chartPath);
|
|
2567
|
+
} else {
|
|
2568
|
+
zarf = assets.zarfYaml(yamlFile);
|
|
2569
|
+
}
|
|
2570
|
+
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2571
|
+
await import_fs8.promises.writeFile(zarfPath, zarf);
|
|
2572
|
+
await assets.generateHelmChart(outputDir);
|
|
2573
|
+
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
2500
2574
|
}
|
|
2501
|
-
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
2502
|
-
const chartPath = `${uuid}-chart`;
|
|
2503
|
-
const yamlPath = (0, import_path2.resolve)(outputDir, yamlFile);
|
|
2504
|
-
const yaml = await assets.allYaml(opts.rbacMode, opts.withPullSecret);
|
|
2505
|
-
try {
|
|
2506
|
-
validateCapabilityNames(assets.capabilities);
|
|
2507
|
-
} catch (e) {
|
|
2508
|
-
console.error(`Error loading capability:`, e);
|
|
2509
|
-
process.exit(1);
|
|
2510
|
-
}
|
|
2511
|
-
const zarfPath = (0, import_path2.resolve)(outputDir, "zarf.yaml");
|
|
2512
|
-
let zarf = "";
|
|
2513
|
-
if (opts.zarf === "chart") {
|
|
2514
|
-
zarf = assets.zarfYamlChart(chartPath);
|
|
2515
|
-
} else {
|
|
2516
|
-
zarf = assets.zarfYaml(yamlFile);
|
|
2517
|
-
}
|
|
2518
|
-
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2519
|
-
await import_fs8.promises.writeFile(zarfPath, zarf);
|
|
2520
|
-
await assets.generateHelmChart(outputDir);
|
|
2521
|
-
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
2522
2575
|
});
|
|
2523
2576
|
}
|
|
2524
2577
|
var externalLibs = Object.keys(dependencies);
|
|
@@ -2615,34 +2668,32 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
2615
2668
|
return { ctx, path, cfg, uuid };
|
|
2616
2669
|
} catch (e) {
|
|
2617
2670
|
console.error(`Error building module:`, e);
|
|
2618
|
-
if (e.stdout)
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2671
|
+
if (!e.stdout) process.exit(1);
|
|
2672
|
+
const out = e.stdout.toString();
|
|
2673
|
+
const err = e.stderr.toString();
|
|
2674
|
+
console.log(out);
|
|
2675
|
+
console.error(err);
|
|
2676
|
+
if (out.includes("Types have separate declarations of a private property '_name'.")) {
|
|
2677
|
+
const pgkErrMatch = /error TS2322: .*? 'import\("\/.*?\/node_modules\/(.*?)\/node_modules/g;
|
|
2678
|
+
out.matchAll(pgkErrMatch);
|
|
2679
|
+
const conflicts = [...out.matchAll(pgkErrMatch)];
|
|
2680
|
+
if (conflicts.length < 1) {
|
|
2681
|
+
console.info(
|
|
2682
|
+
`
|
|
2630
2683
|
One or more imported Pepr Capabilities seem to be using an incompatible version of Pepr.
|
|
2631
2684
|
Try updating your Pepr Capabilities to their latest versions.`,
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2685
|
+
"Version Conflict"
|
|
2686
|
+
);
|
|
2687
|
+
}
|
|
2688
|
+
conflicts.forEach((match) => {
|
|
2689
|
+
console.info(
|
|
2690
|
+
`
|
|
2638
2691
|
Package '${match[1]}' seems to be incompatible with your current version of Pepr.
|
|
2639
2692
|
Try updating to the latest version.`,
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
}
|
|
2693
|
+
"Version Conflict"
|
|
2694
|
+
);
|
|
2695
|
+
});
|
|
2644
2696
|
}
|
|
2645
|
-
process.exit(1);
|
|
2646
2697
|
}
|
|
2647
2698
|
}
|
|
2648
2699
|
|
|
@@ -2685,26 +2736,29 @@ function deploy_default(program2) {
|
|
|
2685
2736
|
process.exit(0);
|
|
2686
2737
|
}
|
|
2687
2738
|
}
|
|
2688
|
-
const
|
|
2689
|
-
|
|
2690
|
-
{
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2739
|
+
const buildModuleResult = await buildModule();
|
|
2740
|
+
if (buildModuleResult?.cfg && buildModuleResult?.path) {
|
|
2741
|
+
const { cfg, path } = buildModuleResult;
|
|
2742
|
+
const webhook = new Assets(
|
|
2743
|
+
{
|
|
2744
|
+
...cfg.pepr,
|
|
2745
|
+
description: cfg.description
|
|
2746
|
+
},
|
|
2747
|
+
path
|
|
2748
|
+
);
|
|
2749
|
+
if (opts.image) {
|
|
2750
|
+
webhook.image = opts.image;
|
|
2751
|
+
}
|
|
2752
|
+
const timeout = cfg.pepr.webhookTimeout ? cfg.pepr.webhookTimeout : 10;
|
|
2753
|
+
try {
|
|
2754
|
+
await webhook.deploy(opts.force, timeout);
|
|
2755
|
+
validateCapabilityNames(webhook.capabilities);
|
|
2756
|
+
await namespaceDeploymentsReady();
|
|
2757
|
+
console.info(`\u2705 Module deployed successfully`);
|
|
2758
|
+
} catch (e) {
|
|
2759
|
+
console.error(`Error deploying module:`, e);
|
|
2760
|
+
process.exit(1);
|
|
2761
|
+
}
|
|
2708
2762
|
}
|
|
2709
2763
|
});
|
|
2710
2764
|
}
|
|
@@ -2767,8 +2821,8 @@ function dev_default(program2) {
|
|
|
2767
2821
|
await Promise.all([
|
|
2768
2822
|
(0, import_kubernetes_fluent_client5.K8s)(import_kubernetes_fluent_client5.kind.MutatingWebhookConfiguration).Delete(name2),
|
|
2769
2823
|
(0, import_kubernetes_fluent_client5.K8s)(import_kubernetes_fluent_client5.kind.ValidatingWebhookConfiguration).Delete(name2),
|
|
2770
|
-
(0, import_kubernetes_fluent_client5.K8s)(
|
|
2771
|
-
(0, import_kubernetes_fluent_client5.K8s)(
|
|
2824
|
+
(0, import_kubernetes_fluent_client5.K8s)(Store).InNamespace("pepr-system").Delete(scheduleStore),
|
|
2825
|
+
(0, import_kubernetes_fluent_client5.K8s)(Store).InNamespace("pepr-system").Delete(store)
|
|
2772
2826
|
]);
|
|
2773
2827
|
});
|
|
2774
2828
|
process.on("SIGINT", () => {
|
|
@@ -2823,37 +2877,33 @@ function monitor_default(program2) {
|
|
|
2823
2877
|
const respMsg = `"msg":"Check response"`;
|
|
2824
2878
|
const lines = await chunk.toString().split("\n");
|
|
2825
2879
|
for (const line of lines) {
|
|
2826
|
-
if (line.includes(respMsg))
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2880
|
+
if (!line.includes(respMsg)) continue;
|
|
2881
|
+
try {
|
|
2882
|
+
const payload = JSON.parse(line.trim());
|
|
2883
|
+
const isMutate = payload.res.patchType || payload.res.warnings;
|
|
2884
|
+
const name2 = `${payload.namespace}${payload.name}`;
|
|
2885
|
+
const uid = payload.res.uid;
|
|
2886
|
+
if (isMutate) {
|
|
2887
|
+
const plainPatch = payload.res?.patch !== void 0 && payload.res?.patch !== null ? atob(payload.res.patch) : "";
|
|
2888
|
+
const patch = plainPatch !== "" && JSON.stringify(JSON.parse(plainPatch), null, 2);
|
|
2889
|
+
const patchType = payload.res.patchType || payload.res.warnings || "";
|
|
2890
|
+
const allowOrDeny = payload.res.allowed ? "\u{1F500}" : "\u{1F6AB}";
|
|
2891
|
+
console.log(`
|
|
2838
2892
|
${allowOrDeny} MUTATE ${name2} (${uid})`);
|
|
2839
|
-
|
|
2840
|
-
console.log(`
|
|
2893
|
+
patchType.length > 0 && console.log(`
|
|
2841
2894
|
\x1B[1;34m${patch}\x1B[0m`);
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
|
-
\u2705 VALIDATE ${name2} (${uid})`);
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
|
-
} catch {
|
|
2895
|
+
} else {
|
|
2896
|
+
const failures = Array.isArray(payload.res) ? payload.res : [payload.res];
|
|
2897
|
+
const filteredFailures = failures.filter((r) => !r.allowed).map((r) => r.status.message);
|
|
2898
|
+
console.log(
|
|
2899
|
+
`
|
|
2900
|
+
${filteredFailures.length > 0 ? "\u274C" : "\u2705"} VALIDATE ${name2} (${uid})`
|
|
2901
|
+
);
|
|
2902
|
+
console.log(
|
|
2903
|
+
filteredFailures.length > 0 ? `\x1B[1;31m${filteredFailures}\x1B[0m` : ""
|
|
2904
|
+
);
|
|
2856
2905
|
}
|
|
2906
|
+
} catch {
|
|
2857
2907
|
}
|
|
2858
2908
|
}
|
|
2859
2909
|
});
|
|
@@ -3029,19 +3079,7 @@ function init_default(program2) {
|
|
|
3029
3079
|
await write((0, import_path3.resolve)(dirName, "capabilities", samplesYaml.path), samplesYaml.data);
|
|
3030
3080
|
await write((0, import_path3.resolve)(dirName, "capabilities", helloPepr.path), helloPepr.data);
|
|
3031
3081
|
if (!opts.skipPostInit) {
|
|
3032
|
-
|
|
3033
|
-
(0, import_child_process4.execSync)("npm install", {
|
|
3034
|
-
stdio: "inherit"
|
|
3035
|
-
});
|
|
3036
|
-
(0, import_child_process4.execSync)("git init --initial-branch=main", {
|
|
3037
|
-
stdio: "inherit"
|
|
3038
|
-
});
|
|
3039
|
-
try {
|
|
3040
|
-
(0, import_child_process4.execSync)("code .", {
|
|
3041
|
-
stdio: "inherit"
|
|
3042
|
-
});
|
|
3043
|
-
} catch (e) {
|
|
3044
|
-
}
|
|
3082
|
+
doPostInitActions(dirName);
|
|
3045
3083
|
}
|
|
3046
3084
|
console.log(`New Pepr module created at ${dirName}`);
|
|
3047
3085
|
console.log(`Open VSCode or your editor of choice in ${dirName} to get started!`);
|
|
@@ -3054,6 +3092,21 @@ function init_default(program2) {
|
|
|
3054
3092
|
}
|
|
3055
3093
|
});
|
|
3056
3094
|
}
|
|
3095
|
+
var doPostInitActions = (dirName) => {
|
|
3096
|
+
process.chdir(dirName);
|
|
3097
|
+
(0, import_child_process4.execSync)("npm install", {
|
|
3098
|
+
stdio: "inherit"
|
|
3099
|
+
});
|
|
3100
|
+
(0, import_child_process4.execSync)("git init --initial-branch=main", {
|
|
3101
|
+
stdio: "inherit"
|
|
3102
|
+
});
|
|
3103
|
+
try {
|
|
3104
|
+
(0, import_child_process4.execSync)("code .", {
|
|
3105
|
+
stdio: "inherit"
|
|
3106
|
+
});
|
|
3107
|
+
} catch (e) {
|
|
3108
|
+
}
|
|
3109
|
+
};
|
|
3057
3110
|
|
|
3058
3111
|
// src/cli/uuid.ts
|
|
3059
3112
|
var import_kubernetes_fluent_client7 = require("kubernetes-fluent-client");
|