pepr 0.26.2 → 0.28.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.js +572 -97
- package/dist/controller.js +1 -1
- package/dist/lib/assets/helm.d.ts +5 -0
- package/dist/lib/assets/helm.d.ts.map +1 -0
- package/dist/lib/assets/index.d.ts +4 -0
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/pods.d.ts +9 -2
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts +1 -0
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/filter.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +9 -0
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/k8s.d.ts +0 -11
- package/dist/lib/k8s.d.ts.map +1 -1
- package/dist/lib/module.d.ts +0 -2
- package/dist/lib/module.d.ts.map +1 -1
- package/dist/lib/watch-processor.d.ts.map +1 -1
- package/dist/lib.js +86 -27
- package/dist/lib.js.map +4 -4
- package/package.json +9 -9
- package/src/cli.ts +2 -0
- package/src/lib/assets/deploy.ts +2 -2
- package/src/lib/assets/helm.ts +199 -0
- package/src/lib/assets/index.ts +121 -4
- package/src/lib/assets/pods.ts +22 -12
- package/src/lib/assets/yaml.ts +116 -4
- package/src/lib/filter.ts +4 -1
- package/src/lib/helpers.ts +120 -5
- package/src/lib/k8s.ts +0 -11
- package/src/lib/module.ts +0 -2
- package/src/lib/watch-processor.ts +21 -10
- package/src/templates/package.json +4 -3
package/dist/cli.js
CHANGED
|
@@ -106,8 +106,8 @@ var banner = `\x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[
|
|
|
106
106
|
// src/cli/build.ts
|
|
107
107
|
var import_child_process2 = require("child_process");
|
|
108
108
|
var import_esbuild = require("esbuild");
|
|
109
|
-
var
|
|
110
|
-
var
|
|
109
|
+
var import_fs8 = require("fs");
|
|
110
|
+
var import_path2 = require("path");
|
|
111
111
|
|
|
112
112
|
// src/lib/included-files.ts
|
|
113
113
|
var import_fs = require("fs");
|
|
@@ -127,6 +127,7 @@ async function createDockerfile(version3, description, includedFiles) {
|
|
|
127
127
|
|
|
128
128
|
// src/lib/assets/index.ts
|
|
129
129
|
var import_crypto3 = __toESM(require("crypto"));
|
|
130
|
+
var import_client_node2 = require("@kubernetes/client-node");
|
|
130
131
|
|
|
131
132
|
// src/lib/tls.ts
|
|
132
133
|
var import_node_forge = __toESM(require("node-forge"));
|
|
@@ -295,7 +296,6 @@ var import_zlib = require("zlib");
|
|
|
295
296
|
// src/lib/helpers.ts
|
|
296
297
|
var import_kubernetes_fluent_client = require("kubernetes-fluent-client");
|
|
297
298
|
var import_fs2 = require("fs");
|
|
298
|
-
var import_commander = __toESM(require("commander"));
|
|
299
299
|
var createRBACMap = (capabilities) => {
|
|
300
300
|
return capabilities.reduce((acc, capability) => {
|
|
301
301
|
capability.bindings.forEach((binding) => {
|
|
@@ -404,7 +404,7 @@ async function namespaceDeploymentsReady(namespace2 = "pepr-system") {
|
|
|
404
404
|
if (ready) {
|
|
405
405
|
return ready;
|
|
406
406
|
}
|
|
407
|
-
await new Promise((
|
|
407
|
+
await new Promise((resolve5) => setTimeout(resolve5, 1e3));
|
|
408
408
|
}
|
|
409
409
|
logger_default.info(`All ${namespace2} deployments are ready`);
|
|
410
410
|
}
|
|
@@ -419,27 +419,56 @@ var parseTimeout = (value, previous) => {
|
|
|
419
419
|
const parsedValue = parseInt(value, 10);
|
|
420
420
|
const floatValue = parseFloat(value);
|
|
421
421
|
if (isNaN(parsedValue)) {
|
|
422
|
-
throw new
|
|
422
|
+
throw new Error("Not a number.");
|
|
423
423
|
} else if (parsedValue !== floatValue) {
|
|
424
|
-
throw new
|
|
424
|
+
throw new Error("Value must be an integer.");
|
|
425
425
|
} else if (parsedValue < 1 || parsedValue > 30) {
|
|
426
|
-
throw new
|
|
426
|
+
throw new Error("Number must be between 1 and 30.");
|
|
427
427
|
}
|
|
428
428
|
return parsedValue;
|
|
429
429
|
};
|
|
430
|
+
function dedent(file) {
|
|
431
|
+
const lines = file.split("\n");
|
|
432
|
+
if (lines[0].trim() === "") {
|
|
433
|
+
lines.shift();
|
|
434
|
+
file = lines.join("\n");
|
|
435
|
+
}
|
|
436
|
+
const match = file.match(/^[ \t]*(?=\S)/gm);
|
|
437
|
+
const indent = match && Math.min(...match.map((el) => el.length));
|
|
438
|
+
if (indent && indent > 0) {
|
|
439
|
+
const re = new RegExp(`^[ \\t]{${indent}}`, "gm");
|
|
440
|
+
return file.replace(re, "");
|
|
441
|
+
}
|
|
442
|
+
return file;
|
|
443
|
+
}
|
|
444
|
+
function replaceString(str, stringA, stringB) {
|
|
445
|
+
const escapedStringA = stringA.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
446
|
+
const regExp = new RegExp(escapedStringA, "g");
|
|
447
|
+
return str.replace(regExp, stringB);
|
|
448
|
+
}
|
|
430
449
|
|
|
431
450
|
// src/lib/assets/pods.ts
|
|
432
451
|
function namespace(namespaceLabels) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
452
|
+
if (namespaceLabels) {
|
|
453
|
+
return {
|
|
454
|
+
apiVersion: "v1",
|
|
455
|
+
kind: "Namespace",
|
|
456
|
+
metadata: {
|
|
457
|
+
name: "pepr-system",
|
|
458
|
+
labels: namespaceLabels ?? {}
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
} else {
|
|
462
|
+
return {
|
|
463
|
+
apiVersion: "v1",
|
|
464
|
+
kind: "Namespace",
|
|
465
|
+
metadata: {
|
|
466
|
+
name: "pepr-system"
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
441
470
|
}
|
|
442
|
-
function watcher(assets, hash) {
|
|
471
|
+
function watcher(assets, hash, buildTimestamp) {
|
|
443
472
|
const { name: name2, image, capabilities, config } = assets;
|
|
444
473
|
let hasSchedule = false;
|
|
445
474
|
const app = `${name2}-watcher`;
|
|
@@ -483,7 +512,7 @@ function watcher(assets, hash) {
|
|
|
483
512
|
template: {
|
|
484
513
|
metadata: {
|
|
485
514
|
annotations: {
|
|
486
|
-
buildTimestamp: `${
|
|
515
|
+
buildTimestamp: `${buildTimestamp}`
|
|
487
516
|
},
|
|
488
517
|
labels: {
|
|
489
518
|
app,
|
|
@@ -576,7 +605,7 @@ function watcher(assets, hash) {
|
|
|
576
605
|
}
|
|
577
606
|
};
|
|
578
607
|
}
|
|
579
|
-
function deployment(assets, hash) {
|
|
608
|
+
function deployment(assets, hash, buildTimestamp) {
|
|
580
609
|
const { name: name2, image, config } = assets;
|
|
581
610
|
const app = name2;
|
|
582
611
|
return {
|
|
@@ -605,7 +634,7 @@ function deployment(assets, hash) {
|
|
|
605
634
|
template: {
|
|
606
635
|
metadata: {
|
|
607
636
|
annotations: {
|
|
608
|
-
buildTimestamp: `${
|
|
637
|
+
buildTimestamp: `${buildTimestamp}`
|
|
609
638
|
},
|
|
610
639
|
labels: {
|
|
611
640
|
app,
|
|
@@ -1058,11 +1087,11 @@ async function setupController(assets, code, hash, force) {
|
|
|
1058
1087
|
const apiToken = apiTokenSecret(name2, assets.apiToken);
|
|
1059
1088
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(apiToken, { force });
|
|
1060
1089
|
logger_default.info("Applying deployment");
|
|
1061
|
-
const dep = deployment(assets, hash);
|
|
1090
|
+
const dep = deployment(assets, hash, assets.buildTimestamp);
|
|
1062
1091
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(dep, { force });
|
|
1063
1092
|
}
|
|
1064
1093
|
async function setupWatcher(assets, hash, force) {
|
|
1065
|
-
const watchDeployment = watcher(assets, hash);
|
|
1094
|
+
const watchDeployment = watcher(assets, hash, assets.buildTimestamp);
|
|
1066
1095
|
if (watchDeployment) {
|
|
1067
1096
|
logger_default.info("Applying watcher deployment");
|
|
1068
1097
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(watchDeployment, { force });
|
|
@@ -1075,7 +1104,7 @@ async function setupWatcher(assets, hash, force) {
|
|
|
1075
1104
|
// src/lib/assets/loader.ts
|
|
1076
1105
|
var import_child_process = require("child_process");
|
|
1077
1106
|
function loadCapabilities(path) {
|
|
1078
|
-
return new Promise((
|
|
1107
|
+
return new Promise((resolve5, reject) => {
|
|
1079
1108
|
const program2 = (0, import_child_process.fork)(path, {
|
|
1080
1109
|
env: {
|
|
1081
1110
|
...process.env,
|
|
@@ -1088,7 +1117,7 @@ function loadCapabilities(path) {
|
|
|
1088
1117
|
for (const capability of capabilities) {
|
|
1089
1118
|
console.info(`Registered Pepr Capability "${capability.name}"`);
|
|
1090
1119
|
}
|
|
1091
|
-
|
|
1120
|
+
resolve5(capabilities);
|
|
1092
1121
|
});
|
|
1093
1122
|
program2.on("error", (error) => {
|
|
1094
1123
|
reject(error);
|
|
@@ -1100,6 +1129,116 @@ function loadCapabilities(path) {
|
|
|
1100
1129
|
var import_client_node = require("@kubernetes/client-node");
|
|
1101
1130
|
var import_crypto2 = __toESM(require("crypto"));
|
|
1102
1131
|
var import_fs4 = require("fs");
|
|
1132
|
+
async function overridesFile({ hash, name: name2, image, config, apiToken }, path) {
|
|
1133
|
+
const overrides = {
|
|
1134
|
+
secrets: {
|
|
1135
|
+
apiToken: Buffer.from(apiToken).toString("base64")
|
|
1136
|
+
},
|
|
1137
|
+
hash,
|
|
1138
|
+
namespace: {
|
|
1139
|
+
annotations: {},
|
|
1140
|
+
labels: {
|
|
1141
|
+
"pepr.dev": ""
|
|
1142
|
+
}
|
|
1143
|
+
},
|
|
1144
|
+
uuid: name2,
|
|
1145
|
+
admission: {
|
|
1146
|
+
failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
|
|
1147
|
+
webhookTimeout: config.webhookTimeout,
|
|
1148
|
+
env: [
|
|
1149
|
+
{ name: "PEPR_WATCH_MODE", value: "false" },
|
|
1150
|
+
{ name: "PEPR_PRETTY_LOG", value: "false" },
|
|
1151
|
+
{ name: "LOG_LEVEL", value: "debug" },
|
|
1152
|
+
process.env.PEPR_MODE === "dev" && { name: "MY_CUSTOM_VAR", value: "example-value" },
|
|
1153
|
+
process.env.PEPR_MODE === "dev" && { name: "ZARF_VAR", value: "###ZARF_VAR_THING###" }
|
|
1154
|
+
],
|
|
1155
|
+
image,
|
|
1156
|
+
annotations: {
|
|
1157
|
+
"pepr.dev/description": `${config.description}` || ""
|
|
1158
|
+
},
|
|
1159
|
+
labels: {
|
|
1160
|
+
app: name2,
|
|
1161
|
+
"pepr.dev/controller": "admission",
|
|
1162
|
+
"pepr.dev/uuid": config.uuid
|
|
1163
|
+
},
|
|
1164
|
+
securityContext: {
|
|
1165
|
+
runAsUser: 65532,
|
|
1166
|
+
runAsGroup: 65532,
|
|
1167
|
+
runAsNonRoot: true,
|
|
1168
|
+
fsGroup: 65532
|
|
1169
|
+
},
|
|
1170
|
+
resources: {
|
|
1171
|
+
requests: {
|
|
1172
|
+
memory: "64Mi",
|
|
1173
|
+
cpu: "100m"
|
|
1174
|
+
},
|
|
1175
|
+
limits: {
|
|
1176
|
+
memory: "256Mi",
|
|
1177
|
+
cpu: "500m"
|
|
1178
|
+
}
|
|
1179
|
+
},
|
|
1180
|
+
containerSecurityContext: {
|
|
1181
|
+
runAsUser: 65532,
|
|
1182
|
+
runAsGroup: 65532,
|
|
1183
|
+
runAsNonRoot: true,
|
|
1184
|
+
allowPrivilegeEscalation: false,
|
|
1185
|
+
capabilities: {
|
|
1186
|
+
drop: ["ALL"]
|
|
1187
|
+
}
|
|
1188
|
+
},
|
|
1189
|
+
nodeSelector: {},
|
|
1190
|
+
tolerations: [],
|
|
1191
|
+
affinity: {}
|
|
1192
|
+
},
|
|
1193
|
+
watcher: {
|
|
1194
|
+
env: [
|
|
1195
|
+
{ name: "PEPR_WATCH_MODE", value: "true" },
|
|
1196
|
+
{ name: "PEPR_PRETTY_LOG", value: "false" },
|
|
1197
|
+
{ name: "LOG_LEVEL", value: "debug" },
|
|
1198
|
+
process.env.PEPR_MODE === "dev" && { name: "MY_CUSTOM_VAR", value: "example-value" },
|
|
1199
|
+
process.env.PEPR_MODE === "dev" && { name: "ZARF_VAR", value: "###ZARF_VAR_THING###" }
|
|
1200
|
+
],
|
|
1201
|
+
image,
|
|
1202
|
+
annotations: {
|
|
1203
|
+
"pepr.dev/description": `${config.description}` || ""
|
|
1204
|
+
},
|
|
1205
|
+
labels: {
|
|
1206
|
+
app: `${name2}-watcher`,
|
|
1207
|
+
"pepr.dev/controller": "watcher",
|
|
1208
|
+
"pepr.dev/uuid": config.uuid
|
|
1209
|
+
},
|
|
1210
|
+
securityContext: {
|
|
1211
|
+
runAsUser: 65532,
|
|
1212
|
+
runAsGroup: 65532,
|
|
1213
|
+
runAsNonRoot: true,
|
|
1214
|
+
fsGroup: 65532
|
|
1215
|
+
},
|
|
1216
|
+
resources: {
|
|
1217
|
+
requests: {
|
|
1218
|
+
memory: "64Mi",
|
|
1219
|
+
cpu: "100m"
|
|
1220
|
+
},
|
|
1221
|
+
limits: {
|
|
1222
|
+
memory: "256Mi",
|
|
1223
|
+
cpu: "500m"
|
|
1224
|
+
}
|
|
1225
|
+
},
|
|
1226
|
+
containerSecurityContext: {
|
|
1227
|
+
runAsUser: 65532,
|
|
1228
|
+
runAsGroup: 65532,
|
|
1229
|
+
runAsNonRoot: true,
|
|
1230
|
+
allowPrivilegeEscalation: false,
|
|
1231
|
+
capabilities: {
|
|
1232
|
+
drop: ["ALL"]
|
|
1233
|
+
}
|
|
1234
|
+
},
|
|
1235
|
+
nodeSelector: {},
|
|
1236
|
+
tolerations: [],
|
|
1237
|
+
affinity: {}
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
await import_fs4.promises.writeFile(path, (0, import_client_node.dumpYaml)(overrides, { noRefs: true, forceQuotes: true }));
|
|
1241
|
+
}
|
|
1103
1242
|
function zarfYaml({ name: name2, image, config }, path) {
|
|
1104
1243
|
const zarfCfg = {
|
|
1105
1244
|
kind: "ZarfPackageConfig",
|
|
@@ -1129,10 +1268,10 @@ function zarfYaml({ name: name2, image, config }, path) {
|
|
|
1129
1268
|
async function allYaml(assets, rbacMode) {
|
|
1130
1269
|
const { name: name2, tls, apiToken, path } = assets;
|
|
1131
1270
|
const code = await import_fs4.promises.readFile(path);
|
|
1132
|
-
|
|
1271
|
+
assets.hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
1133
1272
|
const mutateWebhook = await webhookConfig(assets, "mutate", assets.config.webhookTimeout);
|
|
1134
1273
|
const validateWebhook = await webhookConfig(assets, "validate", assets.config.webhookTimeout);
|
|
1135
|
-
const watchDeployment = watcher(assets, hash);
|
|
1274
|
+
const watchDeployment = watcher(assets, assets.hash, assets.buildTimestamp);
|
|
1136
1275
|
const resources = [
|
|
1137
1276
|
namespace(assets.config.customLabels?.namespace),
|
|
1138
1277
|
clusterRole(name2, assets.capabilities, rbacMode),
|
|
@@ -1140,10 +1279,10 @@ async function allYaml(assets, rbacMode) {
|
|
|
1140
1279
|
serviceAccount(name2),
|
|
1141
1280
|
apiTokenSecret(name2, apiToken),
|
|
1142
1281
|
tlsSecret(name2, tls),
|
|
1143
|
-
deployment(assets, hash),
|
|
1282
|
+
deployment(assets, assets.hash, assets.buildTimestamp),
|
|
1144
1283
|
service(name2),
|
|
1145
1284
|
watcherService(name2),
|
|
1146
|
-
moduleSecret(name2, code, hash),
|
|
1285
|
+
moduleSecret(name2, code, assets.hash),
|
|
1147
1286
|
storeRole(name2),
|
|
1148
1287
|
storeRoleBinding(name2)
|
|
1149
1288
|
];
|
|
@@ -1160,14 +1299,215 @@ async function allYaml(assets, rbacMode) {
|
|
|
1160
1299
|
}
|
|
1161
1300
|
|
|
1162
1301
|
// src/lib/assets/index.ts
|
|
1302
|
+
var import_path = require("path");
|
|
1303
|
+
|
|
1304
|
+
// src/lib/assets/helm.ts
|
|
1305
|
+
function nsTemplate() {
|
|
1306
|
+
return `
|
|
1307
|
+
apiVersion: v1
|
|
1308
|
+
kind: Namespace
|
|
1309
|
+
metadata:
|
|
1310
|
+
name: pepr-system
|
|
1311
|
+
{{- if .Values.namespace.annotations }}
|
|
1312
|
+
annotations:
|
|
1313
|
+
{{- toYaml .Values.namespace.annotations | nindent 6 }}
|
|
1314
|
+
{{- end }}
|
|
1315
|
+
{{- if .Values.namespace.labels }}
|
|
1316
|
+
labels:
|
|
1317
|
+
{{- toYaml .Values.namespace.labels | nindent 6 }}
|
|
1318
|
+
{{- end }}
|
|
1319
|
+
`;
|
|
1320
|
+
}
|
|
1321
|
+
function chartYaml(name2, description) {
|
|
1322
|
+
return `
|
|
1323
|
+
apiVersion: v2
|
|
1324
|
+
name: ${name2}
|
|
1325
|
+
description: ${description || ""}
|
|
1326
|
+
|
|
1327
|
+
# A chart can be either an 'application' or a 'library' chart.
|
|
1328
|
+
#
|
|
1329
|
+
# Application charts are a collection of templates that can be packaged into versioned archives
|
|
1330
|
+
# to be deployed.
|
|
1331
|
+
#
|
|
1332
|
+
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
|
1333
|
+
# a dependency of application charts to inject those utilities and functions into the rendering
|
|
1334
|
+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
|
1335
|
+
type: application
|
|
1336
|
+
|
|
1337
|
+
# This is the chart version. This version number should be incremented each time you make changes
|
|
1338
|
+
# to the chart and its templates, including the app version.
|
|
1339
|
+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
|
1340
|
+
version: 0.1.0
|
|
1341
|
+
|
|
1342
|
+
# This is the version number of the application being deployed. This version number should be
|
|
1343
|
+
# incremented each time you make changes to the application. Versions are not expected to
|
|
1344
|
+
# follow Semantic Versioning. They should reflect the version the application is using.
|
|
1345
|
+
# It is recommended to use it with quotes.
|
|
1346
|
+
appVersion: "1.16.0"
|
|
1347
|
+
`;
|
|
1348
|
+
}
|
|
1349
|
+
function watcherDeployTemplate(buildTimestamp) {
|
|
1350
|
+
return `
|
|
1351
|
+
apiVersion: apps/v1
|
|
1352
|
+
kind: Deployment
|
|
1353
|
+
metadata:
|
|
1354
|
+
name: {{ .Values.uuid }}-watcher
|
|
1355
|
+
namespace: pepr-system
|
|
1356
|
+
annotations:
|
|
1357
|
+
{{- toYaml .Values.watcher.annotations | nindent 4 }}
|
|
1358
|
+
labels:
|
|
1359
|
+
{{- toYaml .Values.watcher.labels | nindent 4 }}
|
|
1360
|
+
spec:
|
|
1361
|
+
replicas: 1
|
|
1362
|
+
strategy:
|
|
1363
|
+
type: Recreate
|
|
1364
|
+
selector:
|
|
1365
|
+
matchLabels:
|
|
1366
|
+
app: {{ .Values.uuid }}-watcher
|
|
1367
|
+
pepr.dev/controller: watcher
|
|
1368
|
+
template:
|
|
1369
|
+
metadata:
|
|
1370
|
+
annotations:
|
|
1371
|
+
buildTimestamp: "${buildTimestamp}"
|
|
1372
|
+
labels:
|
|
1373
|
+
app: {{ .Values.uuid }}-watcher
|
|
1374
|
+
pepr.dev/controller: watcher
|
|
1375
|
+
spec:
|
|
1376
|
+
serviceAccountName: {{ .Values.uuid }}
|
|
1377
|
+
securityContext:
|
|
1378
|
+
{{- toYaml .Values.admission.securityContext | nindent 8 }}
|
|
1379
|
+
containers:
|
|
1380
|
+
- name: watcher
|
|
1381
|
+
image: {{ .Values.watcher.image }}
|
|
1382
|
+
imagePullPolicy: IfNotPresent
|
|
1383
|
+
command:
|
|
1384
|
+
- node
|
|
1385
|
+
- /app/node_modules/pepr/dist/controller.js
|
|
1386
|
+
- {{ .Values.hash }}
|
|
1387
|
+
readinessProbe:
|
|
1388
|
+
httpGet:
|
|
1389
|
+
path: /healthz
|
|
1390
|
+
port: 3000
|
|
1391
|
+
scheme: HTTPS
|
|
1392
|
+
livenessProbe:
|
|
1393
|
+
httpGet:
|
|
1394
|
+
path: /healthz
|
|
1395
|
+
port: 3000
|
|
1396
|
+
scheme: HTTPS
|
|
1397
|
+
ports:
|
|
1398
|
+
- containerPort: 3000
|
|
1399
|
+
resources:
|
|
1400
|
+
{{- toYaml .Values.watcher.resources | nindent 12 }}
|
|
1401
|
+
env:
|
|
1402
|
+
{{- toYaml .Values.watcher.env | nindent 12 }}
|
|
1403
|
+
securityContext:
|
|
1404
|
+
{{- toYaml .Values.watcher.containerSecurityContext | nindent 12 }}
|
|
1405
|
+
volumeMounts:
|
|
1406
|
+
- name: tls-certs
|
|
1407
|
+
mountPath: /etc/certs
|
|
1408
|
+
readOnly: true
|
|
1409
|
+
- name: module
|
|
1410
|
+
mountPath: /app/load
|
|
1411
|
+
readOnly: true
|
|
1412
|
+
volumes:
|
|
1413
|
+
- name: tls-certs
|
|
1414
|
+
secret:
|
|
1415
|
+
secretName: {{ .Values.uuid }}-tls
|
|
1416
|
+
- name: module
|
|
1417
|
+
secret:
|
|
1418
|
+
secretName: {{ .Values.uuid }}-module
|
|
1419
|
+
`;
|
|
1420
|
+
}
|
|
1421
|
+
function admissionDeployTemplate(buildTimestamp) {
|
|
1422
|
+
return `
|
|
1423
|
+
apiVersion: apps/v1
|
|
1424
|
+
kind: Deployment
|
|
1425
|
+
metadata:
|
|
1426
|
+
name: {{ .Values.uuid }}
|
|
1427
|
+
namespace: pepr-system
|
|
1428
|
+
annotations:
|
|
1429
|
+
{{- toYaml .Values.admission.annotations | nindent 4 }}
|
|
1430
|
+
labels:
|
|
1431
|
+
{{- toYaml .Values.admission.labels | nindent 4 }}
|
|
1432
|
+
spec:
|
|
1433
|
+
replicas: 2
|
|
1434
|
+
selector:
|
|
1435
|
+
matchLabels:
|
|
1436
|
+
app: {{ .Values.uuid }}
|
|
1437
|
+
pepr.dev/controller: admission
|
|
1438
|
+
template:
|
|
1439
|
+
metadata:
|
|
1440
|
+
annotations:
|
|
1441
|
+
buildTimestamp: "${buildTimestamp}"
|
|
1442
|
+
labels:
|
|
1443
|
+
app: {{ .Values.uuid }}
|
|
1444
|
+
pepr.dev/controller: admission
|
|
1445
|
+
spec:
|
|
1446
|
+
priorityClassName: system-node-critical
|
|
1447
|
+
serviceAccountName: {{ .Values.uuid }}
|
|
1448
|
+
securityContext:
|
|
1449
|
+
{{- toYaml .Values.admission.securityContext | nindent 8 }}
|
|
1450
|
+
containers:
|
|
1451
|
+
- name: server
|
|
1452
|
+
image: {{ .Values.admission.image }}
|
|
1453
|
+
imagePullPolicy: IfNotPresent
|
|
1454
|
+
command:
|
|
1455
|
+
- node
|
|
1456
|
+
- /app/node_modules/pepr/dist/controller.js
|
|
1457
|
+
- {{ .Values.hash }}
|
|
1458
|
+
readinessProbe:
|
|
1459
|
+
httpGet:
|
|
1460
|
+
path: /healthz
|
|
1461
|
+
port: 3000
|
|
1462
|
+
scheme: HTTPS
|
|
1463
|
+
livenessProbe:
|
|
1464
|
+
httpGet:
|
|
1465
|
+
path: /healthz
|
|
1466
|
+
port: 3000
|
|
1467
|
+
scheme: HTTPS
|
|
1468
|
+
ports:
|
|
1469
|
+
- containerPort: 3000
|
|
1470
|
+
resources:
|
|
1471
|
+
{{- toYaml .Values.admission.resources | nindent 12 }}
|
|
1472
|
+
env:
|
|
1473
|
+
{{- toYaml .Values.admission.env | nindent 12 }}
|
|
1474
|
+
securityContext:
|
|
1475
|
+
{{- toYaml .Values.admission.containerSecurityContext | nindent 12 }}
|
|
1476
|
+
volumeMounts:
|
|
1477
|
+
- name: tls-certs
|
|
1478
|
+
mountPath: /etc/certs
|
|
1479
|
+
readOnly: true
|
|
1480
|
+
- name: api-token
|
|
1481
|
+
mountPath: /app/api-token
|
|
1482
|
+
readOnly: true
|
|
1483
|
+
- name: module
|
|
1484
|
+
mountPath: /app/load
|
|
1485
|
+
readOnly: true
|
|
1486
|
+
volumes:
|
|
1487
|
+
- name: tls-certs
|
|
1488
|
+
secret:
|
|
1489
|
+
secretName: {{ .Values.uuid }}-tls
|
|
1490
|
+
- name: api-token
|
|
1491
|
+
secret:
|
|
1492
|
+
secretName: {{ .Values.uuid }}-api-token
|
|
1493
|
+
- name: module
|
|
1494
|
+
secret:
|
|
1495
|
+
secretName: {{ .Values.uuid }}-module
|
|
1496
|
+
`;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// src/lib/assets/index.ts
|
|
1500
|
+
var import_fs5 = require("fs");
|
|
1163
1501
|
var Assets = class {
|
|
1164
1502
|
constructor(config, path, host) {
|
|
1165
1503
|
this.config = config;
|
|
1166
1504
|
this.path = path;
|
|
1167
1505
|
this.host = host;
|
|
1168
1506
|
this.name = `pepr-${config.uuid}`;
|
|
1507
|
+
this.buildTimestamp = `${Date.now()}`;
|
|
1169
1508
|
this.alwaysIgnore = config.alwaysIgnore;
|
|
1170
1509
|
this.image = `ghcr.io/defenseunicorns/pepr/controller:v${config.peprVersion}`;
|
|
1510
|
+
this.hash = "";
|
|
1171
1511
|
this.tls = genTLS(this.host || `${this.name}.pepr-system.svc`);
|
|
1172
1512
|
this.apiToken = import_crypto3.default.randomBytes(32).toString("hex");
|
|
1173
1513
|
}
|
|
@@ -1177,6 +1517,11 @@ var Assets = class {
|
|
|
1177
1517
|
alwaysIgnore;
|
|
1178
1518
|
capabilities;
|
|
1179
1519
|
image;
|
|
1520
|
+
buildTimestamp;
|
|
1521
|
+
hash;
|
|
1522
|
+
setHash = (hash) => {
|
|
1523
|
+
this.hash = hash;
|
|
1524
|
+
};
|
|
1180
1525
|
deploy = async (force, webhookTimeout) => {
|
|
1181
1526
|
this.capabilities = await loadCapabilities(this.path);
|
|
1182
1527
|
await deploy(this, force, webhookTimeout);
|
|
@@ -1189,10 +1534,91 @@ var Assets = class {
|
|
|
1189
1534
|
}
|
|
1190
1535
|
return allYaml(this, rbacMode);
|
|
1191
1536
|
};
|
|
1537
|
+
generateHelmChart = async (basePath) => {
|
|
1538
|
+
const CHART_DIR = `${basePath}/${this.config.uuid}-chart`;
|
|
1539
|
+
const CHAR_TEMPLATES_DIR = `${CHART_DIR}/templates`;
|
|
1540
|
+
const valuesPath = (0, import_path.resolve)(CHART_DIR, `values.yaml`);
|
|
1541
|
+
const chartPath = (0, import_path.resolve)(CHART_DIR, `Chart.yaml`);
|
|
1542
|
+
const nsPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `namespace.yaml`);
|
|
1543
|
+
const watcherSVCPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `watcher-service.yaml`);
|
|
1544
|
+
const admissionSVCPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `admission-service.yaml`);
|
|
1545
|
+
const mutationWebhookPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `mutation-webhook.yaml`);
|
|
1546
|
+
const validationWebhookPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `validation-webhook.yaml`);
|
|
1547
|
+
const admissionDeployPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `admission-deployment.yaml`);
|
|
1548
|
+
const watcherDeployPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `watcher-deployment.yaml`);
|
|
1549
|
+
const tlsSecretPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `tls-secret.yaml`);
|
|
1550
|
+
const apiTokenSecretPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `api-token-secret.yaml`);
|
|
1551
|
+
const moduleSecretPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `module-secret.yaml`);
|
|
1552
|
+
const storeRolePath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `store-role.yaml`);
|
|
1553
|
+
const storeRoleBindingPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `store-role-binding.yaml`);
|
|
1554
|
+
const clusterRolePath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `cluster-role.yaml`);
|
|
1555
|
+
const clusterRoleBindingPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `cluster-role-binding.yaml`);
|
|
1556
|
+
const serviceAccountPath = (0, import_path.resolve)(CHAR_TEMPLATES_DIR, `service-account.yaml`);
|
|
1557
|
+
try {
|
|
1558
|
+
await createDirectoryIfNotExists(CHART_DIR);
|
|
1559
|
+
await createDirectoryIfNotExists(`${CHART_DIR}/charts`);
|
|
1560
|
+
await createDirectoryIfNotExists(`${CHAR_TEMPLATES_DIR}`);
|
|
1561
|
+
await overridesFile(this, valuesPath);
|
|
1562
|
+
await import_fs5.promises.writeFile(chartPath, dedent(chartYaml(this.config.uuid, this.config.description || "")));
|
|
1563
|
+
await import_fs5.promises.writeFile(nsPath, dedent(nsTemplate()));
|
|
1564
|
+
const code = await import_fs5.promises.readFile(this.path);
|
|
1565
|
+
await import_fs5.promises.writeFile(watcherSVCPath, (0, import_client_node2.dumpYaml)(watcherService(this.name), { noRefs: true }));
|
|
1566
|
+
await import_fs5.promises.writeFile(admissionSVCPath, (0, import_client_node2.dumpYaml)(service(this.name), { noRefs: true }));
|
|
1567
|
+
await import_fs5.promises.writeFile(tlsSecretPath, (0, import_client_node2.dumpYaml)(tlsSecret(this.name, this.tls), { noRefs: true }));
|
|
1568
|
+
await import_fs5.promises.writeFile(apiTokenSecretPath, (0, import_client_node2.dumpYaml)(apiTokenSecret(this.name, this.apiToken), { noRefs: true }));
|
|
1569
|
+
await import_fs5.promises.writeFile(moduleSecretPath, (0, import_client_node2.dumpYaml)(moduleSecret(this.name, code, this.hash), { noRefs: true }));
|
|
1570
|
+
await import_fs5.promises.writeFile(storeRolePath, (0, import_client_node2.dumpYaml)(storeRole(this.name), { noRefs: true }));
|
|
1571
|
+
await import_fs5.promises.writeFile(storeRoleBindingPath, (0, import_client_node2.dumpYaml)(storeRoleBinding(this.name), { noRefs: true }));
|
|
1572
|
+
await import_fs5.promises.writeFile(
|
|
1573
|
+
clusterRolePath,
|
|
1574
|
+
(0, import_client_node2.dumpYaml)(clusterRole(this.name, this.capabilities, "rbac"), { noRefs: true })
|
|
1575
|
+
);
|
|
1576
|
+
await import_fs5.promises.writeFile(clusterRoleBindingPath, (0, import_client_node2.dumpYaml)(clusterRoleBinding(this.name), { noRefs: true }));
|
|
1577
|
+
await import_fs5.promises.writeFile(serviceAccountPath, (0, import_client_node2.dumpYaml)(serviceAccount(this.name), { noRefs: true }));
|
|
1578
|
+
const mutateWebhook = await webhookConfig(this, "mutate", this.config.webhookTimeout);
|
|
1579
|
+
const validateWebhook = await webhookConfig(this, "validate", this.config.webhookTimeout);
|
|
1580
|
+
const watchDeployment = watcher(this, this.hash, this.buildTimestamp);
|
|
1581
|
+
if (validateWebhook || mutateWebhook) {
|
|
1582
|
+
await import_fs5.promises.writeFile(admissionDeployPath, dedent(admissionDeployTemplate(this.buildTimestamp)));
|
|
1583
|
+
}
|
|
1584
|
+
if (mutateWebhook) {
|
|
1585
|
+
const yamlMutateWebhook = (0, import_client_node2.dumpYaml)(mutateWebhook, { noRefs: true });
|
|
1586
|
+
const mutateWebhookTemplate = replaceString(
|
|
1587
|
+
replaceString(
|
|
1588
|
+
replaceString(yamlMutateWebhook, this.name, "{{ .Values.uuid }}"),
|
|
1589
|
+
this.config.onError === "reject" ? "Fail" : "Ignore",
|
|
1590
|
+
"{{ .Values.admission.failurePolicy }}"
|
|
1591
|
+
),
|
|
1592
|
+
`${this.config.webhookTimeout}` || "10",
|
|
1593
|
+
"{{ .Values.admission.webhookTimeout }}"
|
|
1594
|
+
);
|
|
1595
|
+
await import_fs5.promises.writeFile(mutationWebhookPath, mutateWebhookTemplate);
|
|
1596
|
+
}
|
|
1597
|
+
if (validateWebhook) {
|
|
1598
|
+
const yamlValidateWebhook = (0, import_client_node2.dumpYaml)(validateWebhook, { noRefs: true });
|
|
1599
|
+
const validateWebhookTemplate = replaceString(
|
|
1600
|
+
replaceString(
|
|
1601
|
+
replaceString(yamlValidateWebhook, this.name, "{{ .Values.uuid }}"),
|
|
1602
|
+
this.config.onError === "reject" ? "Fail" : "Ignore",
|
|
1603
|
+
"{{ .Values.admission.failurePolicy }}"
|
|
1604
|
+
),
|
|
1605
|
+
`${this.config.webhookTimeout}` || "10",
|
|
1606
|
+
"{{ .Values.admission.webhookTimeout }}"
|
|
1607
|
+
);
|
|
1608
|
+
await import_fs5.promises.writeFile(validationWebhookPath, validateWebhookTemplate);
|
|
1609
|
+
}
|
|
1610
|
+
if (watchDeployment) {
|
|
1611
|
+
await import_fs5.promises.writeFile(watcherDeployPath, dedent(watcherDeployTemplate(this.buildTimestamp)));
|
|
1612
|
+
}
|
|
1613
|
+
} catch (err) {
|
|
1614
|
+
console.error(`Error generating helm chart: ${err.message}`);
|
|
1615
|
+
process.exit(1);
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1192
1618
|
};
|
|
1193
1619
|
|
|
1194
1620
|
// src/cli/init/templates.ts
|
|
1195
|
-
var
|
|
1621
|
+
var import_client_node3 = require("@kubernetes/client-node");
|
|
1196
1622
|
var import_util = require("util");
|
|
1197
1623
|
var import_uuid = require("uuid");
|
|
1198
1624
|
|
|
@@ -1398,7 +1824,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
1398
1824
|
var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
|
|
1399
1825
|
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';
|
|
1400
1826
|
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://api.chucknorris.io/jokes/random?category=dev");\n * const joke = await fetch("https://api.chucknorris.io/jokes/random?category=dev") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://api.chucknorris.io/jokes/random?category=dev")\n * ```\n */\ninterface TheChuckNorrisJoke {\n icon_url: string;\n id: string;\n url: string;\n value: string;\n}\n\nWhen(a.ConfigMap)\n .IsCreated()\n .WithLabel("chuck-norris")\n .Mutate(async change => {\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(\n "https://api.chucknorris.io/jokes/random?category=dev",\n );\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n // Add the Chuck Norris joke to the configmap\n change.Raw.data["chuck-says"] = response.data.value;\n return;\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';
|
|
1401
|
-
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" }, version: "0.
|
|
1827
|
+
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" }, version: "0.28.0", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@types/ramda": "0.29.11", express: "4.18.3", "fast-json-patch": "3.1.1", "kubernetes-fluent-client": "2.2.2", pino: "8.19.0", "pino-pretty": "10.3.1", "prom-client": "15.1.0", ramda: "0.29.1" }, devDependencies: { "@commitlint/cli": "19.0.3", "@commitlint/config-conventional": "19.0.3", "@jest/globals": "29.7.0", "@types/eslint": "8.56.5", "@types/express": "4.17.21", "@types/node": "18.x.x", "@types/node-forge": "1.3.11", "@types/prompts": "2.4.9", "@types/uuid": "9.0.8", jest: "29.7.0", nock: "13.5.4", "ts-jest": "29.1.2" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.15.0", "@typescript-eslint/parser": "6.15.0", commander: "11.1.0", esbuild: "0.19.10", eslint: "8.56.0", "node-forge": "1.3.1", prettier: "3.1.1", prompts: "2.4.2", typescript: "5.3.3", uuid: "9.0.1" } };
|
|
1402
1828
|
|
|
1403
1829
|
// src/templates/pepr.code-snippets.json
|
|
1404
1830
|
var pepr_code_snippets_default = {
|
|
@@ -1457,7 +1883,7 @@ var tsconfig_module_default = {
|
|
|
1457
1883
|
};
|
|
1458
1884
|
|
|
1459
1885
|
// src/cli/init/utils.ts
|
|
1460
|
-
var
|
|
1886
|
+
var import_fs6 = require("fs");
|
|
1461
1887
|
function sanitizeName(name2) {
|
|
1462
1888
|
let sanitized = name2.toLowerCase().replace(/[^a-z0-9-]+/gi, "-");
|
|
1463
1889
|
sanitized = sanitized.replace(/^-+|-+$/g, "");
|
|
@@ -1466,7 +1892,7 @@ function sanitizeName(name2) {
|
|
|
1466
1892
|
}
|
|
1467
1893
|
async function createDir(dir) {
|
|
1468
1894
|
try {
|
|
1469
|
-
await
|
|
1895
|
+
await import_fs6.promises.mkdir(dir);
|
|
1470
1896
|
} catch (err) {
|
|
1471
1897
|
if (err && err.code === "EEXIST") {
|
|
1472
1898
|
throw new Error(`Directory ${dir} already exists`);
|
|
@@ -1479,7 +1905,7 @@ function write(path, data) {
|
|
|
1479
1905
|
if (typeof data !== "string") {
|
|
1480
1906
|
data = JSON.stringify(data, null, 2);
|
|
1481
1907
|
}
|
|
1482
|
-
return
|
|
1908
|
+
return import_fs6.promises.writeFile(path, data);
|
|
1483
1909
|
}
|
|
1484
1910
|
|
|
1485
1911
|
// src/cli/init/templates.ts
|
|
@@ -1501,16 +1927,16 @@ function genPkgJSON(opts, pgkVerOverride) {
|
|
|
1501
1927
|
node: ">=18.0.0"
|
|
1502
1928
|
},
|
|
1503
1929
|
pepr: {
|
|
1504
|
-
name: opts.name.trim(),
|
|
1505
1930
|
uuid: pgkVerOverride ? "static-test" : uuid,
|
|
1506
1931
|
onError: opts.errorBehavior,
|
|
1507
1932
|
webhookTimeout: 10,
|
|
1508
1933
|
customLabels: {
|
|
1509
|
-
namespace: {
|
|
1934
|
+
namespace: {
|
|
1935
|
+
"pepr.dev": ""
|
|
1936
|
+
}
|
|
1510
1937
|
},
|
|
1511
1938
|
alwaysIgnore: {
|
|
1512
|
-
namespaces: []
|
|
1513
|
-
labels: []
|
|
1939
|
+
namespaces: []
|
|
1514
1940
|
},
|
|
1515
1941
|
includedFiles: [],
|
|
1516
1942
|
env: pgkVerOverride ? testEnv : {}
|
|
@@ -1551,7 +1977,7 @@ var gitignore = {
|
|
|
1551
1977
|
};
|
|
1552
1978
|
var samplesYaml = {
|
|
1553
1979
|
path: "hello-pepr.samples.yaml",
|
|
1554
|
-
data: hello_pepr_samples_default.map((r) => (0,
|
|
1980
|
+
data: hello_pepr_samples_default.map((r) => (0, import_client_node3.dumpYaml)(r, { noRefs: true })).join("---\n")
|
|
1555
1981
|
};
|
|
1556
1982
|
var snippet = {
|
|
1557
1983
|
path: "pepr.code-snippets",
|
|
@@ -1576,7 +2002,7 @@ var eslint = {
|
|
|
1576
2002
|
|
|
1577
2003
|
// src/cli/format.ts
|
|
1578
2004
|
var import_eslint = require("eslint");
|
|
1579
|
-
var
|
|
2005
|
+
var import_fs7 = require("fs");
|
|
1580
2006
|
var import_prettier = require("prettier");
|
|
1581
2007
|
function format_default(program2) {
|
|
1582
2008
|
program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
|
|
@@ -1609,7 +2035,7 @@ async function peprFormat(validateOnly) {
|
|
|
1609
2035
|
await import_eslint.ESLint.outputFixes(results);
|
|
1610
2036
|
}
|
|
1611
2037
|
for (const { filePath } of results) {
|
|
1612
|
-
const content = await
|
|
2038
|
+
const content = await import_fs7.promises.readFile(filePath, "utf8");
|
|
1613
2039
|
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
1614
2040
|
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
1615
2041
|
if (validateOnly) {
|
|
@@ -1618,7 +2044,7 @@ async function peprFormat(validateOnly) {
|
|
|
1618
2044
|
console.error(`File ${filePath} is not formatted correctly`);
|
|
1619
2045
|
}
|
|
1620
2046
|
} else {
|
|
1621
|
-
await
|
|
2047
|
+
await import_fs7.promises.writeFile(filePath, formatted);
|
|
1622
2048
|
}
|
|
1623
2049
|
}
|
|
1624
2050
|
return !hasFailure;
|
|
@@ -1630,7 +2056,7 @@ async function peprFormat(validateOnly) {
|
|
|
1630
2056
|
}
|
|
1631
2057
|
|
|
1632
2058
|
// src/cli/build.ts
|
|
1633
|
-
var
|
|
2059
|
+
var import_commander = require("commander");
|
|
1634
2060
|
var peprTS2 = "pepr.ts";
|
|
1635
2061
|
var outputDir = "dist";
|
|
1636
2062
|
function build_default(program2) {
|
|
@@ -1638,22 +2064,25 @@ function build_default(program2) {
|
|
|
1638
2064
|
"-n, --no-embed",
|
|
1639
2065
|
"Disables embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM."
|
|
1640
2066
|
).option(
|
|
1641
|
-
"-i, --custom-image
|
|
2067
|
+
"-i, --custom-image <custom-image>",
|
|
1642
2068
|
"Custom Image: Use custom image for Admission and Watch Deployments."
|
|
1643
2069
|
).option(
|
|
1644
2070
|
"-r, --registry-info [<registry>/<username>]",
|
|
1645
2071
|
"Registry Info: Image registry and username. Note: You must be signed into the registry"
|
|
1646
|
-
).option("-o, --output-dir
|
|
1647
|
-
"--timeout
|
|
2072
|
+
).option("-o, --output-dir <output directory>", "Define where to place build output").option(
|
|
2073
|
+
"--timeout <timeout>",
|
|
1648
2074
|
"How long the API server should wait for a webhook to respond before treating the call as a failure",
|
|
1649
2075
|
parseTimeout
|
|
2076
|
+
).option(
|
|
2077
|
+
"-v, --version <version>. Example: '0.27.3'",
|
|
2078
|
+
"The version of the Pepr image to use in the deployment manifests."
|
|
1650
2079
|
).addOption(
|
|
1651
|
-
new
|
|
2080
|
+
new import_commander.Option(
|
|
1652
2081
|
"--registry <GitHub|Iron Bank>",
|
|
1653
2082
|
"Container registry: Choose container registry for deployment manifests. Can't be used with --custom-image."
|
|
1654
2083
|
).choices(["GitHub", "Iron Bank"])
|
|
1655
2084
|
).addOption(
|
|
1656
|
-
new
|
|
2085
|
+
new import_commander.Option("--rbac-mode [admin|scoped]", "Rbac Mode: admin, scoped (default: admin)").choices(["admin", "scoped"]).default("admin")
|
|
1657
2086
|
).action(async (opts) => {
|
|
1658
2087
|
if (opts.outputDir) {
|
|
1659
2088
|
outputDir = opts.outputDir;
|
|
@@ -1688,6 +2117,9 @@ function build_default(program2) {
|
|
|
1688
2117
|
console.info(`\u2705 Module built successfully at ${path}`);
|
|
1689
2118
|
return;
|
|
1690
2119
|
}
|
|
2120
|
+
if (opts.version) {
|
|
2121
|
+
cfg.pepr.peprVersion = opts.version;
|
|
2122
|
+
}
|
|
1691
2123
|
const assets = new Assets(
|
|
1692
2124
|
{
|
|
1693
2125
|
...cfg.pepr,
|
|
@@ -1708,12 +2140,13 @@ function build_default(program2) {
|
|
|
1708
2140
|
assets.image = image;
|
|
1709
2141
|
}
|
|
1710
2142
|
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
1711
|
-
const yamlPath = (0,
|
|
2143
|
+
const yamlPath = (0, import_path2.resolve)(outputDir, yamlFile);
|
|
1712
2144
|
const yaml = await assets.allYaml(opts.rbacMode);
|
|
1713
|
-
const zarfPath = (0,
|
|
2145
|
+
const zarfPath = (0, import_path2.resolve)(outputDir, "zarf.yaml");
|
|
1714
2146
|
const zarf = assets.zarfYaml(yamlFile);
|
|
1715
|
-
await
|
|
1716
|
-
await
|
|
2147
|
+
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2148
|
+
await import_fs8.promises.writeFile(zarfPath, zarf);
|
|
2149
|
+
await assets.generateHelmChart(outputDir);
|
|
1717
2150
|
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
1718
2151
|
});
|
|
1719
2152
|
}
|
|
@@ -1721,19 +2154,19 @@ var externalLibs = Object.keys(dependencies);
|
|
|
1721
2154
|
externalLibs.push("pepr");
|
|
1722
2155
|
externalLibs.push("@kubernetes/client-node");
|
|
1723
2156
|
async function loadModule(entryPoint = peprTS2) {
|
|
1724
|
-
const entryPointPath = (0,
|
|
1725
|
-
const modulePath = (0,
|
|
1726
|
-
const cfgPath = (0,
|
|
2157
|
+
const entryPointPath = (0, import_path2.resolve)(".", entryPoint);
|
|
2158
|
+
const modulePath = (0, import_path2.dirname)(entryPointPath);
|
|
2159
|
+
const cfgPath = (0, import_path2.resolve)(modulePath, "package.json");
|
|
1727
2160
|
try {
|
|
1728
|
-
await
|
|
1729
|
-
await
|
|
2161
|
+
await import_fs8.promises.access(cfgPath);
|
|
2162
|
+
await import_fs8.promises.access(entryPointPath);
|
|
1730
2163
|
} catch (e) {
|
|
1731
2164
|
console.error(
|
|
1732
2165
|
`Could not find ${cfgPath} or ${entryPointPath} in the current directory. Please run this command from the root of your module's directory.`
|
|
1733
2166
|
);
|
|
1734
2167
|
process.exit(1);
|
|
1735
2168
|
}
|
|
1736
|
-
const moduleText = await
|
|
2169
|
+
const moduleText = await import_fs8.promises.readFile(cfgPath, { encoding: "utf-8" });
|
|
1737
2170
|
const cfg = JSON.parse(moduleText);
|
|
1738
2171
|
const { uuid } = cfg.pepr;
|
|
1739
2172
|
const name2 = `pepr-${uuid}.js`;
|
|
@@ -1746,7 +2179,7 @@ async function loadModule(entryPoint = peprTS2) {
|
|
|
1746
2179
|
entryPointPath,
|
|
1747
2180
|
modulePath,
|
|
1748
2181
|
name: name2,
|
|
1749
|
-
path: (0,
|
|
2182
|
+
path: (0, import_path2.resolve)(outputDir, name2),
|
|
1750
2183
|
uuid
|
|
1751
2184
|
};
|
|
1752
2185
|
}
|
|
@@ -1797,7 +2230,7 @@ async function buildModule(reloader, entryPoint = peprTS2, embed = true) {
|
|
|
1797
2230
|
}
|
|
1798
2231
|
if (!embed) {
|
|
1799
2232
|
ctxCfg.minify = false;
|
|
1800
|
-
ctxCfg.outfile = (0,
|
|
2233
|
+
ctxCfg.outfile = (0, import_path2.resolve)(outputDir, (0, import_path2.basename)(entryPoint, (0, import_path2.extname)(entryPoint))) + ".js";
|
|
1801
2234
|
ctxCfg.packages = "external";
|
|
1802
2235
|
ctxCfg.treeShaking = false;
|
|
1803
2236
|
}
|
|
@@ -1867,8 +2300,9 @@ function deploy_default(program2) {
|
|
|
1867
2300
|
if (opts.image) {
|
|
1868
2301
|
webhook.image = opts.image;
|
|
1869
2302
|
}
|
|
2303
|
+
const timeout = cfg.pepr.webhookTimeout ? cfg.pepr.webhookTimeout : 10;
|
|
1870
2304
|
try {
|
|
1871
|
-
await webhook.deploy(opts.force);
|
|
2305
|
+
await webhook.deploy(opts.force, timeout);
|
|
1872
2306
|
await namespaceDeploymentsReady();
|
|
1873
2307
|
console.info(`\u2705 Module deployed successfully`);
|
|
1874
2308
|
} catch (e) {
|
|
@@ -1880,7 +2314,7 @@ function deploy_default(program2) {
|
|
|
1880
2314
|
|
|
1881
2315
|
// src/cli/dev.ts
|
|
1882
2316
|
var import_child_process3 = require("child_process");
|
|
1883
|
-
var
|
|
2317
|
+
var import_fs9 = require("fs");
|
|
1884
2318
|
var import_prompts2 = __toESM(require("prompts"));
|
|
1885
2319
|
function dev_default(program2) {
|
|
1886
2320
|
program2.command("dev").description("Setup a local webhook development environment").option("-h, --host [host]", "Host to listen on", "host.k3d.internal").option("--confirm", "Skip confirmation prompt").action(async (opts) => {
|
|
@@ -1903,8 +2337,8 @@ function dev_default(program2) {
|
|
|
1903
2337
|
path,
|
|
1904
2338
|
opts.host
|
|
1905
2339
|
);
|
|
1906
|
-
await
|
|
1907
|
-
await
|
|
2340
|
+
await import_fs9.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
|
|
2341
|
+
await import_fs9.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
|
|
1908
2342
|
try {
|
|
1909
2343
|
let program3;
|
|
1910
2344
|
const runFork = async () => {
|
|
@@ -1943,7 +2377,7 @@ function dev_default(program2) {
|
|
|
1943
2377
|
}
|
|
1944
2378
|
|
|
1945
2379
|
// src/cli/monitor.ts
|
|
1946
|
-
var
|
|
2380
|
+
var import_client_node4 = require("@kubernetes/client-node");
|
|
1947
2381
|
var import_kubernetes_fluent_client4 = require("kubernetes-fluent-client");
|
|
1948
2382
|
var import_stream = __toESM(require("stream"));
|
|
1949
2383
|
function monitor_default(program2) {
|
|
@@ -1963,9 +2397,9 @@ function monitor_default(program2) {
|
|
|
1963
2397
|
console.error(errorMessage);
|
|
1964
2398
|
process.exit(1);
|
|
1965
2399
|
}
|
|
1966
|
-
const kc = new
|
|
2400
|
+
const kc = new import_client_node4.KubeConfig();
|
|
1967
2401
|
kc.loadFromDefault();
|
|
1968
|
-
const log = new
|
|
2402
|
+
const log = new import_client_node4.Log(kc);
|
|
1969
2403
|
const logStream = new import_stream.default.PassThrough();
|
|
1970
2404
|
logStream.on("data", (chunk) => {
|
|
1971
2405
|
const respMsg = `"msg":"Check response"`;
|
|
@@ -1978,16 +2412,23 @@ function monitor_default(program2) {
|
|
|
1978
2412
|
const name2 = `${payload.namespace}${payload.name}`;
|
|
1979
2413
|
const uid = payload.uid;
|
|
1980
2414
|
if (isMutate) {
|
|
1981
|
-
const
|
|
2415
|
+
const plainPatch = atob(payload.res.patch) || "";
|
|
2416
|
+
const patch = JSON.stringify(JSON.parse(plainPatch), null, 2);
|
|
2417
|
+
const patchType = payload.res.patchType || payload.res.warnings || "";
|
|
2418
|
+
const allowOrDeny = payload.res.allowed ? "\u{1F500}" : "\u{1F6AB}";
|
|
1982
2419
|
console.log(`
|
|
1983
2420
|
${allowOrDeny} MUTATE ${name2} (${uid})`);
|
|
2421
|
+
if (patchType.length > 0) {
|
|
2422
|
+
console.log(`
|
|
2423
|
+
\x1B[1;34m${patch}\x1B[0m`);
|
|
2424
|
+
}
|
|
1984
2425
|
} else {
|
|
1985
2426
|
const failures = Array.isArray(payload.res) ? payload.res : [payload.res];
|
|
1986
2427
|
const filteredFailures = failures.filter((r) => !r.allowed).map((r) => r.status.message);
|
|
1987
2428
|
if (filteredFailures.length > 0) {
|
|
1988
2429
|
console.log(`
|
|
1989
2430
|
\u274C VALIDATE ${name2} (${uid})`);
|
|
1990
|
-
console.debug(filteredFailures);
|
|
2431
|
+
console.debug(`\x1B[1;31m${filteredFailures}\x1B[0m`);
|
|
1991
2432
|
} else {
|
|
1992
2433
|
console.log(`
|
|
1993
2434
|
\u2705 VALIDATE ${name2} (${uid})`);
|
|
@@ -2012,11 +2453,11 @@ IGNORED - Unable to parse line: ${line}.`);
|
|
|
2012
2453
|
|
|
2013
2454
|
// src/cli/init/index.ts
|
|
2014
2455
|
var import_child_process4 = require("child_process");
|
|
2015
|
-
var
|
|
2456
|
+
var import_path3 = require("path");
|
|
2016
2457
|
var import_prompts4 = __toESM(require("prompts"));
|
|
2017
2458
|
|
|
2018
2459
|
// src/cli/init/walkthrough.ts
|
|
2019
|
-
var
|
|
2460
|
+
var import_fs10 = require("fs");
|
|
2020
2461
|
var import_prompts3 = __toESM(require("prompts"));
|
|
2021
2462
|
|
|
2022
2463
|
// src/lib/errors.ts
|
|
@@ -2036,7 +2477,7 @@ function walkthrough() {
|
|
|
2036
2477
|
validate: async (val) => {
|
|
2037
2478
|
try {
|
|
2038
2479
|
const name2 = sanitizeName(val);
|
|
2039
|
-
await
|
|
2480
|
+
await import_fs10.promises.access(name2, import_fs10.promises.constants.F_OK);
|
|
2040
2481
|
return "A directory with this name already exists";
|
|
2041
2482
|
} catch (e) {
|
|
2042
2483
|
return val.length > 2 || "The name must be at least 3 characters long";
|
|
@@ -2115,19 +2556,19 @@ function init_default(program2) {
|
|
|
2115
2556
|
console.log("Creating new Pepr module...");
|
|
2116
2557
|
try {
|
|
2117
2558
|
await createDir(dirName);
|
|
2118
|
-
await createDir((0,
|
|
2119
|
-
await createDir((0,
|
|
2120
|
-
await write((0,
|
|
2121
|
-
await write((0,
|
|
2122
|
-
await write((0,
|
|
2123
|
-
await write((0,
|
|
2124
|
-
await write((0,
|
|
2125
|
-
await write((0,
|
|
2126
|
-
await write((0,
|
|
2127
|
-
await write((0,
|
|
2128
|
-
await write((0,
|
|
2129
|
-
await write((0,
|
|
2130
|
-
await write((0,
|
|
2559
|
+
await createDir((0, import_path3.resolve)(dirName, ".vscode"));
|
|
2560
|
+
await createDir((0, import_path3.resolve)(dirName, "capabilities"));
|
|
2561
|
+
await write((0, import_path3.resolve)(dirName, gitignore.path), gitignore.data);
|
|
2562
|
+
await write((0, import_path3.resolve)(dirName, eslint.path), eslint.data);
|
|
2563
|
+
await write((0, import_path3.resolve)(dirName, prettier.path), prettier.data);
|
|
2564
|
+
await write((0, import_path3.resolve)(dirName, packageJSON2.path), packageJSON2.data);
|
|
2565
|
+
await write((0, import_path3.resolve)(dirName, readme.path), readme.data);
|
|
2566
|
+
await write((0, import_path3.resolve)(dirName, tsConfig.path), tsConfig.data);
|
|
2567
|
+
await write((0, import_path3.resolve)(dirName, peprTS3.path), peprTS3.data);
|
|
2568
|
+
await write((0, import_path3.resolve)(dirName, ".vscode", snippet.path), snippet.data);
|
|
2569
|
+
await write((0, import_path3.resolve)(dirName, ".vscode", codeSettings.path), codeSettings.data);
|
|
2570
|
+
await write((0, import_path3.resolve)(dirName, "capabilities", samplesYaml.path), samplesYaml.data);
|
|
2571
|
+
await write((0, import_path3.resolve)(dirName, "capabilities", helloPepr.path), helloPepr.data);
|
|
2131
2572
|
if (!opts.skipPostInit) {
|
|
2132
2573
|
process.chdir(dirName);
|
|
2133
2574
|
(0, import_child_process4.execSync)("npm install", {
|
|
@@ -2182,11 +2623,11 @@ function uuid_default(program2) {
|
|
|
2182
2623
|
}
|
|
2183
2624
|
|
|
2184
2625
|
// src/cli/root.ts
|
|
2185
|
-
var
|
|
2186
|
-
var RootCmd = class extends
|
|
2626
|
+
var import_commander2 = require("commander");
|
|
2627
|
+
var RootCmd = class extends import_commander2.Command {
|
|
2187
2628
|
// eslint-disable-next-line class-methods-use-this
|
|
2188
2629
|
createCommand(name2) {
|
|
2189
|
-
const cmd = new
|
|
2630
|
+
const cmd = new import_commander2.Command(name2);
|
|
2190
2631
|
cmd.option("-l, --log-level [level]", "Log level: debug, info, warn, error", "info");
|
|
2191
2632
|
cmd.hook("preAction", (run) => {
|
|
2192
2633
|
logger_default.level = run.opts().logLevel;
|
|
@@ -2197,8 +2638,8 @@ var RootCmd = class extends import_commander3.Command {
|
|
|
2197
2638
|
|
|
2198
2639
|
// src/cli/update.ts
|
|
2199
2640
|
var import_child_process5 = require("child_process");
|
|
2200
|
-
var
|
|
2201
|
-
var
|
|
2641
|
+
var import_fs11 = __toESM(require("fs"));
|
|
2642
|
+
var import_path4 = require("path");
|
|
2202
2643
|
var import_prompts5 = __toESM(require("prompts"));
|
|
2203
2644
|
function update_default(program2) {
|
|
2204
2645
|
program2.command("update").description("Update this Pepr module").option("--skip-template-update", "Skip updating the template files").action(async (opts) => {
|
|
@@ -2232,17 +2673,17 @@ function update_default(program2) {
|
|
|
2232
2673
|
console.log("Updating Pepr config and template tiles...");
|
|
2233
2674
|
try {
|
|
2234
2675
|
if (!opts.skipTemplateUpdate) {
|
|
2235
|
-
await write((0,
|
|
2236
|
-
await write((0,
|
|
2237
|
-
await write((0,
|
|
2238
|
-
await write((0,
|
|
2239
|
-
const samplePath = (0,
|
|
2240
|
-
if (
|
|
2241
|
-
|
|
2676
|
+
await write((0, import_path4.resolve)(prettier.path), prettier.data);
|
|
2677
|
+
await write((0, import_path4.resolve)(tsConfig.path), tsConfig.data);
|
|
2678
|
+
await write((0, import_path4.resolve)(".vscode", snippet.path), snippet.data);
|
|
2679
|
+
await write((0, import_path4.resolve)(".vscode", codeSettings.path), codeSettings.data);
|
|
2680
|
+
const samplePath = (0, import_path4.resolve)("capabilities", samplesYaml.path);
|
|
2681
|
+
if (import_fs11.default.existsSync(samplePath)) {
|
|
2682
|
+
import_fs11.default.unlinkSync(samplePath);
|
|
2242
2683
|
await write(samplePath, samplesYaml.data);
|
|
2243
2684
|
}
|
|
2244
|
-
const tsPath = (0,
|
|
2245
|
-
if (
|
|
2685
|
+
const tsPath = (0, import_path4.resolve)("capabilities", helloPepr.path);
|
|
2686
|
+
if (import_fs11.default.existsSync(tsPath)) {
|
|
2246
2687
|
await write(tsPath, helloPepr.data);
|
|
2247
2688
|
}
|
|
2248
2689
|
}
|
|
@@ -2253,6 +2694,39 @@ function update_default(program2) {
|
|
|
2253
2694
|
});
|
|
2254
2695
|
}
|
|
2255
2696
|
|
|
2697
|
+
// src/cli/kfc.ts
|
|
2698
|
+
var import_child_process6 = require("child_process");
|
|
2699
|
+
var import_prompts6 = __toESM(require("prompts"));
|
|
2700
|
+
function kfc_default(program2) {
|
|
2701
|
+
program2.command("kfc [args...]").description("Execute Kubernetes Fluent Client commands").action(async (args) => {
|
|
2702
|
+
const { confirm: confirm2 } = await (0, import_prompts6.default)({
|
|
2703
|
+
type: "confirm",
|
|
2704
|
+
name: "confirm",
|
|
2705
|
+
message: "For commands that generate files, this may overwrite any previously generated files.\nAre you sure you want to continue?"
|
|
2706
|
+
});
|
|
2707
|
+
if (!confirm2) {
|
|
2708
|
+
return;
|
|
2709
|
+
}
|
|
2710
|
+
console.log("Preparing to execute the requested KFC command...");
|
|
2711
|
+
try {
|
|
2712
|
+
if (args.length === 0) {
|
|
2713
|
+
console.log(
|
|
2714
|
+
"No kubernetes-fluent-client arguments provided. Showing kubernetes-fluent-client help..."
|
|
2715
|
+
);
|
|
2716
|
+
args.push("--help");
|
|
2717
|
+
}
|
|
2718
|
+
const argsString = args.join(" ");
|
|
2719
|
+
(0, import_child_process6.execSync)(`kubernetes-fluent-client ${argsString}`, {
|
|
2720
|
+
stdio: "inherit"
|
|
2721
|
+
});
|
|
2722
|
+
console.log(`\u2705 KFC command executed successfully`);
|
|
2723
|
+
} catch (e) {
|
|
2724
|
+
console.error(e.message);
|
|
2725
|
+
process.exit(1);
|
|
2726
|
+
}
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2256
2730
|
// src/cli.ts
|
|
2257
2731
|
if (process.env.npm_lifecycle_event !== "npx") {
|
|
2258
2732
|
console.warn("Pepr should be run via `npx pepr <command>` instead of `pepr <command>`.");
|
|
@@ -2277,4 +2751,5 @@ update_default(program);
|
|
|
2277
2751
|
format_default(program);
|
|
2278
2752
|
monitor_default(program);
|
|
2279
2753
|
uuid_default(program);
|
|
2754
|
+
kfc_default(program);
|
|
2280
2755
|
program.parse();
|