pepr 0.51.6 → 0.52.0-nightly.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 +2 -2
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.helpers.d.ts +1 -1
- package/dist/cli/build.helpers.d.ts.map +1 -1
- package/dist/cli/crd/create.d.ts +0 -1
- package/dist/cli/crd/create.d.ts.map +1 -1
- package/dist/cli/crd/generate.d.ts.map +1 -1
- package/dist/cli/crd/index.d.ts +2 -2
- package/dist/cli/crd/index.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts +3 -3
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/dev.d.ts +2 -2
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/format/index.d.ts +2 -2
- package/dist/cli/format/index.d.ts.map +1 -1
- package/dist/cli/init/index.d.ts +2 -2
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +13 -12
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/init/walkthrough.d.ts.map +1 -1
- package/dist/cli/kfc.d.ts +2 -2
- package/dist/cli/kfc.d.ts.map +1 -1
- package/dist/cli/monitor.d.ts +2 -2
- package/dist/cli/monitor.d.ts.map +1 -1
- package/dist/cli/update/index.d.ts +2 -2
- package/dist/cli/update/index.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts +2 -2
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +304 -204
- package/dist/controller.js +1 -1
- package/dist/lib/assets/assets.d.ts +13 -2
- package/dist/lib/assets/assets.d.ts.map +1 -1
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/{envrionment.d.ts → environment.d.ts} +1 -1
- package/dist/lib/assets/environment.d.ts.map +1 -0
- package/dist/lib/assets/helm.d.ts +4 -3
- package/dist/lib/assets/helm.d.ts.map +1 -1
- package/dist/lib/assets/{pods.d.ts → k8sObjects.d.ts} +4 -2
- package/dist/lib/assets/k8sObjects.d.ts.map +1 -0
- package/dist/lib/assets/networking.d.ts +0 -2
- package/dist/lib/assets/networking.d.ts.map +1 -1
- package/dist/lib/assets/yaml/generateAllYaml.d.ts +8 -3
- package/dist/lib/assets/yaml/generateAllYaml.d.ts.map +1 -1
- package/dist/lib/assets/yaml/overridesFile.d.ts +4 -1
- package/dist/lib/assets/yaml/overridesFile.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/cli/build.helpers.ts +26 -14
- package/src/cli/build.ts +37 -47
- package/src/cli/crd/create.ts +15 -20
- package/src/cli/crd/generate.ts +9 -6
- package/src/cli/crd/index.ts +2 -2
- package/src/cli/deploy.ts +16 -16
- package/src/cli/dev.ts +8 -8
- package/src/cli/format/index.ts +5 -4
- package/src/cli/init/index.ts +12 -9
- package/src/cli/init/walkthrough.ts +2 -4
- package/src/cli/kfc.ts +17 -13
- package/src/cli/monitor.ts +2 -2
- package/src/cli/update/index.ts +11 -11
- package/src/cli/uuid.ts +2 -2
- package/src/cli.ts +2 -2
- package/src/lib/assets/assets.ts +81 -22
- package/src/lib/assets/deploy.ts +26 -12
- package/src/lib/assets/helm.ts +37 -3
- package/src/lib/assets/{pods.ts → k8sObjects.ts} +69 -22
- package/src/lib/assets/networking.ts +0 -52
- package/src/lib/assets/yaml/generateAllYaml.ts +38 -11
- package/src/lib/assets/yaml/overridesFile.ts +6 -1
- package/src/templates/tsconfig.module.json +2 -2
- package/dist/cli/root.d.ts +0 -5
- package/dist/cli/root.d.ts.map +0 -1
- package/dist/lib/assets/envrionment.d.ts.map +0 -1
- package/dist/lib/assets/pods.d.ts.map +0 -1
- package/src/cli/root.ts +0 -12
- /package/src/lib/assets/{envrionment.ts → environment.ts} +0 -0
package/dist/cli.js
CHANGED
|
@@ -7500,8 +7500,9 @@ function chartYaml(name2, description) {
|
|
|
7500
7500
|
appVersion: "1.16.0"
|
|
7501
7501
|
`;
|
|
7502
7502
|
}
|
|
7503
|
-
function watcherDeployTemplate(buildTimestamp) {
|
|
7503
|
+
function watcherDeployTemplate(buildTimestamp, type) {
|
|
7504
7504
|
return `
|
|
7505
|
+
{{- if .Values.${type}.enabled }}
|
|
7505
7506
|
apiVersion: apps/v1
|
|
7506
7507
|
kind: Deployment
|
|
7507
7508
|
metadata:
|
|
@@ -7529,6 +7530,9 @@ function watcherDeployTemplate(buildTimestamp) {
|
|
|
7529
7530
|
labels:
|
|
7530
7531
|
app: {{ .Values.uuid }}-watcher
|
|
7531
7532
|
pepr.dev/controller: watcher
|
|
7533
|
+
{{- if .Values.watcher.podLabels }}
|
|
7534
|
+
{{- toYaml .Values.watcher.podLabels | nindent 8 }}
|
|
7535
|
+
{{- end }}
|
|
7532
7536
|
spec:
|
|
7533
7537
|
terminationGracePeriodSeconds: {{ .Values.watcher.terminationGracePeriodSeconds }}
|
|
7534
7538
|
serviceAccountName: {{ .Values.uuid }}
|
|
@@ -7593,10 +7597,12 @@ function watcherDeployTemplate(buildTimestamp) {
|
|
|
7593
7597
|
{{- if .Values.watcher.extraVolumes }}
|
|
7594
7598
|
{{- toYaml .Values.watcher.extraVolumes | nindent 8 }}
|
|
7595
7599
|
{{- end }}
|
|
7600
|
+
{{- end }}
|
|
7596
7601
|
`;
|
|
7597
7602
|
}
|
|
7598
|
-
function admissionDeployTemplate(buildTimestamp) {
|
|
7603
|
+
function admissionDeployTemplate(buildTimestamp, type) {
|
|
7599
7604
|
return `
|
|
7605
|
+
{{- if .Values.${type}.enabled }}
|
|
7600
7606
|
apiVersion: apps/v1
|
|
7601
7607
|
kind: Deployment
|
|
7602
7608
|
metadata:
|
|
@@ -7622,6 +7628,9 @@ function admissionDeployTemplate(buildTimestamp) {
|
|
|
7622
7628
|
labels:
|
|
7623
7629
|
app: {{ .Values.uuid }}
|
|
7624
7630
|
pepr.dev/controller: admission
|
|
7631
|
+
{{- if .Values.admission.podLabels }}
|
|
7632
|
+
{{- toYaml .Values.admission.podLabels | nindent 8 }}
|
|
7633
|
+
{{- end }}
|
|
7625
7634
|
spec:
|
|
7626
7635
|
{{- if or .Values.admission.antiAffinity .Values.admission.affinity }}
|
|
7627
7636
|
affinity:
|
|
@@ -7708,6 +7717,7 @@ function admissionDeployTemplate(buildTimestamp) {
|
|
|
7708
7717
|
{{- if .Values.admission.extraVolumes }}
|
|
7709
7718
|
{{- toYaml .Values.admission.extraVolumes | nindent 8 }}
|
|
7710
7719
|
{{- end }}
|
|
7720
|
+
{{- end }}
|
|
7711
7721
|
`;
|
|
7712
7722
|
}
|
|
7713
7723
|
function serviceMonitorTemplate(name2, type) {
|
|
@@ -7737,6 +7747,27 @@ function serviceMonitorTemplate(name2, type) {
|
|
|
7737
7747
|
{{- end }}
|
|
7738
7748
|
`;
|
|
7739
7749
|
}
|
|
7750
|
+
function serviceTemplate(name2, type) {
|
|
7751
|
+
const svcName = type === "admission" ? name2 : `${name2}-${type}`;
|
|
7752
|
+
return `
|
|
7753
|
+
{{- if .Values.${type}.enabled }}
|
|
7754
|
+
apiVersion: v1
|
|
7755
|
+
kind: Service
|
|
7756
|
+
metadata:
|
|
7757
|
+
name: ${svcName}
|
|
7758
|
+
namespace: pepr-system
|
|
7759
|
+
labels:
|
|
7760
|
+
pepr.dev/controller: ${type}
|
|
7761
|
+
spec:
|
|
7762
|
+
selector:
|
|
7763
|
+
app: ${svcName}
|
|
7764
|
+
pepr.dev/controller: ${type}
|
|
7765
|
+
ports:
|
|
7766
|
+
- port: 443
|
|
7767
|
+
targetPort: 3000
|
|
7768
|
+
{{- end }}
|
|
7769
|
+
`;
|
|
7770
|
+
}
|
|
7740
7771
|
|
|
7741
7772
|
// src/lib/filesystemService.ts
|
|
7742
7773
|
var import_fs = require("fs");
|
|
@@ -7752,7 +7783,7 @@ async function createDirectoryIfNotExists(path4) {
|
|
|
7752
7783
|
}
|
|
7753
7784
|
}
|
|
7754
7785
|
|
|
7755
|
-
// src/lib/assets/
|
|
7786
|
+
// src/lib/assets/environment.ts
|
|
7756
7787
|
function genEnv(config, watchMode = false, ignoreWatchMode = false) {
|
|
7757
7788
|
const noWatchDef = {
|
|
7758
7789
|
PEPR_PRETTY_LOG: "false",
|
|
@@ -8090,7 +8121,7 @@ function resolveIgnoreNamespaces(ignoredNSConfig = []) {
|
|
|
8090
8121
|
}
|
|
8091
8122
|
|
|
8092
8123
|
// src/lib/assets/yaml/overridesFile.ts
|
|
8093
|
-
async function overridesFile({ hash, name: name2, image, config, apiPath, capabilities }, path4, imagePullSecrets) {
|
|
8124
|
+
async function overridesFile({ hash, name: name2, image, config, apiPath, capabilities }, path4, imagePullSecrets, controllerType = { admission: true, watcher: true }) {
|
|
8094
8125
|
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
8095
8126
|
const overrides = {
|
|
8096
8127
|
imagePullSecrets,
|
|
@@ -8110,6 +8141,7 @@ async function overridesFile({ hash, name: name2, image, config, apiPath, capabi
|
|
|
8110
8141
|
},
|
|
8111
8142
|
uuid: name2,
|
|
8112
8143
|
admission: {
|
|
8144
|
+
enabled: controllerType.admission === true ? true : false,
|
|
8113
8145
|
antiAffinity: false,
|
|
8114
8146
|
terminationGracePeriodSeconds: 5,
|
|
8115
8147
|
failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
|
|
@@ -8167,6 +8199,7 @@ async function overridesFile({ hash, name: name2, image, config, apiPath, capabi
|
|
|
8167
8199
|
}
|
|
8168
8200
|
},
|
|
8169
8201
|
podAnnotations: {},
|
|
8202
|
+
podLabels: {},
|
|
8170
8203
|
nodeSelector: {},
|
|
8171
8204
|
tolerations: [],
|
|
8172
8205
|
extraVolumeMounts: [],
|
|
@@ -8179,6 +8212,7 @@ async function overridesFile({ hash, name: name2, image, config, apiPath, capabi
|
|
|
8179
8212
|
}
|
|
8180
8213
|
},
|
|
8181
8214
|
watcher: {
|
|
8215
|
+
enabled: controllerType.watcher === true ? true : false,
|
|
8182
8216
|
terminationGracePeriodSeconds: 5,
|
|
8183
8217
|
env: genEnv(config, true, true),
|
|
8184
8218
|
envFrom: [],
|
|
@@ -8238,6 +8272,7 @@ async function overridesFile({ hash, name: name2, image, config, apiPath, capabi
|
|
|
8238
8272
|
extraVolumes: [],
|
|
8239
8273
|
affinity: {},
|
|
8240
8274
|
podAnnotations: {},
|
|
8275
|
+
podLabels: {},
|
|
8241
8276
|
serviceMonitor: {
|
|
8242
8277
|
enabled: false,
|
|
8243
8278
|
labels: {},
|
|
@@ -8386,58 +8421,36 @@ function tlsSecret(name2, tls) {
|
|
|
8386
8421
|
}
|
|
8387
8422
|
};
|
|
8388
8423
|
}
|
|
8389
|
-
|
|
8390
|
-
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
|
|
8394
|
-
|
|
8395
|
-
|
|
8396
|
-
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
|
|
8401
|
-
selector: {
|
|
8402
|
-
app: name2,
|
|
8403
|
-
"pepr.dev/controller": "admission"
|
|
8404
|
-
},
|
|
8405
|
-
ports: [
|
|
8406
|
-
{
|
|
8407
|
-
port: 443,
|
|
8408
|
-
targetPort: 3e3
|
|
8409
|
-
}
|
|
8410
|
-
]
|
|
8424
|
+
|
|
8425
|
+
// src/lib/assets/assets.ts
|
|
8426
|
+
function norWatchOrAdmission(capabilities) {
|
|
8427
|
+
return !isAdmission(capabilities) && !isWatcher(capabilities);
|
|
8428
|
+
}
|
|
8429
|
+
function isAdmission(capabilities) {
|
|
8430
|
+
for (const capability of capabilities) {
|
|
8431
|
+
const admissionBindings = capability.bindings.filter(
|
|
8432
|
+
(binding) => binding.isFinalize || binding.isMutate || binding.isValidate
|
|
8433
|
+
);
|
|
8434
|
+
if (admissionBindings.length > 0) {
|
|
8435
|
+
return true;
|
|
8411
8436
|
}
|
|
8412
|
-
}
|
|
8437
|
+
}
|
|
8438
|
+
return false;
|
|
8413
8439
|
}
|
|
8414
|
-
function
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
metadata: {
|
|
8419
|
-
name: `${name2}-watcher`,
|
|
8420
|
-
namespace: "pepr-system",
|
|
8421
|
-
labels: {
|
|
8422
|
-
"pepr.dev/controller": "watcher"
|
|
8423
|
-
}
|
|
8424
|
-
},
|
|
8425
|
-
spec: {
|
|
8426
|
-
selector: {
|
|
8427
|
-
app: `${name2}-watcher`,
|
|
8428
|
-
"pepr.dev/controller": "watcher"
|
|
8429
|
-
},
|
|
8430
|
-
ports: [
|
|
8431
|
-
{
|
|
8432
|
-
port: 443,
|
|
8433
|
-
targetPort: 3e3
|
|
8434
|
-
}
|
|
8435
|
-
]
|
|
8440
|
+
function isWatcher(capabilities) {
|
|
8441
|
+
for (const capability of capabilities) {
|
|
8442
|
+
if (capability.hasSchedule) {
|
|
8443
|
+
return true;
|
|
8436
8444
|
}
|
|
8437
|
-
|
|
8445
|
+
const watcherBindings = capability.bindings.filter(
|
|
8446
|
+
(binding) => binding.isFinalize || binding.isWatch || binding.isQueue
|
|
8447
|
+
);
|
|
8448
|
+
if (watcherBindings.length > 0) {
|
|
8449
|
+
return true;
|
|
8450
|
+
}
|
|
8451
|
+
}
|
|
8452
|
+
return false;
|
|
8438
8453
|
}
|
|
8439
|
-
|
|
8440
|
-
// src/lib/assets/assets.ts
|
|
8441
8454
|
var Assets = class {
|
|
8442
8455
|
name;
|
|
8443
8456
|
tls;
|
|
@@ -8469,7 +8482,7 @@ var Assets = class {
|
|
|
8469
8482
|
}
|
|
8470
8483
|
zarfYaml = (zarfYamlGenerator, path4) => zarfYamlGenerator(this, path4, "manifests");
|
|
8471
8484
|
zarfYamlChart = (zarfYamlGenerator, path4) => zarfYamlGenerator(this, path4, "charts");
|
|
8472
|
-
allYaml = async (yamlGenerationFunction,
|
|
8485
|
+
allYaml = async (yamlGenerationFunction, getControllerManifests, imagePullSecret) => {
|
|
8473
8486
|
this.capabilities = await loadCapabilities(this.path);
|
|
8474
8487
|
for (const capability of this.capabilities) {
|
|
8475
8488
|
namespaceComplianceValidator(capability, this.alwaysIgnore?.namespaces);
|
|
@@ -8483,16 +8496,30 @@ var Assets = class {
|
|
|
8483
8496
|
const code = await import_fs3.promises.readFile(this.path);
|
|
8484
8497
|
const moduleHash = import_crypto.default.createHash("sha256").update(code).digest("hex");
|
|
8485
8498
|
const deployments = {
|
|
8486
|
-
|
|
8487
|
-
|
|
8499
|
+
admission: getControllerManifests.getDeploymentFunction(
|
|
8500
|
+
this,
|
|
8501
|
+
moduleHash,
|
|
8502
|
+
this.buildTimestamp,
|
|
8503
|
+
imagePullSecret
|
|
8504
|
+
),
|
|
8505
|
+
watch: getControllerManifests.getWatcherFunction(
|
|
8506
|
+
this,
|
|
8507
|
+
moduleHash,
|
|
8508
|
+
this.buildTimestamp,
|
|
8509
|
+
imagePullSecret
|
|
8510
|
+
)
|
|
8511
|
+
};
|
|
8512
|
+
const services = {
|
|
8513
|
+
admission: getControllerManifests.getServiceFunction(this.name, this),
|
|
8514
|
+
watch: getControllerManifests.getWatcherServiceFunction(this.name, this)
|
|
8488
8515
|
};
|
|
8489
|
-
return yamlGenerationFunction(this, deployments);
|
|
8516
|
+
return yamlGenerationFunction(this, deployments, services);
|
|
8490
8517
|
};
|
|
8491
8518
|
writeWebhookFiles = async (validateWebhook, mutateWebhook, helm) => {
|
|
8492
8519
|
if (validateWebhook || mutateWebhook) {
|
|
8493
8520
|
await import_fs3.promises.writeFile(
|
|
8494
8521
|
helm.files.admissionDeploymentYaml,
|
|
8495
|
-
dedent(admissionDeployTemplate(this.buildTimestamp))
|
|
8522
|
+
dedent(admissionDeployTemplate(this.buildTimestamp, "admission"))
|
|
8496
8523
|
);
|
|
8497
8524
|
await import_fs3.promises.writeFile(
|
|
8498
8525
|
helm.files.admissionServiceMonitorYaml,
|
|
@@ -8531,8 +8558,14 @@ var Assets = class {
|
|
|
8531
8558
|
() => dedent(chartYaml(this.config.uuid, this.config.description || ""))
|
|
8532
8559
|
],
|
|
8533
8560
|
[helm.files.namespaceYaml, () => dedent(namespaceTemplate())],
|
|
8534
|
-
[
|
|
8535
|
-
|
|
8561
|
+
[
|
|
8562
|
+
helm.files.watcherServiceYaml,
|
|
8563
|
+
() => dedent(serviceTemplate(this.name, "watcher"))
|
|
8564
|
+
],
|
|
8565
|
+
[
|
|
8566
|
+
helm.files.admissionServiceYaml,
|
|
8567
|
+
() => dedent(serviceTemplate(this.name, "admission"))
|
|
8568
|
+
],
|
|
8536
8569
|
[helm.files.tlsSecretYaml, () => toYaml(tlsSecret(this.name, this.tls))],
|
|
8537
8570
|
[
|
|
8538
8571
|
helm.files.apiPathSecretYaml,
|
|
@@ -8557,7 +8590,10 @@ var Assets = class {
|
|
|
8557
8590
|
apiPath: this.apiPath,
|
|
8558
8591
|
capabilities: this.capabilities
|
|
8559
8592
|
};
|
|
8560
|
-
await overridesFile(overrideData, helm.files.valuesYaml, this.imagePullSecrets
|
|
8593
|
+
await overridesFile(overrideData, helm.files.valuesYaml, this.imagePullSecrets, {
|
|
8594
|
+
admission: isAdmission(this.capabilities) || norWatchOrAdmission(this.capabilities),
|
|
8595
|
+
watcher: isWatcher(this.capabilities)
|
|
8596
|
+
});
|
|
8561
8597
|
const webhooks = {
|
|
8562
8598
|
mutate: await webhookGeneratorFunction(
|
|
8563
8599
|
this,
|
|
@@ -8575,7 +8611,7 @@ var Assets = class {
|
|
|
8575
8611
|
if (watchDeployment) {
|
|
8576
8612
|
await import_fs3.promises.writeFile(
|
|
8577
8613
|
helm.files.watcherDeploymentYaml,
|
|
8578
|
-
dedent(watcherDeployTemplate(this.buildTimestamp))
|
|
8614
|
+
dedent(watcherDeployTemplate(this.buildTimestamp, "watcher"))
|
|
8579
8615
|
);
|
|
8580
8616
|
await import_fs3.promises.writeFile(
|
|
8581
8617
|
helm.files.watcherServiceMonitorYaml,
|
|
@@ -8822,8 +8858,8 @@ var tsconfig_module_default = {
|
|
|
8822
8858
|
emitDeclarationOnly: true,
|
|
8823
8859
|
esModuleInterop: true,
|
|
8824
8860
|
lib: ["ES2022"],
|
|
8825
|
-
module: "
|
|
8826
|
-
moduleResolution: "
|
|
8861
|
+
module: "NodeNext",
|
|
8862
|
+
moduleResolution: "NodeNext",
|
|
8827
8863
|
outDir: "dist",
|
|
8828
8864
|
resolveJsonModule: true,
|
|
8829
8865
|
rootDir: ".",
|
|
@@ -8839,7 +8875,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
8839
8875
|
var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```text\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
|
|
8840
8876
|
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';
|
|
8841
8877
|
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\nimport { MockAgent, setGlobalDispatcher } from "undici";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.SetLabel("pepr", "was-here").SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>): void {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap).IsCreated().InNamespace("pepr-demo-2").WithName("example-4a").Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://icanhazdadjoke.com/");\n * const joke = await fetch("https://icanhazdadjoke.com/") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://icanhazdadjoke.com")\n * ```\n */\ninterface TheChuckNorrisJoke {\n id: string;\n joke: string;\n status: number;\n}\n\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("chuck-norris")\n .Mutate(cm => cm.SetLabel("got-jokes", "true"))\n .Watch(async cm => {\n const jokeURL = "https://icanhazdadjoke.com";\n\n const mockAgent: MockAgent = new MockAgent();\n setGlobalDispatcher(mockAgent);\n const mockClient = mockAgent.get(jokeURL);\n mockClient.intercept({ path: "/", method: "GET" }).reply(\n 200,\n {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\n },\n {\n headers: {\n "Content-Type": "application/json; charset=utf-8",\n },\n },\n );\n\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(jokeURL, {\n headers: {\n Accept: "application/json",\n },\n });\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n const { joke } = response.data;\n // Add Joke to the Store\n await Store.setItemAndWait(jokeURL, joke);\n // Add the Chuck Norris joke to the configmap\n try {\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: cm.metadata.name,\n namespace: cm.metadata.namespace,\n },\n data: {\n "chuck-says": Store.getItem(jokeURL),\n },\n });\n } catch (error) {\n Log.error(error, "Failed to apply ConfigMap using server-side apply.", {\n cm,\n });\n }\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
|
|
8842
|
-
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*"], version: "0.
|
|
8878
|
+
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*"], version: "0.52.0-nightly.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { build: "tsc -p config/tsconfig.root.json && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr/private:dev $(node scripts/read-unicorn-build-args.mjs) .", ci: "npm ci", "format:check": "npm run format:src && npm run format:tests && npm run format:markdown && npm run format:integration && npm run format:prettier -- --check", "format:fix": "npm run format:src -- --fix && npm run format:markdown -- --fix && npm run format:integration -- --fix && npm run format:prettier -- --write", "format:integration": "eslint --config config/eslint.integration.config.mjs integration/cli integration/helpers", "format:markdown": 'npx -y markdownlint-cli --config config/.markdownlint.json --ignore adr --ignore integration/testroot --ignore pepr-test-module --ignore node_modules "**/*.md"', "format:prettier": "prettier --config config/.prettierrc src integration/cli/**/*.ts integration/helpers/**/*.ts", "format:src": "eslint --config config/eslint.root.config.mjs 'src/**/*.ts' --ignore-pattern '**/*.test.ts' --ignore-pattern 'src/templates/**'", "format:tests": "eslint --config config/eslint.test.config.mjs 'src/**/*.test.ts'", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi`, "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && vitest run src/build-artifact.test.ts", "test:docs": "vitest run --config=config/vitest.integration.config.ts integration/cli/docs/*.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "vitest run --config=config/vitest.integration.config.ts integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr/private:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr/private:dev -c pepr-dev", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:run": "vitest run --config=config/vitest.journey.config.ts journey/entrypoint.test.ts", "test:journey:run-wasm": "vitest run --config=config/vitest.journey.config.ts journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && npm run test:journey:run", "test:unit": "npm run gen-data-json && NODE_OPTIONS=--no-deprecation vitest --config config/vitest.root.config.ts run --coverage", "test:upgrade:unicorn": "npm run test:journey:k3d && npm run test:journey:image:unicorn && vitest run integration/cluster/upgrade.test.ts", "test:upgrade:upstream": "npm run test:journey:k3d && npm run test:journey:image && vitest run integration/cluster/upgrade.test.ts" }, dependencies: { "@types/ramda": "0.30.2", commander: "14.0.0", express: "5.1.0", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.8.1", pino: "9.7.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.31.3", sigstore: "3.1.0", "ts-morph": "^26.0.0" }, devDependencies: { "@commitlint/cli": "19.8.1", "@commitlint/config-conventional": "19.8.1", "@fast-check/vitest": "^0.2.1", "@types/eslint": "9.6.1", "@types/express": "5.0.3", "@types/json-pointer": "^1.0.34", "@types/node": "24.x.x", "@types/node-forge": "1.3.13", "@types/uuid": "10.0.0", "@types/ws": "^8.18.1", "@vitest/coverage-v8": "^3.2.3", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", tsx: "^4.20.3", undici: "^7.0.1", vitest: "^3.2.3" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.33.0", "@typescript-eslint/parser": "8.33.0", esbuild: "0.25.5", eslint: "^9.26.0", "node-forge": "1.3.1", prettier: "3.5.3", prompts: "2.4.2", typescript: "5.8.3", uuid: "11.1.0" } };
|
|
8843
8879
|
|
|
8844
8880
|
// src/cli/init/utils.ts
|
|
8845
8881
|
var import_fs4 = require("fs");
|
|
@@ -9038,12 +9074,12 @@ async function peprFormat(validateOnly) {
|
|
|
9038
9074
|
const formatter = await eslint2.loadFormatter("stylish");
|
|
9039
9075
|
const resultText = await formatter.format(results, {});
|
|
9040
9076
|
if (resultText) {
|
|
9041
|
-
|
|
9077
|
+
logger_default.info(resultText);
|
|
9042
9078
|
}
|
|
9043
9079
|
if (!validateOnly) {
|
|
9044
9080
|
await import_eslint.ESLint.outputFixes(results);
|
|
9045
9081
|
}
|
|
9046
|
-
hasFailure = await formatWithPrettier(results, validateOnly);
|
|
9082
|
+
hasFailure = hasFailure || await formatWithPrettier(results, validateOnly);
|
|
9047
9083
|
return !hasFailure;
|
|
9048
9084
|
} catch (e) {
|
|
9049
9085
|
console.error(`Error formatting module:`, e);
|
|
@@ -9078,7 +9114,7 @@ var import_fs9 = require("fs");
|
|
|
9078
9114
|
var import_crypto2 = __toESM(require("crypto"));
|
|
9079
9115
|
var import_client_node4 = require("@kubernetes/client-node");
|
|
9080
9116
|
|
|
9081
|
-
// src/lib/assets/
|
|
9117
|
+
// src/lib/assets/k8sObjects.ts
|
|
9082
9118
|
var import_zlib = require("zlib");
|
|
9083
9119
|
function getNamespace(namespaceLabels) {
|
|
9084
9120
|
if (namespaceLabels) {
|
|
@@ -9101,20 +9137,11 @@ function getNamespace(namespaceLabels) {
|
|
|
9101
9137
|
}
|
|
9102
9138
|
}
|
|
9103
9139
|
function getWatcher(assets, hash, buildTimestamp, imagePullSecret) {
|
|
9104
|
-
const { name: name2, image,
|
|
9105
|
-
|
|
9106
|
-
const app = `${name2}-watcher`;
|
|
9107
|
-
const bindings = [];
|
|
9108
|
-
for (const capability of capabilities) {
|
|
9109
|
-
if (capability.hasSchedule) {
|
|
9110
|
-
hasSchedule = true;
|
|
9111
|
-
}
|
|
9112
|
-
const watchers = capability.bindings.filter((binding) => binding.isWatch);
|
|
9113
|
-
bindings.push(...watchers);
|
|
9114
|
-
}
|
|
9115
|
-
if (bindings.length < 1 && !hasSchedule) {
|
|
9140
|
+
const { name: name2, image, config } = assets;
|
|
9141
|
+
if (!isWatcher(assets.capabilities)) {
|
|
9116
9142
|
return null;
|
|
9117
9143
|
}
|
|
9144
|
+
const app = `${name2}-watcher`;
|
|
9118
9145
|
const deploy = {
|
|
9119
9146
|
apiVersion: "apps/v1",
|
|
9120
9147
|
kind: "Deployment",
|
|
@@ -9247,6 +9274,9 @@ function getWatcher(assets, hash, buildTimestamp, imagePullSecret) {
|
|
|
9247
9274
|
function getDeployment(assets, hash, buildTimestamp, imagePullSecret) {
|
|
9248
9275
|
const { name: name2, image, config } = assets;
|
|
9249
9276
|
const app = name2;
|
|
9277
|
+
if (!isAdmission(assets.capabilities) && !norWatchOrAdmission(assets.capabilities)) {
|
|
9278
|
+
return null;
|
|
9279
|
+
}
|
|
9250
9280
|
const deploy = {
|
|
9251
9281
|
apiVersion: "apps/v1",
|
|
9252
9282
|
kind: "Deployment",
|
|
@@ -9407,6 +9437,62 @@ function getModuleSecret(name2, data, hash) {
|
|
|
9407
9437
|
};
|
|
9408
9438
|
}
|
|
9409
9439
|
}
|
|
9440
|
+
function service(name2, assets) {
|
|
9441
|
+
if (!isAdmission(assets.capabilities) && !norWatchOrAdmission(assets.capabilities)) {
|
|
9442
|
+
return null;
|
|
9443
|
+
}
|
|
9444
|
+
return {
|
|
9445
|
+
apiVersion: "v1",
|
|
9446
|
+
kind: "Service",
|
|
9447
|
+
metadata: {
|
|
9448
|
+
name: name2,
|
|
9449
|
+
namespace: "pepr-system",
|
|
9450
|
+
labels: {
|
|
9451
|
+
"pepr.dev/controller": "admission"
|
|
9452
|
+
}
|
|
9453
|
+
},
|
|
9454
|
+
spec: {
|
|
9455
|
+
selector: {
|
|
9456
|
+
app: name2,
|
|
9457
|
+
"pepr.dev/controller": "admission"
|
|
9458
|
+
},
|
|
9459
|
+
ports: [
|
|
9460
|
+
{
|
|
9461
|
+
port: 443,
|
|
9462
|
+
targetPort: 3e3
|
|
9463
|
+
}
|
|
9464
|
+
]
|
|
9465
|
+
}
|
|
9466
|
+
};
|
|
9467
|
+
}
|
|
9468
|
+
function watcherService(name2, assets) {
|
|
9469
|
+
if (!isWatcher(assets.capabilities)) {
|
|
9470
|
+
return null;
|
|
9471
|
+
}
|
|
9472
|
+
return {
|
|
9473
|
+
apiVersion: "v1",
|
|
9474
|
+
kind: "Service",
|
|
9475
|
+
metadata: {
|
|
9476
|
+
name: `${name2}-watcher`,
|
|
9477
|
+
namespace: "pepr-system",
|
|
9478
|
+
labels: {
|
|
9479
|
+
"pepr.dev/controller": "watcher"
|
|
9480
|
+
}
|
|
9481
|
+
},
|
|
9482
|
+
spec: {
|
|
9483
|
+
selector: {
|
|
9484
|
+
app: `${name2}-watcher`,
|
|
9485
|
+
"pepr.dev/controller": "watcher"
|
|
9486
|
+
},
|
|
9487
|
+
ports: [
|
|
9488
|
+
{
|
|
9489
|
+
port: 443,
|
|
9490
|
+
targetPort: 3e3
|
|
9491
|
+
}
|
|
9492
|
+
]
|
|
9493
|
+
}
|
|
9494
|
+
};
|
|
9495
|
+
}
|
|
9410
9496
|
|
|
9411
9497
|
// src/lib/assets/yaml/generateAllYaml.ts
|
|
9412
9498
|
var import_fs8 = require("fs");
|
|
@@ -9495,24 +9581,37 @@ async function webhookConfigGenerator(assets, mutateOrValidate, timeoutSeconds =
|
|
|
9495
9581
|
}
|
|
9496
9582
|
|
|
9497
9583
|
// src/lib/assets/yaml/generateAllYaml.ts
|
|
9498
|
-
|
|
9584
|
+
function pushControllerManifests(resources, deployments, services) {
|
|
9585
|
+
if (deployments.watch) {
|
|
9586
|
+
resources.push(deployments.watch);
|
|
9587
|
+
}
|
|
9588
|
+
if (deployments.admission) {
|
|
9589
|
+
resources.push(deployments.admission);
|
|
9590
|
+
}
|
|
9591
|
+
if (services.admission) {
|
|
9592
|
+
resources.push(services.admission);
|
|
9593
|
+
}
|
|
9594
|
+
if (services.watch) {
|
|
9595
|
+
resources.push(services.watch);
|
|
9596
|
+
}
|
|
9597
|
+
return resources;
|
|
9598
|
+
}
|
|
9599
|
+
async function generateAllYaml(assets, deployments, services) {
|
|
9499
9600
|
const { name: name2, tls, apiPath, path: path4, config } = assets;
|
|
9500
9601
|
const code = await import_fs8.promises.readFile(path4);
|
|
9501
9602
|
const hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
9502
|
-
|
|
9603
|
+
let resources = [
|
|
9503
9604
|
getNamespace(assets.config.customLabels?.namespace),
|
|
9504
9605
|
clusterRole(name2, assets.capabilities, config.rbacMode, config.rbac),
|
|
9505
9606
|
clusterRoleBinding(name2),
|
|
9506
9607
|
serviceAccount(name2),
|
|
9507
9608
|
apiPathSecret(name2, apiPath),
|
|
9508
9609
|
tlsSecret(name2, tls),
|
|
9509
|
-
deployments.default,
|
|
9510
|
-
service(name2),
|
|
9511
|
-
watcherService(name2),
|
|
9512
9610
|
getModuleSecret(name2, code, hash),
|
|
9513
9611
|
storeRole(name2),
|
|
9514
9612
|
storeRoleBinding(name2)
|
|
9515
9613
|
];
|
|
9614
|
+
resources = pushControllerManifests(resources, deployments, services);
|
|
9516
9615
|
const webhooks = {
|
|
9517
9616
|
mutate: await webhookConfigGenerator(assets, "mutate" /* MUTATE */, assets.config.webhookTimeout),
|
|
9518
9617
|
validate: await webhookConfigGenerator(
|
|
@@ -9521,7 +9620,7 @@ async function generateAllYaml(assets, deployments) {
|
|
|
9521
9620
|
assets.config.webhookTimeout
|
|
9522
9621
|
)
|
|
9523
9622
|
};
|
|
9524
|
-
const additionalResources = [webhooks.mutate, webhooks.validate
|
|
9623
|
+
const additionalResources = [webhooks.mutate, webhooks.validate].filter(
|
|
9525
9624
|
(resource) => resource !== null && resource !== void 0
|
|
9526
9625
|
);
|
|
9527
9626
|
resources.push(...additionalResources);
|
|
@@ -9585,18 +9684,15 @@ function determineRbacMode(opts, cfg) {
|
|
|
9585
9684
|
}
|
|
9586
9685
|
return cfg.pepr.rbacMode || "admin";
|
|
9587
9686
|
}
|
|
9588
|
-
async function
|
|
9589
|
-
|
|
9590
|
-
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
process.exit(1);
|
|
9597
|
-
}
|
|
9687
|
+
async function createOutputDirectory(outputDir2) {
|
|
9688
|
+
try {
|
|
9689
|
+
const dir = outputDir2 === "" ? "dist" : outputDir2;
|
|
9690
|
+
await createDirectoryIfNotExists(dir);
|
|
9691
|
+
return dir;
|
|
9692
|
+
} catch (error) {
|
|
9693
|
+
console.error(`Error creating output directory: ${error.message}`);
|
|
9694
|
+
process.exit(1);
|
|
9598
9695
|
}
|
|
9599
|
-
return defaultOutputDir;
|
|
9600
9696
|
}
|
|
9601
9697
|
function checkIronBankImage(registry, image, peprVersion) {
|
|
9602
9698
|
return registry === "Iron Bank" ? `registry1.dso.mil/ironbank/opensource/defenseunicorns/pepr/controller:v${peprVersion}` : image;
|
|
@@ -9643,7 +9739,16 @@ async function generateYamlAndWriteToDisk(obj) {
|
|
|
9643
9739
|
const chartPath = `${uuid}-chart`;
|
|
9644
9740
|
const yamlPath = (0, import_path3.resolve)(outputDir2, yamlFile);
|
|
9645
9741
|
try {
|
|
9646
|
-
const yaml = await assets.allYaml(
|
|
9742
|
+
const yaml = await assets.allYaml(
|
|
9743
|
+
generateAllYaml,
|
|
9744
|
+
{
|
|
9745
|
+
getDeploymentFunction: getDeployment,
|
|
9746
|
+
getWatcherFunction: getWatcher,
|
|
9747
|
+
getServiceFunction: service,
|
|
9748
|
+
getWatcherServiceFunction: watcherService
|
|
9749
|
+
},
|
|
9750
|
+
imagePullSecret
|
|
9751
|
+
);
|
|
9647
9752
|
const zarfPath = (0, import_path3.resolve)(outputDir2, "zarf.yaml");
|
|
9648
9753
|
let localZarf = "";
|
|
9649
9754
|
if (zarf === "chart") {
|
|
@@ -9654,7 +9759,7 @@ async function generateYamlAndWriteToDisk(obj) {
|
|
|
9654
9759
|
await import_fs9.promises.writeFile(yamlPath, yaml);
|
|
9655
9760
|
await import_fs9.promises.writeFile(zarfPath, localZarf);
|
|
9656
9761
|
await assets.generateHelmChart(webhookConfigGenerator, getWatcher, getModuleSecret, outputDir2);
|
|
9657
|
-
console.info(
|
|
9762
|
+
console.info(`K8s resource for the module saved to ${yamlPath}`);
|
|
9658
9763
|
} catch (error) {
|
|
9659
9764
|
console.error(`Error generating YAML: ${error}`);
|
|
9660
9765
|
process.exit(1);
|
|
@@ -9665,48 +9770,42 @@ async function generateYamlAndWriteToDisk(obj) {
|
|
|
9665
9770
|
var peprTS2 = "pepr.ts";
|
|
9666
9771
|
var outputDir = "dist";
|
|
9667
9772
|
function build_default(program2) {
|
|
9668
|
-
program2.command("build").description("Build a Pepr Module for deployment").
|
|
9669
|
-
"-
|
|
9670
|
-
|
|
9773
|
+
program2.command("build").description("Build a Pepr Module for deployment").addOption(
|
|
9774
|
+
new import_commander.Option("-M, --rbac-mode <mode>", "Override module config and set RBAC mode.").choices([
|
|
9775
|
+
"admin",
|
|
9776
|
+
"scoped"
|
|
9777
|
+
])
|
|
9671
9778
|
).addOption(
|
|
9672
9779
|
new import_commander.Option(
|
|
9673
|
-
"-
|
|
9674
|
-
"
|
|
9675
|
-
).conflicts(["registryInfo", "registry"])
|
|
9676
|
-
).addOption(
|
|
9677
|
-
new import_commander.Option(
|
|
9678
|
-
"-r, --registry-info [<registry>/<username>]",
|
|
9679
|
-
"Provide the image registry and username for building and pushing a custom WASM container. Requires authentication. Builds and pushes `'registry/username/custom-pepr-controller:<current-version>'`."
|
|
9780
|
+
"-I, --registry-info <registry/username>",
|
|
9781
|
+
"Provide the image registry and username for building and pushing a custom WASM container. Requires authentication. Conflicts with --custom-image and --registry. Builds and pushes `'<registry/username>/custom-pepr-controller:<current-version>'`."
|
|
9680
9782
|
).conflicts(["customImage", "registry"])
|
|
9681
|
-
).option("-
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
|
|
9783
|
+
).option("-P, --with-pull-secret <name>", "Use image pull secret for controller Deployment.", "").addOption(
|
|
9784
|
+
new import_commander.Option(
|
|
9785
|
+
"-c, --custom-name <name>",
|
|
9786
|
+
"Set name for zarf component and service monitors in helm charts."
|
|
9787
|
+
)
|
|
9788
|
+
).option("-e, --entry-point <file>", "Specify the entry point file to build with.", peprTS2).addOption(
|
|
9789
|
+
new import_commander.Option(
|
|
9790
|
+
"-i, --custom-image <image>",
|
|
9791
|
+
"Specify a custom image with version for deployments. Conflicts with --registry-info and --registry. Example: 'docker.io/username/custom-pepr-controller:v1.0.0'"
|
|
9792
|
+
).conflicts(["registryInfo", "registry"])
|
|
9685
9793
|
).option(
|
|
9686
|
-
"--
|
|
9687
|
-
"
|
|
9688
|
-
|
|
9689
|
-
).addOption(
|
|
9794
|
+
"-n, --no-embed",
|
|
9795
|
+
"Disable embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM."
|
|
9796
|
+
).option("-o, --output <directory>", "Set output directory.", "dist").addOption(
|
|
9690
9797
|
new import_commander.Option(
|
|
9691
|
-
"--registry <GitHub|Iron Bank>",
|
|
9692
|
-
"Container registry: Choose container registry for deployment manifests.
|
|
9798
|
+
"-r, --registry <GitHub|Iron Bank>",
|
|
9799
|
+
"Container registry: Choose container registry for deployment manifests. Conflicts with --custom-image and --registry-info."
|
|
9693
9800
|
).conflicts(["customImage", "registryInfo"]).choices(["GitHub", "Iron Bank"])
|
|
9801
|
+
).option(
|
|
9802
|
+
"-t, --timeout <seconds>",
|
|
9803
|
+
"How long the API server should wait for a webhook to respond before treating the call as a failure.",
|
|
9804
|
+
parseTimeout
|
|
9694
9805
|
).addOption(
|
|
9695
|
-
new import_commander.Option(
|
|
9696
|
-
"-z, --zarf [manifest|chart]",
|
|
9697
|
-
"Zarf package type: manifest, chart (default: manifest)"
|
|
9698
|
-
).choices(["manifest", "chart"]).default("manifest")
|
|
9699
|
-
).addOption(
|
|
9700
|
-
new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(
|
|
9701
|
-
["admin", "scoped"]
|
|
9702
|
-
)
|
|
9703
|
-
).addOption(
|
|
9704
|
-
new import_commander.Option(
|
|
9705
|
-
"--custom-name [name]",
|
|
9706
|
-
"Specify a custom name for zarf component and service monitors in helm charts."
|
|
9707
|
-
)
|
|
9806
|
+
new import_commander.Option("-z, --zarf <manifest|chart>", "Set Zarf package type").choices(["manifest", "chart"]).default("manifest")
|
|
9708
9807
|
).action(async (opts) => {
|
|
9709
|
-
outputDir = await
|
|
9808
|
+
outputDir = await createOutputDirectory(opts.output);
|
|
9710
9809
|
const buildModuleResult = await buildModule(void 0, opts.entryPoint, opts.embed);
|
|
9711
9810
|
const { cfg, path: path4 } = buildModuleResult;
|
|
9712
9811
|
if (opts.customName) {
|
|
@@ -9731,7 +9830,7 @@ function build_default(program2) {
|
|
|
9731
9830
|
);
|
|
9732
9831
|
}
|
|
9733
9832
|
if (!opts.embed) {
|
|
9734
|
-
console.info(
|
|
9833
|
+
console.info(`Module built successfully at ${path4}`);
|
|
9735
9834
|
return;
|
|
9736
9835
|
}
|
|
9737
9836
|
const assets = new Assets(
|
|
@@ -9816,7 +9915,7 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
9816
9915
|
setup(build) {
|
|
9817
9916
|
build.onEnd(async (r) => {
|
|
9818
9917
|
if (r?.metafile) {
|
|
9819
|
-
console.
|
|
9918
|
+
console.info(await (0, import_esbuild2.analyzeMetafile)(r.metafile));
|
|
9820
9919
|
}
|
|
9821
9920
|
if (reloader) {
|
|
9822
9921
|
await reloader(r);
|
|
@@ -9849,7 +9948,7 @@ function handleModuleBuildError(e) {
|
|
|
9849
9948
|
if (!e.stdout) process.exit(1);
|
|
9850
9949
|
const out = e.stdout.toString();
|
|
9851
9950
|
const err = e.stderr.toString();
|
|
9852
|
-
console.
|
|
9951
|
+
console.info(out);
|
|
9853
9952
|
console.error(err);
|
|
9854
9953
|
if (out.includes("Types have separate declarations of a private property '_name'.")) {
|
|
9855
9954
|
const pgkErrMatch = /error TS2322: .*? 'import\("\/.*?\/node_modules\/(.*?)\/node_modules/g;
|
|
@@ -9876,7 +9975,7 @@ function handleModuleBuildError(e) {
|
|
|
9876
9975
|
async function checkFormat() {
|
|
9877
9976
|
const validFormat = await peprFormat(true);
|
|
9878
9977
|
if (!validFormat) {
|
|
9879
|
-
console.
|
|
9978
|
+
console.info(
|
|
9880
9979
|
"\x1B[33m%s\x1B[0m",
|
|
9881
9980
|
"Formatting errors were found. The build will continue, but you may want to run `npx pepr format` to address any issues."
|
|
9882
9981
|
);
|
|
@@ -10027,26 +10126,34 @@ async function setupController(assets, code, hash, force) {
|
|
|
10027
10126
|
logger_default.info("Applying module secret");
|
|
10028
10127
|
const mod = getModuleSecret(name2, code, hash);
|
|
10029
10128
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(mod, { force });
|
|
10030
|
-
|
|
10031
|
-
|
|
10032
|
-
|
|
10129
|
+
if (isAdmission(assets.capabilities) || norWatchOrAdmission(assets.capabilities)) {
|
|
10130
|
+
const svc = service(name2, assets);
|
|
10131
|
+
if (svc) {
|
|
10132
|
+
logger_default.info("Applying controller service");
|
|
10133
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Service).Apply(svc, { force });
|
|
10134
|
+
}
|
|
10135
|
+
const dep = getDeployment(assets, hash, assets.buildTimestamp);
|
|
10136
|
+
if (dep) {
|
|
10137
|
+
logger_default.info("Applying deployment");
|
|
10138
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(dep, { force });
|
|
10139
|
+
}
|
|
10140
|
+
}
|
|
10033
10141
|
logger_default.info("Applying TLS secret");
|
|
10034
10142
|
const tls = tlsSecret(name2, assets.tls);
|
|
10035
10143
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(tls, { force });
|
|
10036
10144
|
logger_default.info("Applying API path secret");
|
|
10037
10145
|
const apiPath = apiPathSecret(name2, assets.apiPath);
|
|
10038
10146
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(apiPath, { force });
|
|
10039
|
-
logger_default.info("Applying deployment");
|
|
10040
|
-
const dep = getDeployment(assets, hash, assets.buildTimestamp);
|
|
10041
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(dep, { force });
|
|
10042
10147
|
}
|
|
10043
10148
|
async function setupWatcher(assets, hash, force) {
|
|
10044
10149
|
const watchDeployment = getWatcher(assets, hash, assets.buildTimestamp);
|
|
10045
10150
|
if (watchDeployment) {
|
|
10046
10151
|
logger_default.info("Applying watcher deployment");
|
|
10047
10152
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(watchDeployment, { force });
|
|
10153
|
+
}
|
|
10154
|
+
const watchSvc = watcherService(assets.name, assets);
|
|
10155
|
+
if (watchSvc) {
|
|
10048
10156
|
logger_default.info("Applying watcher service");
|
|
10049
|
-
const watchSvc = watcherService(assets.name);
|
|
10050
10157
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Service).Apply(watchSvc, { force });
|
|
10051
10158
|
}
|
|
10052
10159
|
}
|
|
@@ -10113,7 +10220,7 @@ function validateImagePullSecretDetails(details) {
|
|
|
10113
10220
|
if (missing.length > 0) {
|
|
10114
10221
|
return {
|
|
10115
10222
|
valid: false,
|
|
10116
|
-
error: `Error: Must provide ${missing.join(", ")} when providing --
|
|
10223
|
+
error: `Error: Must provide ${missing.join(", ")} when providing --pull-secret`
|
|
10117
10224
|
};
|
|
10118
10225
|
}
|
|
10119
10226
|
return { valid: true };
|
|
@@ -10134,15 +10241,15 @@ function generateImagePullSecret(details) {
|
|
|
10134
10241
|
};
|
|
10135
10242
|
}
|
|
10136
10243
|
async function getUserConfirmation(opts) {
|
|
10137
|
-
if (opts.
|
|
10244
|
+
if (opts.yes) {
|
|
10138
10245
|
return true;
|
|
10139
10246
|
}
|
|
10140
|
-
const
|
|
10247
|
+
const confirmation = await (0, import_prompts.default)({
|
|
10141
10248
|
type: "confirm",
|
|
10142
|
-
name: "
|
|
10249
|
+
name: "yes",
|
|
10143
10250
|
message: "This will remove and redeploy the module. Continue?"
|
|
10144
10251
|
});
|
|
10145
|
-
return
|
|
10252
|
+
return confirmation.yes ? true : false;
|
|
10146
10253
|
}
|
|
10147
10254
|
async function buildAndDeployModule(image, force) {
|
|
10148
10255
|
const builtModule = await buildModule();
|
|
@@ -10170,7 +10277,7 @@ async function buildAndDeployModule(image, force) {
|
|
|
10170
10277
|
}
|
|
10171
10278
|
}
|
|
10172
10279
|
function deploy_default(program2) {
|
|
10173
|
-
program2.command("deploy").description("Deploy a Pepr Module").option("-
|
|
10280
|
+
program2.command("deploy").description("Deploy a Pepr Module").option("-E, --docker-email <email>", "Email for Docker registry.").option("-P, --docker-password <password>", "Password for Docker registry.").option("-S, --docker-server <server>", "Docker server address.").option("-U, --docker-username <username>", "Docker registry username.").option("-f, --force", "Force deploy the module, override manager field.").option("-i, --image <image>", "Override the image tag.").option("-p, --pull-secret <name>", "Deploy imagePullSecret for Controller private registry.").option("-y, --yes", "Skip confirmation prompts.").action(async (opts) => {
|
|
10174
10281
|
const valResp = validateImagePullSecretDetails(opts);
|
|
10175
10282
|
if (!valResp.valid) {
|
|
10176
10283
|
console.error(valResp.error);
|
|
@@ -10202,14 +10309,14 @@ var import_child_process4 = require("child_process");
|
|
|
10202
10309
|
var import_kubernetes_fluent_client5 = require("kubernetes-fluent-client");
|
|
10203
10310
|
var import_fs12 = require("fs");
|
|
10204
10311
|
function dev_default(program2) {
|
|
10205
|
-
program2.command("dev").description("Setup a local webhook development environment").option("-
|
|
10206
|
-
if (!opts.
|
|
10312
|
+
program2.command("dev").description("Setup a local webhook development environment").option("-H, --host <host>", "Host to listen on", "host.k3d.internal").option("-y, --yes", "Skip confirmation prompt").action(async (opts) => {
|
|
10313
|
+
if (!opts.yes) {
|
|
10207
10314
|
const confirm2 = await (0, import_prompts2.default)({
|
|
10208
10315
|
type: "confirm",
|
|
10209
|
-
name: "
|
|
10316
|
+
name: "yes",
|
|
10210
10317
|
message: "This will remove and redeploy the module. Continue?"
|
|
10211
10318
|
});
|
|
10212
|
-
if (!confirm2.
|
|
10319
|
+
if (!confirm2.yes) {
|
|
10213
10320
|
process.exitCode = 0;
|
|
10214
10321
|
return;
|
|
10215
10322
|
}
|
|
@@ -10492,7 +10599,7 @@ async function setErrorBehavior(errorBehavior) {
|
|
|
10492
10599
|
async function confirm(dirName, packageJSON2, peprTSPath, skipPrompt) {
|
|
10493
10600
|
const confirmationPrompt = {
|
|
10494
10601
|
type: "confirm",
|
|
10495
|
-
name: "
|
|
10602
|
+
name: "yes",
|
|
10496
10603
|
message: "Create the new Pepr module?"
|
|
10497
10604
|
};
|
|
10498
10605
|
const confirmationMessage = `To be generated:
|
|
@@ -10515,17 +10622,20 @@ ${packageJSON2.print.replace(/^/gm, " \u2502 ")}
|
|
|
10515
10622
|
} else {
|
|
10516
10623
|
console.log(confirmationMessage);
|
|
10517
10624
|
const confirm2 = await (0, import_prompts3.default)([confirmationPrompt]);
|
|
10518
|
-
const shouldCreateModule = confirm2.
|
|
10625
|
+
const shouldCreateModule = confirm2.yes === "y" || confirm2.yes === "yes" || confirm2.yes === true ? true : false;
|
|
10519
10626
|
return shouldCreateModule;
|
|
10520
10627
|
}
|
|
10521
10628
|
}
|
|
10522
10629
|
|
|
10523
10630
|
// src/cli/init/index.ts
|
|
10631
|
+
var import_commander2 = require("commander");
|
|
10524
10632
|
function init_default(program2) {
|
|
10525
10633
|
let response = {};
|
|
10526
10634
|
let pkgOverride = "";
|
|
10527
|
-
program2.command("init").description("Initialize a new Pepr Module").option("
|
|
10528
|
-
"--
|
|
10635
|
+
program2.command("init").description("Initialize a new Pepr Module").option("-d, --description <string>", "Explain the purpose of the new module.").addOption(
|
|
10636
|
+
new import_commander2.Option("-e, --error-behavior <behavior>", "Set an error behavior.").choices(ErrorList)
|
|
10637
|
+
).option("-n, --name <string>", "Set the name of the new module.").option("-s, --skip-post-init", "Skip npm install, git init, and VSCode launch.").option(
|
|
10638
|
+
"-u, --uuid <string>",
|
|
10529
10639
|
"Unique identifier for your module with a max length of 36 characters.",
|
|
10530
10640
|
(uuid) => {
|
|
10531
10641
|
if (uuid.length > UUID_LENGTH_LIMIT) {
|
|
@@ -10533,7 +10643,7 @@ function init_default(program2) {
|
|
|
10533
10643
|
}
|
|
10534
10644
|
return uuid.toLocaleLowerCase();
|
|
10535
10645
|
}
|
|
10536
|
-
).hook("preAction", async (thisCommand) => {
|
|
10646
|
+
).option("-y, --yes", "Skip verification prompt when creating a new module.").hook("preAction", async (thisCommand) => {
|
|
10537
10647
|
if (process.env.TEST_MODE === "true") {
|
|
10538
10648
|
import_prompts4.default.inject([
|
|
10539
10649
|
"pepr-test-module",
|
|
@@ -10551,7 +10661,7 @@ function init_default(program2) {
|
|
|
10551
10661
|
}).action(async (opts) => {
|
|
10552
10662
|
const dirName = sanitizeName(response.name);
|
|
10553
10663
|
const packageJSON2 = genPkgJSON(response, pkgOverride);
|
|
10554
|
-
const confirmed = await confirm(dirName, packageJSON2, peprTSTemplate.path, opts.
|
|
10664
|
+
const confirmed = await confirm(dirName, packageJSON2, peprTSTemplate.path, opts.yes);
|
|
10555
10665
|
if (confirmed) {
|
|
10556
10666
|
console.log("Creating new Pepr module...");
|
|
10557
10667
|
try {
|
|
@@ -10642,15 +10752,8 @@ function uuid_default(program2) {
|
|
|
10642
10752
|
});
|
|
10643
10753
|
}
|
|
10644
10754
|
|
|
10645
|
-
// src/cli
|
|
10646
|
-
var
|
|
10647
|
-
var RootCmd = class extends import_commander2.Command {
|
|
10648
|
-
// eslint-disable-next-line class-methods-use-this
|
|
10649
|
-
createCommand(name2) {
|
|
10650
|
-
const cmd = new import_commander2.Command(name2);
|
|
10651
|
-
return cmd;
|
|
10652
|
-
}
|
|
10653
|
-
};
|
|
10755
|
+
// src/cli.ts
|
|
10756
|
+
var import_commander5 = require("commander");
|
|
10654
10757
|
|
|
10655
10758
|
// src/cli/update/index.ts
|
|
10656
10759
|
var import_child_process6 = require("child_process");
|
|
@@ -10658,7 +10761,7 @@ var import_fs14 = __toESM(require("fs"));
|
|
|
10658
10761
|
var import_path6 = require("path");
|
|
10659
10762
|
var import_prompts5 = __toESM(require("prompts"));
|
|
10660
10763
|
function update_default(program2) {
|
|
10661
|
-
program2.command("update").description("Update this Pepr module. Not recommended for prod as it may change files.").option("--skip-template-update", "
|
|
10764
|
+
program2.command("update").description("Update this Pepr module. Not recommended for prod as it may change files.").option("-s, --skip-template-update", "Do not update template files").action(async (opts) => {
|
|
10662
10765
|
if (!opts.skipTemplateUpdate) {
|
|
10663
10766
|
const { confirm: confirm2 } = await (0, import_prompts5.default)({
|
|
10664
10767
|
type: "confirm",
|
|
@@ -10669,7 +10772,7 @@ function update_default(program2) {
|
|
|
10669
10772
|
return;
|
|
10670
10773
|
}
|
|
10671
10774
|
}
|
|
10672
|
-
|
|
10775
|
+
logger_default.info("Updating the Pepr module...");
|
|
10673
10776
|
try {
|
|
10674
10777
|
(0, import_child_process6.execSync)("npm install pepr@latest", {
|
|
10675
10778
|
stdio: "inherit"
|
|
@@ -10679,14 +10782,14 @@ function update_default(program2) {
|
|
|
10679
10782
|
stdio: "inherit"
|
|
10680
10783
|
});
|
|
10681
10784
|
}
|
|
10682
|
-
|
|
10683
|
-
} catch (
|
|
10684
|
-
|
|
10785
|
+
logger_default.info(`\u2705 Module updated successfully`);
|
|
10786
|
+
} catch (error) {
|
|
10787
|
+
logger_default.error(error, `Error updating Pepr module:`);
|
|
10685
10788
|
process.exitCode = 1;
|
|
10686
10789
|
}
|
|
10687
10790
|
});
|
|
10688
10791
|
program2.command("update-templates", { hidden: true }).description("Perform template updates").action(async (opts) => {
|
|
10689
|
-
|
|
10792
|
+
logger_default.info("Updating Pepr config and template files...");
|
|
10690
10793
|
try {
|
|
10691
10794
|
if (!opts.skipTemplateUpdate) {
|
|
10692
10795
|
await write((0, import_path6.resolve)(prettier.path), prettier.data);
|
|
@@ -10703,9 +10806,8 @@ function update_default(program2) {
|
|
|
10703
10806
|
await write(tsPath, helloPepr.data);
|
|
10704
10807
|
}
|
|
10705
10808
|
}
|
|
10706
|
-
|
|
10707
|
-
|
|
10708
|
-
console.error(`Error updating template files:`, e);
|
|
10809
|
+
} catch (error) {
|
|
10810
|
+
logger_default.error(error, `Error updating template files:`);
|
|
10709
10811
|
process.exitCode = 1;
|
|
10710
10812
|
}
|
|
10711
10813
|
});
|
|
@@ -10715,14 +10817,16 @@ function update_default(program2) {
|
|
|
10715
10817
|
var import_child_process7 = require("child_process");
|
|
10716
10818
|
var import_prompts6 = __toESM(require("prompts"));
|
|
10717
10819
|
function kfc_default(program2) {
|
|
10718
|
-
program2.command("kfc [args...]").description("Execute Kubernetes Fluent Client commands").action(async (args) => {
|
|
10719
|
-
|
|
10720
|
-
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10820
|
+
program2.command("kfc [args...]").description("Execute Kubernetes Fluent Client commands").option("-y, --yes", "Skip confirmation prompt.").action(async (args, options) => {
|
|
10821
|
+
if (!options.yes) {
|
|
10822
|
+
const { confirm: confirm2 } = await (0, import_prompts6.default)({
|
|
10823
|
+
type: "confirm",
|
|
10824
|
+
name: "confirm",
|
|
10825
|
+
message: "For commands that generate files, this may overwrite any previously generated files.\nAre you sure you want to continue?"
|
|
10826
|
+
});
|
|
10827
|
+
if (!confirm2) {
|
|
10828
|
+
return;
|
|
10829
|
+
}
|
|
10726
10830
|
}
|
|
10727
10831
|
try {
|
|
10728
10832
|
if (args.length === 0) {
|
|
@@ -10743,13 +10847,13 @@ function kfc_default(program2) {
|
|
|
10743
10847
|
var import_commander3 = require("commander");
|
|
10744
10848
|
var import_fs15 = require("fs");
|
|
10745
10849
|
var import_path7 = __toESM(require("path"));
|
|
10746
|
-
var create = new import_commander3.Command("create").description("Create a new CRD TypeScript definition").
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
"Namespaced"
|
|
10751
|
-
).option("--
|
|
10752
|
-
console.log("This feature is currently in alpha
|
|
10850
|
+
var create = new import_commander3.Command("create").description("Create a new CRD TypeScript definition").addOption(
|
|
10851
|
+
new import_commander3.Option(
|
|
10852
|
+
"-S, --scope <scope>",
|
|
10853
|
+
"Whether the resulting custom resource is cluster- or namespace-scoped"
|
|
10854
|
+
).choices(["Namespaced", "Cluster"]).default("Namespaced")
|
|
10855
|
+
).option("-d, --domain <domain>", "Optional domain for CRD (e.g. pepr.dev)", "pepr.dev").requiredOption("-g, --group <group>", "API group (e.g. cache)").requiredOption("-k, --kind <kind>", "Kind name (e.g. memcached)").option("-p, --plural <plural>", "Plural name for CRD (e.g. memcacheds)").requiredOption("-s, --short-name <name>", "Short name for CRD (e.g. mc)", "").requiredOption("-v, --version <version>", "API version (e.g. v1alpha1)").action(async ({ group: group2, version: version3, kind: kind8, domain, scope, plural: plural2, shortName }) => {
|
|
10856
|
+
console.log("This feature is currently in alpha.");
|
|
10753
10857
|
const outputDir2 = import_path7.default.resolve(`./api/${version3}`);
|
|
10754
10858
|
await createDirectoryIfNotExists(outputDir2);
|
|
10755
10859
|
await import_fs15.promises.writeFile(
|
|
@@ -10838,12 +10942,6 @@ type ${kind8}StatusCondition = {
|
|
|
10838
10942
|
|
|
10839
10943
|
`;
|
|
10840
10944
|
};
|
|
10841
|
-
function validateScope(value) {
|
|
10842
|
-
if (value !== "Cluster" && value !== "Namespaced") {
|
|
10843
|
-
throw new Error("Scope must be either 'Cluster' or 'Namespaced'");
|
|
10844
|
-
}
|
|
10845
|
-
return value;
|
|
10846
|
-
}
|
|
10847
10945
|
|
|
10848
10946
|
// src/cli/crd/generate.ts
|
|
10849
10947
|
var import_commander4 = require("commander");
|
|
@@ -10865,7 +10963,9 @@ var WarningMessages = {
|
|
|
10865
10963
|
};
|
|
10866
10964
|
|
|
10867
10965
|
// src/cli/crd/generate.ts
|
|
10868
|
-
var generate_default = new import_commander4.Command("generate").description(
|
|
10966
|
+
var generate_default = new import_commander4.Command("generate").description(
|
|
10967
|
+
"Generate CRD manifests from TypeScript definitions stored in 'api/' of the current directory."
|
|
10968
|
+
).option("-o, --output <directory>", "Output directory for generated CRDs", "./crds").action(generateCRDs);
|
|
10869
10969
|
function extractCRDDetails(content, sourceFile) {
|
|
10870
10970
|
const kind8 = extractSingleLineComment(content, "Kind");
|
|
10871
10971
|
const group2 = extractSingleLineComment(content, "Group") ?? "example";
|
|
@@ -10877,7 +10977,7 @@ function extractCRDDetails(content, sourceFile) {
|
|
|
10877
10977
|
return { kind: kind8, plural: plural2, scope, shortNames, fqdn };
|
|
10878
10978
|
}
|
|
10879
10979
|
async function generateCRDs(options) {
|
|
10880
|
-
|
|
10980
|
+
logger_default.warn("This feature is currently in alpha.\n");
|
|
10881
10981
|
const outputDir2 = import_path8.default.resolve(options.output);
|
|
10882
10982
|
await createDirectoryIfNotExists(outputDir2);
|
|
10883
10983
|
const project = new import_ts_morph.Project();
|
|
@@ -10902,12 +11002,12 @@ function processSourceFile(sourceFile, version3, outputDir2) {
|
|
|
10902
11002
|
const content = sourceFile.getFullText();
|
|
10903
11003
|
const { kind: kind8, fqdn, scope, plural: plural2, shortNames } = extractCRDDetails(content, sourceFile);
|
|
10904
11004
|
if (!kind8) {
|
|
10905
|
-
|
|
11005
|
+
logger_default.warn(WarningMessages.MISSING_KIND_COMMENT(sourceFile.getBaseName()));
|
|
10906
11006
|
return;
|
|
10907
11007
|
}
|
|
10908
11008
|
const spec = sourceFile.getInterface(`${kind8}Spec`);
|
|
10909
11009
|
if (!spec) {
|
|
10910
|
-
|
|
11010
|
+
logger_default.warn(WarningMessages.MISSING_INTERFACE(sourceFile.getBaseName(), kind8));
|
|
10911
11011
|
return;
|
|
10912
11012
|
}
|
|
10913
11013
|
const condition = sourceFile.getTypeAlias(`${kind8}StatusCondition`);
|
|
@@ -10925,7 +11025,7 @@ function processSourceFile(sourceFile, version3, outputDir2) {
|
|
|
10925
11025
|
});
|
|
10926
11026
|
const outPath = import_path8.default.join(outputDir2, `${kind8.toLowerCase()}.yaml`);
|
|
10927
11027
|
import_fs16.default.writeFileSync(outPath, (0, import_yaml.stringify)(crd), "utf8");
|
|
10928
|
-
|
|
11028
|
+
logger_default.info(`\u2714 Created ${outPath}`);
|
|
10929
11029
|
}
|
|
10930
11030
|
function extractSingleLineComment(content, label) {
|
|
10931
11031
|
const match = content.match(new RegExp(`//\\s+${label}:\\s+(.*)`));
|
|
@@ -11090,7 +11190,7 @@ function crd_default(program2) {
|
|
|
11090
11190
|
if (process.env.npm_lifecycle_event !== "npx") {
|
|
11091
11191
|
console.info("Pepr should be run via `npx pepr <command>` instead of `pepr <command>`.");
|
|
11092
11192
|
}
|
|
11093
|
-
var program = new
|
|
11193
|
+
var program = new import_commander5.Command();
|
|
11094
11194
|
if (!process.env.PEPR_NODE_WARNINGS) {
|
|
11095
11195
|
process.removeAllListeners("warning");
|
|
11096
11196
|
}
|