pepr 0.51.6-nightly.3 → 0.51.6-nightly.5
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.map +1 -1
- package/dist/cli/build.helpers.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts +1 -1
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli.js +229 -130
- 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 +1 -1
- package/src/cli/build.helpers.ts +17 -2
- package/src/cli/build.ts +27 -39
- package/src/cli/deploy.ts +13 -13
- package/src/lib/assets/assets.ts +81 -22
- package/src/lib/assets/deploy.ts +26 -12
- package/src/lib/assets/helm.ts +31 -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 +4 -1
- package/src/templates/tsconfig.module.json +2 -2
- package/dist/lib/assets/envrionment.d.ts.map +0 -1
- package/dist/lib/assets/pods.d.ts.map +0 -1
- /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:
|
|
@@ -7593,10 +7594,12 @@ function watcherDeployTemplate(buildTimestamp) {
|
|
|
7593
7594
|
{{- if .Values.watcher.extraVolumes }}
|
|
7594
7595
|
{{- toYaml .Values.watcher.extraVolumes | nindent 8 }}
|
|
7595
7596
|
{{- end }}
|
|
7597
|
+
{{- end }}
|
|
7596
7598
|
`;
|
|
7597
7599
|
}
|
|
7598
|
-
function admissionDeployTemplate(buildTimestamp) {
|
|
7600
|
+
function admissionDeployTemplate(buildTimestamp, type) {
|
|
7599
7601
|
return `
|
|
7602
|
+
{{- if .Values.${type}.enabled }}
|
|
7600
7603
|
apiVersion: apps/v1
|
|
7601
7604
|
kind: Deployment
|
|
7602
7605
|
metadata:
|
|
@@ -7708,6 +7711,7 @@ function admissionDeployTemplate(buildTimestamp) {
|
|
|
7708
7711
|
{{- if .Values.admission.extraVolumes }}
|
|
7709
7712
|
{{- toYaml .Values.admission.extraVolumes | nindent 8 }}
|
|
7710
7713
|
{{- end }}
|
|
7714
|
+
{{- end }}
|
|
7711
7715
|
`;
|
|
7712
7716
|
}
|
|
7713
7717
|
function serviceMonitorTemplate(name2, type) {
|
|
@@ -7737,6 +7741,27 @@ function serviceMonitorTemplate(name2, type) {
|
|
|
7737
7741
|
{{- end }}
|
|
7738
7742
|
`;
|
|
7739
7743
|
}
|
|
7744
|
+
function serviceTemplate(name2, type) {
|
|
7745
|
+
const svcName = type === "admission" ? name2 : `${name2}-${type}`;
|
|
7746
|
+
return `
|
|
7747
|
+
{{- if .Values.${type}.enabled }}
|
|
7748
|
+
apiVersion: v1
|
|
7749
|
+
kind: Service
|
|
7750
|
+
metadata:
|
|
7751
|
+
name: ${svcName}
|
|
7752
|
+
namespace: pepr-system
|
|
7753
|
+
labels:
|
|
7754
|
+
pepr.dev/controller: ${type}
|
|
7755
|
+
spec:
|
|
7756
|
+
selector:
|
|
7757
|
+
app: ${svcName}
|
|
7758
|
+
pepr.dev/controller: ${type}
|
|
7759
|
+
ports:
|
|
7760
|
+
- port: 443
|
|
7761
|
+
targetPort: 3000
|
|
7762
|
+
{{- end }}
|
|
7763
|
+
`;
|
|
7764
|
+
}
|
|
7740
7765
|
|
|
7741
7766
|
// src/lib/filesystemService.ts
|
|
7742
7767
|
var import_fs = require("fs");
|
|
@@ -7752,7 +7777,7 @@ async function createDirectoryIfNotExists(path4) {
|
|
|
7752
7777
|
}
|
|
7753
7778
|
}
|
|
7754
7779
|
|
|
7755
|
-
// src/lib/assets/
|
|
7780
|
+
// src/lib/assets/environment.ts
|
|
7756
7781
|
function genEnv(config, watchMode = false, ignoreWatchMode = false) {
|
|
7757
7782
|
const noWatchDef = {
|
|
7758
7783
|
PEPR_PRETTY_LOG: "false",
|
|
@@ -8090,7 +8115,7 @@ function resolveIgnoreNamespaces(ignoredNSConfig = []) {
|
|
|
8090
8115
|
}
|
|
8091
8116
|
|
|
8092
8117
|
// src/lib/assets/yaml/overridesFile.ts
|
|
8093
|
-
async function overridesFile({ hash, name: name2, image, config, apiPath, capabilities }, path4, imagePullSecrets) {
|
|
8118
|
+
async function overridesFile({ hash, name: name2, image, config, apiPath, capabilities }, path4, imagePullSecrets, controllerType = { admission: true, watcher: true }) {
|
|
8094
8119
|
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
8095
8120
|
const overrides = {
|
|
8096
8121
|
imagePullSecrets,
|
|
@@ -8110,6 +8135,7 @@ async function overridesFile({ hash, name: name2, image, config, apiPath, capabi
|
|
|
8110
8135
|
},
|
|
8111
8136
|
uuid: name2,
|
|
8112
8137
|
admission: {
|
|
8138
|
+
enabled: controllerType.admission === true ? true : false,
|
|
8113
8139
|
antiAffinity: false,
|
|
8114
8140
|
terminationGracePeriodSeconds: 5,
|
|
8115
8141
|
failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
|
|
@@ -8179,6 +8205,7 @@ async function overridesFile({ hash, name: name2, image, config, apiPath, capabi
|
|
|
8179
8205
|
}
|
|
8180
8206
|
},
|
|
8181
8207
|
watcher: {
|
|
8208
|
+
enabled: controllerType.watcher === true ? true : false,
|
|
8182
8209
|
terminationGracePeriodSeconds: 5,
|
|
8183
8210
|
env: genEnv(config, true, true),
|
|
8184
8211
|
envFrom: [],
|
|
@@ -8386,58 +8413,36 @@ function tlsSecret(name2, tls) {
|
|
|
8386
8413
|
}
|
|
8387
8414
|
};
|
|
8388
8415
|
}
|
|
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
|
-
]
|
|
8416
|
+
|
|
8417
|
+
// src/lib/assets/assets.ts
|
|
8418
|
+
function norWatchOrAdmission(capabilities) {
|
|
8419
|
+
return !isAdmission(capabilities) && !isWatcher(capabilities);
|
|
8420
|
+
}
|
|
8421
|
+
function isAdmission(capabilities) {
|
|
8422
|
+
for (const capability of capabilities) {
|
|
8423
|
+
const admissionBindings = capability.bindings.filter(
|
|
8424
|
+
(binding) => binding.isFinalize || binding.isMutate || binding.isValidate
|
|
8425
|
+
);
|
|
8426
|
+
if (admissionBindings.length > 0) {
|
|
8427
|
+
return true;
|
|
8411
8428
|
}
|
|
8412
|
-
}
|
|
8429
|
+
}
|
|
8430
|
+
return false;
|
|
8413
8431
|
}
|
|
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
|
-
]
|
|
8432
|
+
function isWatcher(capabilities) {
|
|
8433
|
+
for (const capability of capabilities) {
|
|
8434
|
+
if (capability.hasSchedule) {
|
|
8435
|
+
return true;
|
|
8436
8436
|
}
|
|
8437
|
-
|
|
8437
|
+
const watcherBindings = capability.bindings.filter(
|
|
8438
|
+
(binding) => binding.isFinalize || binding.isWatch || binding.isQueue
|
|
8439
|
+
);
|
|
8440
|
+
if (watcherBindings.length > 0) {
|
|
8441
|
+
return true;
|
|
8442
|
+
}
|
|
8443
|
+
}
|
|
8444
|
+
return false;
|
|
8438
8445
|
}
|
|
8439
|
-
|
|
8440
|
-
// src/lib/assets/assets.ts
|
|
8441
8446
|
var Assets = class {
|
|
8442
8447
|
name;
|
|
8443
8448
|
tls;
|
|
@@ -8469,7 +8474,7 @@ var Assets = class {
|
|
|
8469
8474
|
}
|
|
8470
8475
|
zarfYaml = (zarfYamlGenerator, path4) => zarfYamlGenerator(this, path4, "manifests");
|
|
8471
8476
|
zarfYamlChart = (zarfYamlGenerator, path4) => zarfYamlGenerator(this, path4, "charts");
|
|
8472
|
-
allYaml = async (yamlGenerationFunction,
|
|
8477
|
+
allYaml = async (yamlGenerationFunction, getControllerManifests, imagePullSecret) => {
|
|
8473
8478
|
this.capabilities = await loadCapabilities(this.path);
|
|
8474
8479
|
for (const capability of this.capabilities) {
|
|
8475
8480
|
namespaceComplianceValidator(capability, this.alwaysIgnore?.namespaces);
|
|
@@ -8483,16 +8488,30 @@ var Assets = class {
|
|
|
8483
8488
|
const code = await import_fs3.promises.readFile(this.path);
|
|
8484
8489
|
const moduleHash = import_crypto.default.createHash("sha256").update(code).digest("hex");
|
|
8485
8490
|
const deployments = {
|
|
8486
|
-
|
|
8487
|
-
|
|
8491
|
+
admission: getControllerManifests.getDeploymentFunction(
|
|
8492
|
+
this,
|
|
8493
|
+
moduleHash,
|
|
8494
|
+
this.buildTimestamp,
|
|
8495
|
+
imagePullSecret
|
|
8496
|
+
),
|
|
8497
|
+
watch: getControllerManifests.getWatcherFunction(
|
|
8498
|
+
this,
|
|
8499
|
+
moduleHash,
|
|
8500
|
+
this.buildTimestamp,
|
|
8501
|
+
imagePullSecret
|
|
8502
|
+
)
|
|
8503
|
+
};
|
|
8504
|
+
const services = {
|
|
8505
|
+
admission: getControllerManifests.getServiceFunction(this.name, this),
|
|
8506
|
+
watch: getControllerManifests.getWatcherServiceFunction(this.name, this)
|
|
8488
8507
|
};
|
|
8489
|
-
return yamlGenerationFunction(this, deployments);
|
|
8508
|
+
return yamlGenerationFunction(this, deployments, services);
|
|
8490
8509
|
};
|
|
8491
8510
|
writeWebhookFiles = async (validateWebhook, mutateWebhook, helm) => {
|
|
8492
8511
|
if (validateWebhook || mutateWebhook) {
|
|
8493
8512
|
await import_fs3.promises.writeFile(
|
|
8494
8513
|
helm.files.admissionDeploymentYaml,
|
|
8495
|
-
dedent(admissionDeployTemplate(this.buildTimestamp))
|
|
8514
|
+
dedent(admissionDeployTemplate(this.buildTimestamp, "admission"))
|
|
8496
8515
|
);
|
|
8497
8516
|
await import_fs3.promises.writeFile(
|
|
8498
8517
|
helm.files.admissionServiceMonitorYaml,
|
|
@@ -8531,8 +8550,14 @@ var Assets = class {
|
|
|
8531
8550
|
() => dedent(chartYaml(this.config.uuid, this.config.description || ""))
|
|
8532
8551
|
],
|
|
8533
8552
|
[helm.files.namespaceYaml, () => dedent(namespaceTemplate())],
|
|
8534
|
-
[
|
|
8535
|
-
|
|
8553
|
+
[
|
|
8554
|
+
helm.files.watcherServiceYaml,
|
|
8555
|
+
() => dedent(serviceTemplate(this.name, "watcher"))
|
|
8556
|
+
],
|
|
8557
|
+
[
|
|
8558
|
+
helm.files.admissionServiceYaml,
|
|
8559
|
+
() => dedent(serviceTemplate(this.name, "admission"))
|
|
8560
|
+
],
|
|
8536
8561
|
[helm.files.tlsSecretYaml, () => toYaml(tlsSecret(this.name, this.tls))],
|
|
8537
8562
|
[
|
|
8538
8563
|
helm.files.apiPathSecretYaml,
|
|
@@ -8557,7 +8582,10 @@ var Assets = class {
|
|
|
8557
8582
|
apiPath: this.apiPath,
|
|
8558
8583
|
capabilities: this.capabilities
|
|
8559
8584
|
};
|
|
8560
|
-
await overridesFile(overrideData, helm.files.valuesYaml, this.imagePullSecrets
|
|
8585
|
+
await overridesFile(overrideData, helm.files.valuesYaml, this.imagePullSecrets, {
|
|
8586
|
+
admission: isAdmission(this.capabilities) || norWatchOrAdmission(this.capabilities),
|
|
8587
|
+
watcher: isWatcher(this.capabilities)
|
|
8588
|
+
});
|
|
8561
8589
|
const webhooks = {
|
|
8562
8590
|
mutate: await webhookGeneratorFunction(
|
|
8563
8591
|
this,
|
|
@@ -8575,7 +8603,7 @@ var Assets = class {
|
|
|
8575
8603
|
if (watchDeployment) {
|
|
8576
8604
|
await import_fs3.promises.writeFile(
|
|
8577
8605
|
helm.files.watcherDeploymentYaml,
|
|
8578
|
-
dedent(watcherDeployTemplate(this.buildTimestamp))
|
|
8606
|
+
dedent(watcherDeployTemplate(this.buildTimestamp, "watcher"))
|
|
8579
8607
|
);
|
|
8580
8608
|
await import_fs3.promises.writeFile(
|
|
8581
8609
|
helm.files.watcherServiceMonitorYaml,
|
|
@@ -8822,8 +8850,8 @@ var tsconfig_module_default = {
|
|
|
8822
8850
|
emitDeclarationOnly: true,
|
|
8823
8851
|
esModuleInterop: true,
|
|
8824
8852
|
lib: ["ES2022"],
|
|
8825
|
-
module: "
|
|
8826
|
-
moduleResolution: "
|
|
8853
|
+
module: "NodeNext",
|
|
8854
|
+
moduleResolution: "NodeNext",
|
|
8827
8855
|
outDir: "dist",
|
|
8828
8856
|
resolveJsonModule: true,
|
|
8829
8857
|
rootDir: ".",
|
|
@@ -8839,7 +8867,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
8839
8867
|
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
8868
|
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
8869
|
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.51.6-nightly.
|
|
8870
|
+
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.51.6-nightly.5", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc -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) .", "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": "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 && npm run test:journey:upgrade", "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", "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 pepr-upgrade-test --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'", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && vitest run --config=config/vitest.journey.config.ts journey/pepr-upgrade.test.ts", "test:unit": "npm run gen-data-json && NODE_OPTIONS=--no-deprecation vitest --config config/vitest.root.config.ts run --coverage", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, 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.0", 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.12", "@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", "brace-expansion": "1.1.11" }, 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
8871
|
|
|
8844
8872
|
// src/cli/init/utils.ts
|
|
8845
8873
|
var import_fs4 = require("fs");
|
|
@@ -9078,7 +9106,7 @@ var import_fs9 = require("fs");
|
|
|
9078
9106
|
var import_crypto2 = __toESM(require("crypto"));
|
|
9079
9107
|
var import_client_node4 = require("@kubernetes/client-node");
|
|
9080
9108
|
|
|
9081
|
-
// src/lib/assets/
|
|
9109
|
+
// src/lib/assets/k8sObjects.ts
|
|
9082
9110
|
var import_zlib = require("zlib");
|
|
9083
9111
|
function getNamespace(namespaceLabels) {
|
|
9084
9112
|
if (namespaceLabels) {
|
|
@@ -9101,20 +9129,11 @@ function getNamespace(namespaceLabels) {
|
|
|
9101
9129
|
}
|
|
9102
9130
|
}
|
|
9103
9131
|
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) {
|
|
9132
|
+
const { name: name2, image, config } = assets;
|
|
9133
|
+
if (!isWatcher(assets.capabilities)) {
|
|
9116
9134
|
return null;
|
|
9117
9135
|
}
|
|
9136
|
+
const app = `${name2}-watcher`;
|
|
9118
9137
|
const deploy = {
|
|
9119
9138
|
apiVersion: "apps/v1",
|
|
9120
9139
|
kind: "Deployment",
|
|
@@ -9247,6 +9266,9 @@ function getWatcher(assets, hash, buildTimestamp, imagePullSecret) {
|
|
|
9247
9266
|
function getDeployment(assets, hash, buildTimestamp, imagePullSecret) {
|
|
9248
9267
|
const { name: name2, image, config } = assets;
|
|
9249
9268
|
const app = name2;
|
|
9269
|
+
if (!isAdmission(assets.capabilities) && !norWatchOrAdmission(assets.capabilities)) {
|
|
9270
|
+
return null;
|
|
9271
|
+
}
|
|
9250
9272
|
const deploy = {
|
|
9251
9273
|
apiVersion: "apps/v1",
|
|
9252
9274
|
kind: "Deployment",
|
|
@@ -9407,6 +9429,62 @@ function getModuleSecret(name2, data, hash) {
|
|
|
9407
9429
|
};
|
|
9408
9430
|
}
|
|
9409
9431
|
}
|
|
9432
|
+
function service(name2, assets) {
|
|
9433
|
+
if (!isAdmission(assets.capabilities) && !norWatchOrAdmission(assets.capabilities)) {
|
|
9434
|
+
return null;
|
|
9435
|
+
}
|
|
9436
|
+
return {
|
|
9437
|
+
apiVersion: "v1",
|
|
9438
|
+
kind: "Service",
|
|
9439
|
+
metadata: {
|
|
9440
|
+
name: name2,
|
|
9441
|
+
namespace: "pepr-system",
|
|
9442
|
+
labels: {
|
|
9443
|
+
"pepr.dev/controller": "admission"
|
|
9444
|
+
}
|
|
9445
|
+
},
|
|
9446
|
+
spec: {
|
|
9447
|
+
selector: {
|
|
9448
|
+
app: name2,
|
|
9449
|
+
"pepr.dev/controller": "admission"
|
|
9450
|
+
},
|
|
9451
|
+
ports: [
|
|
9452
|
+
{
|
|
9453
|
+
port: 443,
|
|
9454
|
+
targetPort: 3e3
|
|
9455
|
+
}
|
|
9456
|
+
]
|
|
9457
|
+
}
|
|
9458
|
+
};
|
|
9459
|
+
}
|
|
9460
|
+
function watcherService(name2, assets) {
|
|
9461
|
+
if (!isWatcher(assets.capabilities)) {
|
|
9462
|
+
return null;
|
|
9463
|
+
}
|
|
9464
|
+
return {
|
|
9465
|
+
apiVersion: "v1",
|
|
9466
|
+
kind: "Service",
|
|
9467
|
+
metadata: {
|
|
9468
|
+
name: `${name2}-watcher`,
|
|
9469
|
+
namespace: "pepr-system",
|
|
9470
|
+
labels: {
|
|
9471
|
+
"pepr.dev/controller": "watcher"
|
|
9472
|
+
}
|
|
9473
|
+
},
|
|
9474
|
+
spec: {
|
|
9475
|
+
selector: {
|
|
9476
|
+
app: `${name2}-watcher`,
|
|
9477
|
+
"pepr.dev/controller": "watcher"
|
|
9478
|
+
},
|
|
9479
|
+
ports: [
|
|
9480
|
+
{
|
|
9481
|
+
port: 443,
|
|
9482
|
+
targetPort: 3e3
|
|
9483
|
+
}
|
|
9484
|
+
]
|
|
9485
|
+
}
|
|
9486
|
+
};
|
|
9487
|
+
}
|
|
9410
9488
|
|
|
9411
9489
|
// src/lib/assets/yaml/generateAllYaml.ts
|
|
9412
9490
|
var import_fs8 = require("fs");
|
|
@@ -9495,24 +9573,37 @@ async function webhookConfigGenerator(assets, mutateOrValidate, timeoutSeconds =
|
|
|
9495
9573
|
}
|
|
9496
9574
|
|
|
9497
9575
|
// src/lib/assets/yaml/generateAllYaml.ts
|
|
9498
|
-
|
|
9576
|
+
function pushControllerManifests(resources, deployments, services) {
|
|
9577
|
+
if (deployments.watch) {
|
|
9578
|
+
resources.push(deployments.watch);
|
|
9579
|
+
}
|
|
9580
|
+
if (deployments.admission) {
|
|
9581
|
+
resources.push(deployments.admission);
|
|
9582
|
+
}
|
|
9583
|
+
if (services.admission) {
|
|
9584
|
+
resources.push(services.admission);
|
|
9585
|
+
}
|
|
9586
|
+
if (services.watch) {
|
|
9587
|
+
resources.push(services.watch);
|
|
9588
|
+
}
|
|
9589
|
+
return resources;
|
|
9590
|
+
}
|
|
9591
|
+
async function generateAllYaml(assets, deployments, services) {
|
|
9499
9592
|
const { name: name2, tls, apiPath, path: path4, config } = assets;
|
|
9500
9593
|
const code = await import_fs8.promises.readFile(path4);
|
|
9501
9594
|
const hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
9502
|
-
|
|
9595
|
+
let resources = [
|
|
9503
9596
|
getNamespace(assets.config.customLabels?.namespace),
|
|
9504
9597
|
clusterRole(name2, assets.capabilities, config.rbacMode, config.rbac),
|
|
9505
9598
|
clusterRoleBinding(name2),
|
|
9506
9599
|
serviceAccount(name2),
|
|
9507
9600
|
apiPathSecret(name2, apiPath),
|
|
9508
9601
|
tlsSecret(name2, tls),
|
|
9509
|
-
deployments.default,
|
|
9510
|
-
service(name2),
|
|
9511
|
-
watcherService(name2),
|
|
9512
9602
|
getModuleSecret(name2, code, hash),
|
|
9513
9603
|
storeRole(name2),
|
|
9514
9604
|
storeRoleBinding(name2)
|
|
9515
9605
|
];
|
|
9606
|
+
resources = pushControllerManifests(resources, deployments, services);
|
|
9516
9607
|
const webhooks = {
|
|
9517
9608
|
mutate: await webhookConfigGenerator(assets, "mutate" /* MUTATE */, assets.config.webhookTimeout),
|
|
9518
9609
|
validate: await webhookConfigGenerator(
|
|
@@ -9521,7 +9612,7 @@ async function generateAllYaml(assets, deployments) {
|
|
|
9521
9612
|
assets.config.webhookTimeout
|
|
9522
9613
|
)
|
|
9523
9614
|
};
|
|
9524
|
-
const additionalResources = [webhooks.mutate, webhooks.validate
|
|
9615
|
+
const additionalResources = [webhooks.mutate, webhooks.validate].filter(
|
|
9525
9616
|
(resource) => resource !== null && resource !== void 0
|
|
9526
9617
|
);
|
|
9527
9618
|
resources.push(...additionalResources);
|
|
@@ -9643,7 +9734,16 @@ async function generateYamlAndWriteToDisk(obj) {
|
|
|
9643
9734
|
const chartPath = `${uuid}-chart`;
|
|
9644
9735
|
const yamlPath = (0, import_path3.resolve)(outputDir2, yamlFile);
|
|
9645
9736
|
try {
|
|
9646
|
-
const yaml = await assets.allYaml(
|
|
9737
|
+
const yaml = await assets.allYaml(
|
|
9738
|
+
generateAllYaml,
|
|
9739
|
+
{
|
|
9740
|
+
getDeploymentFunction: getDeployment,
|
|
9741
|
+
getWatcherFunction: getWatcher,
|
|
9742
|
+
getServiceFunction: service,
|
|
9743
|
+
getWatcherServiceFunction: watcherService
|
|
9744
|
+
},
|
|
9745
|
+
imagePullSecret
|
|
9746
|
+
);
|
|
9647
9747
|
const zarfPath = (0, import_path3.resolve)(outputDir2, "zarf.yaml");
|
|
9648
9748
|
let localZarf = "";
|
|
9649
9749
|
if (zarf === "chart") {
|
|
@@ -9665,48 +9765,39 @@ async function generateYamlAndWriteToDisk(obj) {
|
|
|
9665
9765
|
var peprTS2 = "pepr.ts";
|
|
9666
9766
|
var outputDir = "dist";
|
|
9667
9767
|
function build_default(program2) {
|
|
9668
|
-
program2.command("build").description("Build a Pepr Module for deployment").
|
|
9669
|
-
"-
|
|
9670
|
-
"Disables embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM."
|
|
9671
|
-
).addOption(
|
|
9672
|
-
new import_commander.Option(
|
|
9673
|
-
"-i, --custom-image <custom-image>",
|
|
9674
|
-
"Specify a custom image (including version) for Admission and Watch Deployments. Example: 'docker.io/username/custom-pepr-controller:v1.0.0'"
|
|
9675
|
-
).conflicts(["registryInfo", "registry"])
|
|
9768
|
+
program2.command("build").description("Build a Pepr Module for deployment").addOption(
|
|
9769
|
+
new import_commander.Option("-M, --rbac-mode <admin|scoped>", "Set RBAC mode.").choices(["admin", "scoped"])
|
|
9676
9770
|
).addOption(
|
|
9677
9771
|
new import_commander.Option(
|
|
9678
|
-
"-
|
|
9679
|
-
"Provide the image registry and username for building and pushing a custom WASM container. Requires authentication. Builds and pushes `'registry/username
|
|
9772
|
+
"-I, --registry-info <registry/username>",
|
|
9773
|
+
"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
9774
|
).conflicts(["customImage", "registry"])
|
|
9681
|
-
).option("-
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
|
|
9775
|
+
).option("-P, --with-pull-secret <name>", "Use image pull secret for controller Deployment.", "").addOption(
|
|
9776
|
+
new import_commander.Option(
|
|
9777
|
+
"-c, --custom-name <name>",
|
|
9778
|
+
"Set name for zarf component and service monitors in helm charts."
|
|
9779
|
+
)
|
|
9780
|
+
).option("-e, --entry-point <file>", "Specify the entry point file to build with.", peprTS2).addOption(
|
|
9781
|
+
new import_commander.Option(
|
|
9782
|
+
"-i, --custom-image <image>",
|
|
9783
|
+
"Specify a custom image with version for deployments. Conflicts with --registry-info and --registry. Example: 'docker.io/username/custom-pepr-controller:v1.0.0'"
|
|
9784
|
+
).conflicts(["registryInfo", "registry"])
|
|
9685
9785
|
).option(
|
|
9686
|
-
"--
|
|
9687
|
-
"
|
|
9688
|
-
|
|
9689
|
-
).addOption(
|
|
9786
|
+
"-n, --no-embed",
|
|
9787
|
+
"Disable embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM."
|
|
9788
|
+
).option("-o, --output <directory>", "Set output directory.").addOption(
|
|
9690
9789
|
new import_commander.Option(
|
|
9691
|
-
"--registry <GitHub|Iron Bank>",
|
|
9692
|
-
"Container registry: Choose container registry for deployment manifests.
|
|
9790
|
+
"-r, --registry <GitHub|Iron Bank>",
|
|
9791
|
+
"Container registry: Choose container registry for deployment manifests. Conflicts with --custom-image and --registry-info."
|
|
9693
9792
|
).conflicts(["customImage", "registryInfo"]).choices(["GitHub", "Iron Bank"])
|
|
9793
|
+
).option(
|
|
9794
|
+
"-t, --timeout <seconds>",
|
|
9795
|
+
"How long the API server should wait for a webhook to respond before treating the call as a failure.",
|
|
9796
|
+
parseTimeout
|
|
9694
9797
|
).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
|
-
)
|
|
9798
|
+
new import_commander.Option("-z, --zarf <manifest|chart>", "Set Zarf package type").choices(["manifest", "chart"]).default("manifest")
|
|
9708
9799
|
).action(async (opts) => {
|
|
9709
|
-
outputDir = await handleCustomOutputDir(opts.
|
|
9800
|
+
outputDir = await handleCustomOutputDir(opts.output);
|
|
9710
9801
|
const buildModuleResult = await buildModule(void 0, opts.entryPoint, opts.embed);
|
|
9711
9802
|
const { cfg, path: path4 } = buildModuleResult;
|
|
9712
9803
|
if (opts.customName) {
|
|
@@ -10027,26 +10118,34 @@ async function setupController(assets, code, hash, force) {
|
|
|
10027
10118
|
logger_default.info("Applying module secret");
|
|
10028
10119
|
const mod = getModuleSecret(name2, code, hash);
|
|
10029
10120
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(mod, { force });
|
|
10030
|
-
|
|
10031
|
-
|
|
10032
|
-
|
|
10121
|
+
if (isAdmission(assets.capabilities) || norWatchOrAdmission(assets.capabilities)) {
|
|
10122
|
+
const svc = service(name2, assets);
|
|
10123
|
+
if (svc) {
|
|
10124
|
+
logger_default.info("Applying controller service");
|
|
10125
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Service).Apply(svc, { force });
|
|
10126
|
+
}
|
|
10127
|
+
const dep = getDeployment(assets, hash, assets.buildTimestamp);
|
|
10128
|
+
if (dep) {
|
|
10129
|
+
logger_default.info("Applying deployment");
|
|
10130
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(dep, { force });
|
|
10131
|
+
}
|
|
10132
|
+
}
|
|
10033
10133
|
logger_default.info("Applying TLS secret");
|
|
10034
10134
|
const tls = tlsSecret(name2, assets.tls);
|
|
10035
10135
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(tls, { force });
|
|
10036
10136
|
logger_default.info("Applying API path secret");
|
|
10037
10137
|
const apiPath = apiPathSecret(name2, assets.apiPath);
|
|
10038
10138
|
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
10139
|
}
|
|
10043
10140
|
async function setupWatcher(assets, hash, force) {
|
|
10044
10141
|
const watchDeployment = getWatcher(assets, hash, assets.buildTimestamp);
|
|
10045
10142
|
if (watchDeployment) {
|
|
10046
10143
|
logger_default.info("Applying watcher deployment");
|
|
10047
10144
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(watchDeployment, { force });
|
|
10145
|
+
}
|
|
10146
|
+
const watchSvc = watcherService(assets.name, assets);
|
|
10147
|
+
if (watchSvc) {
|
|
10048
10148
|
logger_default.info("Applying watcher service");
|
|
10049
|
-
const watchSvc = watcherService(assets.name);
|
|
10050
10149
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Service).Apply(watchSvc, { force });
|
|
10051
10150
|
}
|
|
10052
10151
|
}
|
|
@@ -10134,15 +10233,15 @@ function generateImagePullSecret(details) {
|
|
|
10134
10233
|
};
|
|
10135
10234
|
}
|
|
10136
10235
|
async function getUserConfirmation(opts) {
|
|
10137
|
-
if (opts.
|
|
10236
|
+
if (opts.yes) {
|
|
10138
10237
|
return true;
|
|
10139
10238
|
}
|
|
10140
|
-
const
|
|
10239
|
+
const confirmation = await (0, import_prompts.default)({
|
|
10141
10240
|
type: "confirm",
|
|
10142
|
-
name: "
|
|
10241
|
+
name: "yes",
|
|
10143
10242
|
message: "This will remove and redeploy the module. Continue?"
|
|
10144
10243
|
});
|
|
10145
|
-
return
|
|
10244
|
+
return confirmation.yes ? true : false;
|
|
10146
10245
|
}
|
|
10147
10246
|
async function buildAndDeployModule(image, force) {
|
|
10148
10247
|
const builtModule = await buildModule();
|
|
@@ -10170,7 +10269,7 @@ async function buildAndDeployModule(image, force) {
|
|
|
10170
10269
|
}
|
|
10171
10270
|
}
|
|
10172
10271
|
function deploy_default(program2) {
|
|
10173
|
-
program2.command("deploy").description("Deploy a Pepr Module").option("-
|
|
10272
|
+
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
10273
|
const valResp = validateImagePullSecretDetails(opts);
|
|
10175
10274
|
if (!valResp.valid) {
|
|
10176
10275
|
console.error(valResp.error);
|