pepr 0.42.1 → 0.42.2
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/deploy.d.ts +15 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.helpers.d.ts +3 -0
- package/dist/cli/format.helpers.d.ts.map +1 -0
- package/dist/cli/init/enums.d.ts +10 -0
- package/dist/cli/init/enums.d.ts.map +1 -0
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +15 -11
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/init/utils.d.ts.map +1 -1
- package/dist/cli/init/walkthrough.d.ts +3 -2
- package/dist/cli/init/walkthrough.d.ts.map +1 -1
- package/dist/cli/kfc.d.ts.map +1 -1
- package/dist/cli/root.d.ts.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +145 -306
- package/dist/controller.js +1 -195
- package/dist/fixtures/loader.d.ts.map +1 -1
- package/dist/lib/assets/deploy.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/pods.d.ts +1 -3
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts +2 -2
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +1 -1
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts +1 -1
- package/dist/lib/controller/storeCache.d.ts.map +1 -1
- package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
- package/dist/lib/core/capability.d.ts.map +1 -0
- package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
- package/dist/lib/core/module.d.ts.map +1 -0
- package/dist/lib/core/queue.d.ts.map +1 -0
- package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
- package/dist/lib/core/schedule.d.ts.map +1 -0
- package/dist/lib/core/storage.d.ts.map +1 -0
- package/dist/lib/deploymentChecks.d.ts.map +1 -1
- package/dist/lib/errors.d.ts +0 -5
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/filesystemService.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
- package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
- package/dist/lib/filter/filter.d.ts +33 -1
- package/dist/lib/filter/filter.d.ts.map +1 -1
- package/dist/lib/finalizer.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +4 -9
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/included-files.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/processors/mutate-processor.d.ts +28 -0
- package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
- package/dist/lib/{validate-processor.d.ts → processors/validate-processor.d.ts} +5 -5
- package/dist/lib/processors/validate-processor.d.ts.map +1 -0
- package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
- package/dist/lib/processors/watch-processor.d.ts.map +1 -0
- package/dist/lib/telemetry/logger.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts +2 -2
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +383 -243
- package/dist/lib.js.map +4 -4
- package/dist/sdk/heredoc.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/cli/deploy.ts +113 -74
- package/src/cli/dev.ts +2 -2
- package/src/cli/format.helpers.ts +27 -0
- package/src/cli/format.ts +4 -18
- package/src/cli/init/enums.ts +9 -0
- package/src/cli/init/index.ts +4 -3
- package/src/cli/init/templates.ts +30 -2
- package/src/cli/init/utils.ts +3 -3
- package/src/cli/init/walkthrough.ts +7 -8
- package/src/cli/kfc.ts +1 -1
- package/src/cli/root.ts +1 -1
- package/src/cli/update.ts +1 -1
- package/src/cli/uuid.ts +1 -1
- package/src/fixtures/loader.ts +2 -2
- package/src/lib/assets/deploy.ts +5 -5
- package/src/lib/assets/index.ts +1 -1
- package/src/lib/assets/pods.ts +1 -1
- package/src/lib/assets/webhooks.ts +30 -45
- package/src/lib/controller/index.ts +4 -4
- package/src/lib/controller/store.ts +2 -2
- package/src/lib/controller/storeCache.ts +6 -2
- package/src/lib/{capability.ts → core/capability.ts} +4 -4
- package/src/lib/{module.ts → core/module.ts} +10 -10
- package/src/lib/{queue.ts → core/queue.ts} +1 -1
- package/src/lib/deploymentChecks.ts +2 -2
- package/src/lib/errors.ts +3 -8
- package/src/lib/filesystemService.ts +1 -1
- package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
- package/src/lib/filter/filter.ts +204 -111
- package/src/lib/finalizer.ts +2 -2
- package/src/lib/helpers.ts +20 -133
- package/src/lib/included-files.ts +1 -1
- package/src/lib/processors/mutate-processor.ts +225 -0
- package/src/lib/{validate-processor.ts → processors/validate-processor.ts} +8 -8
- package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +8 -8
- package/src/lib/telemetry/logger.ts +3 -1
- package/src/lib/tls.ts +5 -1
- package/src/lib/validate-request.ts +4 -4
- package/src/lib.ts +2 -2
- package/src/runtime/controller.ts +2 -2
- package/src/sdk/heredoc.ts +1 -1
- package/dist/lib/capability.d.ts.map +0 -1
- package/dist/lib/module.d.ts.map +0 -1
- package/dist/lib/mutate-processor.d.ts +0 -6
- package/dist/lib/mutate-processor.d.ts.map +0 -1
- package/dist/lib/queue.d.ts.map +0 -1
- package/dist/lib/schedule.d.ts.map +0 -1
- package/dist/lib/storage.d.ts.map +0 -1
- package/dist/lib/validate-processor.d.ts.map +0 -1
- package/dist/lib/watch-processor.d.ts.map +0 -1
- package/src/lib/mutate-processor.ts +0 -165
- /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
- /package/dist/lib/{storage.d.ts → core/storage.d.ts} +0 -0
- /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
- /package/src/lib/{storage.ts → core/storage.ts} +0 -0
package/dist/cli.js
CHANGED
|
@@ -267,200 +267,6 @@ function sanitizeResourceName(name2) {
|
|
|
267
267
|
return name2.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
// src/lib/filter/adjudicators/adjudicators.ts
|
|
271
|
-
var import_ramda = require("ramda");
|
|
272
|
-
var declaredOperation = (0, import_ramda.pipe)(
|
|
273
|
-
(request) => request?.operation,
|
|
274
|
-
(0, import_ramda.defaultTo)("")
|
|
275
|
-
);
|
|
276
|
-
var declaredGroup = (0, import_ramda.pipe)(
|
|
277
|
-
(request) => request?.kind?.group,
|
|
278
|
-
(0, import_ramda.defaultTo)("")
|
|
279
|
-
);
|
|
280
|
-
var declaredVersion = (0, import_ramda.pipe)(
|
|
281
|
-
(request) => request?.kind?.version,
|
|
282
|
-
(0, import_ramda.defaultTo)("")
|
|
283
|
-
);
|
|
284
|
-
var declaredKind = (0, import_ramda.pipe)(
|
|
285
|
-
(request) => request?.kind?.kind,
|
|
286
|
-
(0, import_ramda.defaultTo)("")
|
|
287
|
-
);
|
|
288
|
-
var declaredUid = (0, import_ramda.pipe)((request) => request?.uid, (0, import_ramda.defaultTo)(""));
|
|
289
|
-
var carriesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
290
|
-
(kubernetesObject) => !!kubernetesObject.metadata?.deletionTimestamp,
|
|
291
|
-
(0, import_ramda.defaultTo)(false)
|
|
292
|
-
);
|
|
293
|
-
var missingDeletionTimestamp = (0, import_ramda.complement)(carriesDeletionTimestamp);
|
|
294
|
-
var carriedKind = (0, import_ramda.pipe)(
|
|
295
|
-
(kubernetesObject) => kubernetesObject?.kind,
|
|
296
|
-
(0, import_ramda.defaultTo)("not set")
|
|
297
|
-
);
|
|
298
|
-
var carriedVersion = (0, import_ramda.pipe)(
|
|
299
|
-
(kubernetesObject) => kubernetesObject?.metadata?.resourceVersion,
|
|
300
|
-
(0, import_ramda.defaultTo)("not set")
|
|
301
|
-
);
|
|
302
|
-
var carriedName = (0, import_ramda.pipe)(
|
|
303
|
-
(kubernetesObject) => kubernetesObject?.metadata?.name,
|
|
304
|
-
(0, import_ramda.defaultTo)("")
|
|
305
|
-
);
|
|
306
|
-
var carriesName = (0, import_ramda.pipe)(carriedName, (0, import_ramda.equals)(""), import_ramda.not);
|
|
307
|
-
var missingName = (0, import_ramda.complement)(carriesName);
|
|
308
|
-
var carriedNamespace = (0, import_ramda.pipe)(
|
|
309
|
-
(kubernetesObject) => kubernetesObject?.metadata?.namespace,
|
|
310
|
-
(0, import_ramda.defaultTo)("")
|
|
311
|
-
);
|
|
312
|
-
var carriesNamespace = (0, import_ramda.pipe)(carriedNamespace, (0, import_ramda.equals)(""), import_ramda.not);
|
|
313
|
-
var carriedAnnotations = (0, import_ramda.pipe)(
|
|
314
|
-
(kubernetesObject) => kubernetesObject?.metadata?.annotations,
|
|
315
|
-
(0, import_ramda.defaultTo)({})
|
|
316
|
-
);
|
|
317
|
-
var carriesAnnotations = (0, import_ramda.pipe)(carriedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
|
|
318
|
-
var carriedLabels = (0, import_ramda.pipe)(
|
|
319
|
-
(kubernetesObject) => kubernetesObject?.metadata?.labels,
|
|
320
|
-
(0, import_ramda.defaultTo)({})
|
|
321
|
-
);
|
|
322
|
-
var carriesLabels = (0, import_ramda.pipe)(carriedLabels, (0, import_ramda.equals)({}), import_ramda.not);
|
|
323
|
-
var definesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
324
|
-
(binding) => binding?.filters?.deletionTimestamp ?? false,
|
|
325
|
-
(0, import_ramda.defaultTo)(false)
|
|
326
|
-
);
|
|
327
|
-
var ignoresDeletionTimestamp = (0, import_ramda.complement)(definesDeletionTimestamp);
|
|
328
|
-
var definedName = (0, import_ramda.pipe)((binding) => {
|
|
329
|
-
return binding.filters.name;
|
|
330
|
-
}, (0, import_ramda.defaultTo)(""));
|
|
331
|
-
var definesName = (0, import_ramda.pipe)(definedName, (0, import_ramda.equals)(""), import_ramda.not);
|
|
332
|
-
var ignoresName = (0, import_ramda.complement)(definesName);
|
|
333
|
-
var definedNameRegex = (0, import_ramda.pipe)(
|
|
334
|
-
(binding) => binding.filters?.regexName,
|
|
335
|
-
(0, import_ramda.defaultTo)("")
|
|
336
|
-
);
|
|
337
|
-
var definesNameRegex = (0, import_ramda.pipe)(definedNameRegex, (0, import_ramda.equals)(""), import_ramda.not);
|
|
338
|
-
var definedNamespaces = (0, import_ramda.pipe)((binding) => binding?.filters?.namespaces, (0, import_ramda.defaultTo)([]));
|
|
339
|
-
var definesNamespaces = (0, import_ramda.pipe)(definedNamespaces, (0, import_ramda.equals)([]), import_ramda.not);
|
|
340
|
-
var definedNamespaceRegexes = (0, import_ramda.pipe)((binding) => binding?.filters?.regexNamespaces, (0, import_ramda.defaultTo)([]));
|
|
341
|
-
var definesNamespaceRegexes = (0, import_ramda.pipe)(definedNamespaceRegexes, (0, import_ramda.equals)([]), import_ramda.not);
|
|
342
|
-
var definedAnnotations = (0, import_ramda.pipe)((binding) => binding?.filters?.annotations, (0, import_ramda.defaultTo)({}));
|
|
343
|
-
var definesAnnotations = (0, import_ramda.pipe)(definedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
|
|
344
|
-
var definedLabels = (0, import_ramda.pipe)((binding) => binding?.filters?.labels, (0, import_ramda.defaultTo)({}));
|
|
345
|
-
var definesLabels = (0, import_ramda.pipe)(definedLabels, (0, import_ramda.equals)({}), import_ramda.not);
|
|
346
|
-
var definedEvent = (binding) => {
|
|
347
|
-
return binding.event;
|
|
348
|
-
};
|
|
349
|
-
var definesDelete = (0, import_ramda.pipe)(definedEvent, (0, import_ramda.equals)("DELETE" /* DELETE */));
|
|
350
|
-
var definedGroup = (0, import_ramda.pipe)((binding) => binding?.kind?.group, (0, import_ramda.defaultTo)(""));
|
|
351
|
-
var definesGroup = (0, import_ramda.pipe)(definedGroup, (0, import_ramda.equals)(""), import_ramda.not);
|
|
352
|
-
var definedVersion = (0, import_ramda.pipe)(
|
|
353
|
-
(binding) => binding?.kind?.version,
|
|
354
|
-
(0, import_ramda.defaultTo)("")
|
|
355
|
-
);
|
|
356
|
-
var definesVersion = (0, import_ramda.pipe)(definedVersion, (0, import_ramda.equals)(""), import_ramda.not);
|
|
357
|
-
var definedKind = (0, import_ramda.pipe)((binding) => binding?.kind?.kind, (0, import_ramda.defaultTo)(""));
|
|
358
|
-
var definesKind = (0, import_ramda.pipe)(definedKind, (0, import_ramda.equals)(""), import_ramda.not);
|
|
359
|
-
var definedCallback = (binding) => {
|
|
360
|
-
return binding.isFinalize ? binding.finalizeCallback : binding.isWatch ? binding.watchCallback : binding.isMutate ? binding.mutateCallback : binding.isValidate ? binding.validateCallback : null;
|
|
361
|
-
};
|
|
362
|
-
var definedCallbackName = (0, import_ramda.pipe)(definedCallback, (0, import_ramda.defaultTo)({ name: "" }), (callback) => callback.name);
|
|
363
|
-
var mismatchedDeletionTimestamp = (0, import_ramda.allPass)([
|
|
364
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesDeletionTimestamp),
|
|
365
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), missingDeletionTimestamp)
|
|
366
|
-
]);
|
|
367
|
-
var mismatchedName = (0, import_ramda.allPass)([
|
|
368
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesName),
|
|
369
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => definedName(binding) !== carriedName(kubernetesObject))
|
|
370
|
-
]);
|
|
371
|
-
var mismatchedNameRegex = (0, import_ramda.allPass)([
|
|
372
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNameRegex),
|
|
373
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => new RegExp(definedNameRegex(binding)).test(carriedName(kubernetesObject)), import_ramda.not)
|
|
374
|
-
]);
|
|
375
|
-
var bindsToKind = (0, import_ramda.curry)(
|
|
376
|
-
(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)])
|
|
377
|
-
);
|
|
378
|
-
var bindsToNamespace = (0, import_ramda.curry)((0, import_ramda.pipe)(bindsToKind(import_ramda.__, "Namespace")));
|
|
379
|
-
var misboundNamespace = (0, import_ramda.allPass)([bindsToNamespace, definesNamespaces]);
|
|
380
|
-
var mismatchedNamespace = (0, import_ramda.allPass)([
|
|
381
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaces),
|
|
382
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => definedNamespaces(binding).includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
383
|
-
]);
|
|
384
|
-
var mismatchedNamespaceRegex = (0, import_ramda.allPass)([
|
|
385
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaceRegexes),
|
|
386
|
-
(0, import_ramda.pipe)(
|
|
387
|
-
(binding, kubernetesObject) => (0, import_ramda.pipe)(
|
|
388
|
-
(0, import_ramda.any)((regEx) => new RegExp(regEx).test(carriedNamespace(kubernetesObject))),
|
|
389
|
-
import_ramda.not
|
|
390
|
-
)(definedNamespaceRegexes(binding))
|
|
391
|
-
)
|
|
392
|
-
]);
|
|
393
|
-
var metasMismatch = (0, import_ramda.pipe)(
|
|
394
|
-
(defined, carried) => {
|
|
395
|
-
const result = { defined, carried, unalike: {} };
|
|
396
|
-
result.unalike = Object.entries(result.defined).map(([key, value]) => {
|
|
397
|
-
const keyMissing = !Object.hasOwn(result.carried, key);
|
|
398
|
-
const noValue = !value;
|
|
399
|
-
const valMissing = !result.carried[key];
|
|
400
|
-
const valDiffers = result.carried[key] !== result.defined[key];
|
|
401
|
-
return keyMissing ? { [key]: value } : noValue ? {} : valMissing ? { [key]: value } : valDiffers ? { [key]: value } : {};
|
|
402
|
-
}).reduce((acc, cur) => ({ ...acc, ...cur }), {});
|
|
403
|
-
return result.unalike;
|
|
404
|
-
},
|
|
405
|
-
(unalike) => Object.keys(unalike).length > 0
|
|
406
|
-
);
|
|
407
|
-
var mismatchedAnnotations = (0, import_ramda.allPass)([
|
|
408
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesAnnotations),
|
|
409
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedAnnotations(binding), carriedAnnotations(kubernetesObject)))
|
|
410
|
-
]);
|
|
411
|
-
var mismatchedLabels = (0, import_ramda.allPass)([
|
|
412
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesLabels),
|
|
413
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedLabels(binding), carriedLabels(kubernetesObject)))
|
|
414
|
-
]);
|
|
415
|
-
var uncarryableNamespace = (0, import_ramda.allPass)([
|
|
416
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
417
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
418
|
-
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
419
|
-
]);
|
|
420
|
-
var missingCarriableNamespace = (0, import_ramda.allPass)([
|
|
421
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
422
|
-
(0, import_ramda.pipe)(
|
|
423
|
-
(namespaceSelector, kubernetesObject) => kubernetesObject.kind === "Namespace" ? !namespaceSelector.includes(kubernetesObject.metadata.name) : !carriesNamespace(kubernetesObject)
|
|
424
|
-
)
|
|
425
|
-
]);
|
|
426
|
-
var carriesIgnoredNamespace = (0, import_ramda.allPass)([
|
|
427
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
428
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
429
|
-
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)))
|
|
430
|
-
]);
|
|
431
|
-
var unbindableNamespaces = (0, import_ramda.allPass)([
|
|
432
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
433
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), definesNamespaces),
|
|
434
|
-
(0, import_ramda.pipe)(
|
|
435
|
-
(namespaceSelector, binding) => (0, import_ramda.difference)(definedNamespaces(binding), namespaceSelector),
|
|
436
|
-
import_ramda.length,
|
|
437
|
-
(0, import_ramda.equals)(0),
|
|
438
|
-
import_ramda.not
|
|
439
|
-
)
|
|
440
|
-
]);
|
|
441
|
-
var misboundDeleteWithDeletionTimestamp = (0, import_ramda.allPass)([definesDelete, definesDeletionTimestamp]);
|
|
442
|
-
var operationMatchesEvent = (0, import_ramda.anyPass)([
|
|
443
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), (0, import_ramda.equals)("*" /* ANY */)),
|
|
444
|
-
(0, import_ramda.pipe)((operation, event) => operation.valueOf() === event.valueOf()),
|
|
445
|
-
(0, import_ramda.pipe)((operation, event) => operation ? event.includes(operation) : false)
|
|
446
|
-
]);
|
|
447
|
-
var mismatchedEvent = (0, import_ramda.pipe)(
|
|
448
|
-
(binding, request) => operationMatchesEvent(declaredOperation(request), definedEvent(binding)),
|
|
449
|
-
import_ramda.not
|
|
450
|
-
);
|
|
451
|
-
var mismatchedGroup = (0, import_ramda.allPass)([
|
|
452
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesGroup),
|
|
453
|
-
(0, import_ramda.pipe)((binding, request) => definedGroup(binding) !== declaredGroup(request))
|
|
454
|
-
]);
|
|
455
|
-
var mismatchedVersion = (0, import_ramda.allPass)([
|
|
456
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesVersion),
|
|
457
|
-
(0, import_ramda.pipe)((binding, request) => definedVersion(binding) !== declaredVersion(request))
|
|
458
|
-
]);
|
|
459
|
-
var mismatchedKind = (0, import_ramda.allPass)([
|
|
460
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesKind),
|
|
461
|
-
(0, import_ramda.pipe)((binding, request) => definedKind(binding) !== declaredKind(request))
|
|
462
|
-
]);
|
|
463
|
-
|
|
464
270
|
// src/lib/helpers.ts
|
|
465
271
|
function matchesRegex(pattern, testString) {
|
|
466
272
|
return new RegExp(pattern).test(testString);
|
|
@@ -555,7 +361,11 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
555
361
|
`Error in ${name2} capability. A binding violates namespace rules. Please check ignoredNamespaces and capability namespaces: ${namespaceError}`
|
|
556
362
|
);
|
|
557
363
|
}
|
|
558
|
-
|
|
364
|
+
matchRegexToCapababilityNamespace(bindingRegexNamespaces, capabilityNamespaces);
|
|
365
|
+
checkRegexNamespaces(bindingRegexNamespaces, ignoredNamespaces);
|
|
366
|
+
}
|
|
367
|
+
var matchRegexToCapababilityNamespace = (bindingRegexNamespaces, capabilityNamespaces) => {
|
|
368
|
+
if (bindingRegexNamespaces.length > 0 && capabilityNamespaces && capabilityNamespaces.length > 0) {
|
|
559
369
|
for (const regexNamespace of bindingRegexNamespaces) {
|
|
560
370
|
let matches = false;
|
|
561
371
|
matches = regexNamespace !== "" && capabilityNamespaces.some((capabilityNamespace) => matchesRegex(regexNamespace, capabilityNamespace));
|
|
@@ -566,7 +376,9 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
566
376
|
}
|
|
567
377
|
}
|
|
568
378
|
}
|
|
569
|
-
|
|
379
|
+
};
|
|
380
|
+
var checkRegexNamespaces = (bindingRegexNamespaces, ignoredNamespaces) => {
|
|
381
|
+
if (bindingRegexNamespaces.length > 0 && ignoredNamespaces && ignoredNamespaces.length > 0) {
|
|
570
382
|
for (const regexNamespace of bindingRegexNamespaces) {
|
|
571
383
|
const matchedNS = ignoredNamespaces.find((ignoredNS) => matchesRegex(regexNamespace, ignoredNS));
|
|
572
384
|
if (matchedNS) {
|
|
@@ -576,7 +388,7 @@ function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
|
576
388
|
}
|
|
577
389
|
}
|
|
578
390
|
}
|
|
579
|
-
}
|
|
391
|
+
};
|
|
580
392
|
function secretOverLimit(str) {
|
|
581
393
|
const encoder = new TextEncoder();
|
|
582
394
|
const encoded = encoder.encode(str);
|
|
@@ -584,7 +396,7 @@ function secretOverLimit(str) {
|
|
|
584
396
|
const oneMiBInBytes = 1048576;
|
|
585
397
|
return sizeInBytes > oneMiBInBytes;
|
|
586
398
|
}
|
|
587
|
-
var parseTimeout = (value
|
|
399
|
+
var parseTimeout = (value) => {
|
|
588
400
|
const parsedValue = parseInt(value, 10);
|
|
589
401
|
const floatValue = parseFloat(value);
|
|
590
402
|
if (isNaN(parsedValue)) {
|
|
@@ -1118,51 +930,40 @@ var peprStoreCRD = {
|
|
|
1118
930
|
};
|
|
1119
931
|
|
|
1120
932
|
// src/lib/assets/webhooks.ts
|
|
1121
|
-
var
|
|
933
|
+
var import_ramda = require("ramda");
|
|
1122
934
|
var peprIgnoreLabel = {
|
|
1123
935
|
key: "pepr.dev",
|
|
1124
936
|
operator: "NotIn",
|
|
1125
937
|
values: ["ignore"]
|
|
1126
938
|
};
|
|
1127
939
|
var peprIgnoreNamespaces = ["kube-system", "pepr-system"];
|
|
940
|
+
var validateRule = (binding, isMutateWebhook) => {
|
|
941
|
+
const { event, kind: kind8, isMutate, isValidate } = binding;
|
|
942
|
+
if (isMutateWebhook && !isMutate || !isMutateWebhook && !isValidate) {
|
|
943
|
+
return void 0;
|
|
944
|
+
}
|
|
945
|
+
const operations = event === "CREATEORUPDATE" /* CREATE_OR_UPDATE */ ? ["CREATE" /* CREATE */, "UPDATE" /* UPDATE */] : [event];
|
|
946
|
+
const resource = kind8.plural || `${kind8.kind.toLowerCase()}s`;
|
|
947
|
+
const ruleObject = {
|
|
948
|
+
apiGroups: [kind8.group],
|
|
949
|
+
apiVersions: [kind8.version || "*"],
|
|
950
|
+
operations,
|
|
951
|
+
resources: [resource, ...resource === "pods" ? ["pods/ephemeralcontainers"] : []]
|
|
952
|
+
};
|
|
953
|
+
return ruleObject;
|
|
954
|
+
};
|
|
1128
955
|
async function generateWebhookRules(assets, isMutateWebhook) {
|
|
1129
956
|
const { config, capabilities } = assets;
|
|
1130
|
-
const rules =
|
|
1131
|
-
for (const capability of capabilities) {
|
|
957
|
+
const rules = capabilities.flatMap((capability) => {
|
|
1132
958
|
console.info(`Module ${config.uuid} has capability: ${capability.name}`);
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
continue;
|
|
1137
|
-
}
|
|
1138
|
-
if (!isMutateWebhook && !isValidate) {
|
|
1139
|
-
continue;
|
|
1140
|
-
}
|
|
1141
|
-
const operations = [];
|
|
1142
|
-
if (event === "CREATEORUPDATE" /* CREATE_OR_UPDATE */) {
|
|
1143
|
-
operations.push("CREATE" /* CREATE */, "UPDATE" /* UPDATE */);
|
|
1144
|
-
} else {
|
|
1145
|
-
operations.push(event);
|
|
1146
|
-
}
|
|
1147
|
-
const resource = kind8.plural || `${kind8.kind.toLowerCase()}s`;
|
|
1148
|
-
const ruleObject = {
|
|
1149
|
-
apiGroups: [kind8.group],
|
|
1150
|
-
apiVersions: [kind8.version || "*"],
|
|
1151
|
-
operations,
|
|
1152
|
-
resources: [resource]
|
|
1153
|
-
};
|
|
1154
|
-
if (resource === "pods") {
|
|
1155
|
-
ruleObject.resources.push("pods/ephemeralcontainers");
|
|
1156
|
-
}
|
|
1157
|
-
rules.push(ruleObject);
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
return (0, import_ramda2.uniqWith)(import_ramda2.equals, rules);
|
|
959
|
+
return capability.bindings.map((binding) => validateRule(binding, isMutateWebhook)).filter((rule) => !!rule);
|
|
960
|
+
});
|
|
961
|
+
return (0, import_ramda.uniqWith)(import_ramda.equals, rules);
|
|
1161
962
|
}
|
|
1162
963
|
async function webhookConfig(assets, mutateOrValidate, timeoutSeconds = 10) {
|
|
1163
964
|
const ignore = [peprIgnoreLabel];
|
|
1164
965
|
const { name: name2, tls, config, apiToken, host } = assets;
|
|
1165
|
-
const ignoreNS = (0,
|
|
966
|
+
const ignoreNS = (0, import_ramda.concat)(peprIgnoreNamespaces, config?.alwaysIgnore?.namespaces || []);
|
|
1166
967
|
if (ignoreNS) {
|
|
1167
968
|
ignore.push({
|
|
1168
969
|
key: "kubernetes.io/metadata.name",
|
|
@@ -2206,7 +2007,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
2206
2007
|
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';
|
|
2207
2008
|
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';
|
|
2208
2009
|
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\nimport { MockAgent, setGlobalDispatcher } from "undici";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\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 const mockAgent: MockAgent = new MockAgent();\n setGlobalDispatcher(mockAgent);\n const mockClient = mockAgent.get(jokeURL);\n mockClient.intercept({ path: "/", method: "GET" }).reply(\n 200,\n {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\n },\n {\n headers: {\n "Content-Type": "application/json; charset=utf-8",\n },\n },\n );\n\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(jokeURL, {\n headers: {\n Accept: "application/json",\n },\n });\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n const { joke } = response.data;\n // Add Joke to the Store\n await Store.setItemAndWait(jokeURL, joke);\n // Add the Chuck Norris joke to the configmap\n try {\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: cm.metadata.name,\n namespace: cm.metadata.namespace,\n },\n data: {\n "chuck-says": Store.getItem(jokeURL),\n },\n });\n } catch (error) {\n Log.error(error, "Failed to apply ConfigMap using server-side apply.", {\n cm,\n });\n }\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
|
|
2209
|
-
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.42.
|
|
2010
|
+
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.42.2", 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.2", "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.7", pino: "9.6.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.0.0" }, devDependencies: { "@commitlint/cli": "19.6.1", "@commitlint/config-conventional": "19.6.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", "ts-jest": "29.2.5", undici: "^7.0.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", "@types/prompts": "2.4.9", eslint: "8.57.0", commander: "12.1.0", esbuild: "0.24.0", "node-forge": "1.3.1", prettier: "3.4.2", prompts: "2.4.2", typescript: "^5.3.3", uuid: "11.0.3" } };
|
|
2210
2011
|
|
|
2211
2012
|
// src/templates/pepr.code-snippets.json
|
|
2212
2013
|
var pepr_code_snippets_default = {
|
|
@@ -2393,8 +2194,27 @@ var import_commander = require("commander");
|
|
|
2393
2194
|
|
|
2394
2195
|
// src/cli/format.ts
|
|
2395
2196
|
var import_eslint = require("eslint");
|
|
2197
|
+
|
|
2198
|
+
// src/cli/format.helpers.ts
|
|
2396
2199
|
var import_fs6 = require("fs");
|
|
2397
2200
|
var import_prettier = require("prettier");
|
|
2201
|
+
async function formatWithPrettier(results, validateOnly) {
|
|
2202
|
+
let hasFailure = false;
|
|
2203
|
+
for (const { filePath } of results) {
|
|
2204
|
+
const content = await import_fs6.promises.readFile(filePath, "utf8");
|
|
2205
|
+
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
2206
|
+
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
2207
|
+
if (validateOnly && formatted !== content) {
|
|
2208
|
+
hasFailure = true;
|
|
2209
|
+
console.error(`File ${filePath} is not formatted correctly`);
|
|
2210
|
+
} else {
|
|
2211
|
+
await import_fs6.promises.writeFile(filePath, formatted);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
return hasFailure;
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
// src/cli/format.ts
|
|
2398
2218
|
function format_default(program2) {
|
|
2399
2219
|
program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
|
|
2400
2220
|
const success = await peprFormat(opts.validateOnly);
|
|
@@ -2425,17 +2245,7 @@ async function peprFormat(validateOnly) {
|
|
|
2425
2245
|
if (!validateOnly) {
|
|
2426
2246
|
await import_eslint.ESLint.outputFixes(results);
|
|
2427
2247
|
}
|
|
2428
|
-
|
|
2429
|
-
const content = await import_fs6.promises.readFile(filePath, "utf8");
|
|
2430
|
-
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
2431
|
-
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
2432
|
-
if (validateOnly && formatted !== content) {
|
|
2433
|
-
hasFailure = true;
|
|
2434
|
-
console.error(`File ${filePath} is not formatted correctly`);
|
|
2435
|
-
} else {
|
|
2436
|
-
await import_fs6.promises.writeFile(filePath, formatted);
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2248
|
+
hasFailure = await formatWithPrettier(results, validateOnly);
|
|
2439
2249
|
return !hasFailure;
|
|
2440
2250
|
} catch (e) {
|
|
2441
2251
|
console.error(`Error formatting module:`, e);
|
|
@@ -2804,66 +2614,92 @@ async function namespaceDeploymentsReady(namespace = "pepr-system") {
|
|
|
2804
2614
|
}
|
|
2805
2615
|
|
|
2806
2616
|
// src/cli/deploy.ts
|
|
2617
|
+
function validateImagePullSecretDetails(details) {
|
|
2618
|
+
if (!details.pullSecret) {
|
|
2619
|
+
return { valid: true };
|
|
2620
|
+
}
|
|
2621
|
+
if (details.pullSecret !== sanitizeName(details.pullSecret)) {
|
|
2622
|
+
return {
|
|
2623
|
+
valid: false,
|
|
2624
|
+
error: `Invalid --pullSecret. Must be valid name as defined in RFC 1123.`
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
const missing = [];
|
|
2628
|
+
if (!details.dockerEmail) {
|
|
2629
|
+
missing.push("--docker-email");
|
|
2630
|
+
}
|
|
2631
|
+
if (!details.dockerServer) {
|
|
2632
|
+
missing.push("--docker-server");
|
|
2633
|
+
}
|
|
2634
|
+
if (!details.dockerUsername) {
|
|
2635
|
+
missing.push("--docker-username");
|
|
2636
|
+
}
|
|
2637
|
+
if (!details.dockerPassword) {
|
|
2638
|
+
missing.push("--docker-password");
|
|
2639
|
+
}
|
|
2640
|
+
if (missing.length > 0) {
|
|
2641
|
+
return {
|
|
2642
|
+
valid: false,
|
|
2643
|
+
error: `Error: Must provide ${missing.join(", ")} when providing --pullSecret`
|
|
2644
|
+
};
|
|
2645
|
+
}
|
|
2646
|
+
return { valid: true };
|
|
2647
|
+
}
|
|
2648
|
+
function generateImagePullSecret(details) {
|
|
2649
|
+
const auth = Buffer.from(`${details.dockerUsername}:${details.dockerPassword}`).toString(
|
|
2650
|
+
"base64"
|
|
2651
|
+
);
|
|
2652
|
+
return {
|
|
2653
|
+
auths: {
|
|
2654
|
+
[details.dockerServer]: {
|
|
2655
|
+
username: details.dockerUsername,
|
|
2656
|
+
password: details.dockerPassword,
|
|
2657
|
+
email: details.dockerEmail,
|
|
2658
|
+
auth
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2663
|
+
async function getUserConfirmation(opts) {
|
|
2664
|
+
if (opts.confirm) {
|
|
2665
|
+
return true;
|
|
2666
|
+
}
|
|
2667
|
+
const confirm2 = await (0, import_prompts.default)({
|
|
2668
|
+
type: "confirm",
|
|
2669
|
+
name: "confirm",
|
|
2670
|
+
message: "This will remove and redeploy the module. Continue?"
|
|
2671
|
+
});
|
|
2672
|
+
return confirm2.confirm ? true : false;
|
|
2673
|
+
}
|
|
2807
2674
|
function deploy_default(program2) {
|
|
2808
2675
|
program2.command("deploy").description("Deploy a Pepr Module").option("-i, --image [image]", "Override the image tag").option("--confirm", "Skip confirmation prompt").option("--pullSecret <name>", "Deploy imagePullSecret for Controller private registry").option("--docker-server <server>", "Docker server address").option("--docker-username <username>", "Docker registry username").option("--docker-email <email>", "Email for Docker registry").option("--docker-password <password>", "Password for Docker registry").option("--force", "Force deploy the module, override manager field").action(async (opts) => {
|
|
2809
|
-
|
|
2810
|
-
if (
|
|
2811
|
-
console.error(
|
|
2812
|
-
"Error: Must provide docker server, username, email, and password when providing pull secret"
|
|
2813
|
-
);
|
|
2676
|
+
const valResp = validateImagePullSecretDetails(opts);
|
|
2677
|
+
if (!valResp.valid) {
|
|
2678
|
+
console.error(valResp.error);
|
|
2814
2679
|
process.exit(1);
|
|
2815
|
-
}
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
);
|
|
2819
|
-
process.exit(1);
|
|
2820
|
-
} else if (opts.pullSecret) {
|
|
2821
|
-
imagePullSecret = {
|
|
2822
|
-
auths: {
|
|
2823
|
-
[opts.dockerServer]: {
|
|
2824
|
-
username: opts.dockerUsername,
|
|
2825
|
-
password: opts.dockerPassword,
|
|
2826
|
-
email: opts.dockerEmail,
|
|
2827
|
-
auth: Buffer.from(`${opts.dockerUsername}:${opts.dockerPassword}`).toString("base64")
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
};
|
|
2831
|
-
await deployImagePullSecret(imagePullSecret, opts.pullSecret);
|
|
2680
|
+
}
|
|
2681
|
+
if (opts.pullSecret) {
|
|
2682
|
+
await deployImagePullSecret(generateImagePullSecret(opts), opts.pullSecret);
|
|
2832
2683
|
return;
|
|
2833
2684
|
}
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
message: "This will remove and redeploy the module. Continue?"
|
|
2839
|
-
});
|
|
2840
|
-
if (!confirm2.confirm) {
|
|
2841
|
-
process.exit(0);
|
|
2842
|
-
}
|
|
2685
|
+
await getUserConfirmation(opts) || process.exit(0);
|
|
2686
|
+
const builtModule = await buildModule();
|
|
2687
|
+
if (!builtModule) {
|
|
2688
|
+
return;
|
|
2843
2689
|
}
|
|
2844
|
-
const
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
);
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
const timeout = cfg.pepr.webhookTimeout ? cfg.pepr.webhookTimeout : 10;
|
|
2858
|
-
try {
|
|
2859
|
-
await webhook.deploy(opts.force, timeout);
|
|
2860
|
-
validateCapabilityNames(webhook.capabilities);
|
|
2861
|
-
await namespaceDeploymentsReady();
|
|
2862
|
-
console.info(`\u2705 Module deployed successfully`);
|
|
2863
|
-
} catch (e) {
|
|
2864
|
-
console.error(`Error deploying module:`, e);
|
|
2865
|
-
process.exit(1);
|
|
2866
|
-
}
|
|
2690
|
+
const webhook = new Assets(
|
|
2691
|
+
{ ...builtModule.cfg.pepr, description: builtModule.cfg.description },
|
|
2692
|
+
builtModule.path
|
|
2693
|
+
);
|
|
2694
|
+
webhook.image = opts.image ?? webhook.image;
|
|
2695
|
+
try {
|
|
2696
|
+
await webhook.deploy(opts.force, builtModule.cfg.pepr.webhookTimeout ?? 10);
|
|
2697
|
+
validateCapabilityNames(webhook.capabilities);
|
|
2698
|
+
await namespaceDeploymentsReady();
|
|
2699
|
+
console.info(`\u2705 Module deployed successfully`);
|
|
2700
|
+
} catch (e) {
|
|
2701
|
+
console.error(`Error deploying module:`, e);
|
|
2702
|
+
process.exit(1);
|
|
2867
2703
|
}
|
|
2868
2704
|
});
|
|
2869
2705
|
}
|
|
@@ -3051,13 +2887,16 @@ var import_prompts4 = __toESM(require("prompts"));
|
|
|
3051
2887
|
var import_fs11 = require("fs");
|
|
3052
2888
|
var import_prompts3 = __toESM(require("prompts"));
|
|
3053
2889
|
|
|
2890
|
+
// src/cli/init/enums.ts
|
|
2891
|
+
var OnError = /* @__PURE__ */ ((OnError2) => {
|
|
2892
|
+
OnError2["AUDIT"] = "audit";
|
|
2893
|
+
OnError2["IGNORE"] = "ignore";
|
|
2894
|
+
OnError2["REJECT"] = "reject";
|
|
2895
|
+
return OnError2;
|
|
2896
|
+
})(OnError || {});
|
|
2897
|
+
|
|
3054
2898
|
// src/lib/errors.ts
|
|
3055
|
-
var
|
|
3056
|
-
audit: "audit",
|
|
3057
|
-
ignore: "ignore",
|
|
3058
|
-
reject: "reject"
|
|
3059
|
-
};
|
|
3060
|
-
var ErrorList = Object.values(Errors);
|
|
2899
|
+
var ErrorList = Object.values(OnError);
|
|
3061
2900
|
|
|
3062
2901
|
// src/cli/init/walkthrough.ts
|
|
3063
2902
|
async function walkthrough(opts) {
|
|
@@ -3113,18 +2952,18 @@ async function setErrorBehavior(errorBehavior) {
|
|
|
3113
2952
|
choices: [
|
|
3114
2953
|
{
|
|
3115
2954
|
title: "Reject the operation",
|
|
3116
|
-
value:
|
|
2955
|
+
value: "reject" /* REJECT */,
|
|
3117
2956
|
description: "In the event that Pepr is down or other module errors occur, the operation will not be allowed to continue. (Recommended for production.)"
|
|
3118
2957
|
},
|
|
3119
2958
|
{
|
|
3120
2959
|
title: "Ignore",
|
|
3121
|
-
value:
|
|
2960
|
+
value: "ignore" /* IGNORE */,
|
|
3122
2961
|
description: "In the event that Pepr is down or other module errors occur, an entry will be generated in the Pepr Controller Log and the operation will be allowed to continue. (Recommended for development, not for production.)",
|
|
3123
2962
|
selected: true
|
|
3124
2963
|
},
|
|
3125
2964
|
{
|
|
3126
2965
|
title: "Log an audit event",
|
|
3127
|
-
value:
|
|
2966
|
+
value: "audit" /* AUDIT */,
|
|
3128
2967
|
description: "Pepr will continue processing and generate an entry in the Pepr Controller log as well as an audit event in the cluster."
|
|
3129
2968
|
}
|
|
3130
2969
|
]
|
|
@@ -3172,7 +3011,7 @@ ${packageJSON2.print.replace(/^/gm, " \u2502 ")}
|
|
|
3172
3011
|
function init_default(program2) {
|
|
3173
3012
|
let response = {};
|
|
3174
3013
|
let pkgOverride = "";
|
|
3175
|
-
program2.command("init").description("Initialize a new Pepr Module").option("--confirm", "Skip verification prompt when creating a new module.").option("--description <string>", "Explain the purpose of the new module.").option("--name <string>", "Set the name of the new module.").option("--skip-post-init", "Skip npm install, git init, and VSCode launch.").option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.",
|
|
3014
|
+
program2.command("init").description("Initialize a new Pepr Module").option("--confirm", "Skip verification prompt when creating a new module.").option("--description <string>", "Explain the purpose of the new module.").option("--name <string>", "Set the name of the new module.").option("--skip-post-init", "Skip npm install, git init, and VSCode launch.").option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.", "reject" /* REJECT */).hook("preAction", async (thisCommand) => {
|
|
3176
3015
|
if (process.env.TEST_MODE === "true") {
|
|
3177
3016
|
import_prompts4.default.inject(["pepr-test-module", "A test module for Pepr", "ignore", "y"]);
|
|
3178
3017
|
pkgOverride = "file:../pepr-0.0.0-development.tgz";
|