pepr 0.42.1 → 0.42.3
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.helpers.d.ts +1 -1
- package/dist/cli/build.helpers.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts +15 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.helpers.d.ts +3 -0
- package/dist/cli/format.helpers.d.ts.map +1 -0
- package/dist/cli/init/enums.d.ts +10 -0
- package/dist/cli/init/enums.d.ts.map +1 -0
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +15 -11
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/init/utils.d.ts.map +1 -1
- package/dist/cli/init/walkthrough.d.ts +3 -2
- package/dist/cli/init/walkthrough.d.ts.map +1 -1
- package/dist/cli/kfc.d.ts.map +1 -1
- package/dist/cli/root.d.ts.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +1073 -1220
- package/dist/controller.js +1 -195
- package/dist/fixtures/loader.d.ts.map +1 -1
- package/dist/lib/assets/assets.d.ts +27 -0
- package/dist/lib/assets/assets.d.ts.map +1 -0
- package/dist/lib/assets/deploy.d.ts +1 -1
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/index.d.ts +5 -24
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/pods.d.ts +2 -4
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/webhooks.d.ts +1 -1
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts +31 -5
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts +2 -2
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +1 -1
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts +1 -1
- package/dist/lib/controller/storeCache.d.ts.map +1 -1
- package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
- package/dist/lib/core/capability.d.ts.map +1 -0
- package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
- package/dist/lib/core/module.d.ts.map +1 -0
- package/dist/lib/core/queue.d.ts.map +1 -0
- package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
- package/dist/lib/core/schedule.d.ts.map +1 -0
- package/dist/lib/core/storage.d.ts.map +1 -0
- package/dist/lib/deploymentChecks.d.ts.map +1 -1
- package/dist/lib/errors.d.ts +0 -5
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/filesystemService.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
- package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
- package/dist/lib/filter/filter.d.ts +33 -1
- package/dist/lib/filter/filter.d.ts.map +1 -1
- package/dist/lib/finalizer.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +4 -9
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/included-files.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/processors/mutate-processor.d.ts +28 -0
- package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
- package/dist/lib/{validate-processor.d.ts → processors/validate-processor.d.ts} +5 -5
- package/dist/lib/processors/validate-processor.d.ts.map +1 -0
- package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
- package/dist/lib/processors/watch-processor.d.ts.map +1 -0
- package/dist/lib/telemetry/logger.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts +2 -2
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +383 -243
- package/dist/lib.js.map +4 -4
- package/dist/sdk/heredoc.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/cli/build.helpers.ts +1 -1
- package/src/cli/build.ts +1 -1
- package/src/cli/deploy.ts +114 -75
- package/src/cli/dev.ts +3 -3
- package/src/cli/format.helpers.ts +27 -0
- package/src/cli/format.ts +4 -18
- package/src/cli/init/enums.ts +9 -0
- package/src/cli/init/index.ts +4 -3
- package/src/cli/init/templates.ts +30 -2
- package/src/cli/init/utils.ts +3 -3
- package/src/cli/init/walkthrough.ts +7 -8
- package/src/cli/kfc.ts +1 -1
- package/src/cli/root.ts +1 -1
- package/src/cli/update.ts +1 -1
- package/src/cli/uuid.ts +1 -1
- package/src/fixtures/loader.ts +2 -2
- package/src/lib/assets/assets.ts +176 -0
- package/src/lib/assets/deploy.ts +6 -6
- package/src/lib/assets/index.ts +10 -144
- package/src/lib/assets/pods.ts +2 -2
- package/src/lib/assets/webhooks.ts +32 -56
- package/src/lib/assets/yaml.ts +47 -25
- package/src/lib/controller/index.ts +4 -4
- package/src/lib/controller/store.ts +2 -2
- package/src/lib/controller/storeCache.ts +6 -2
- package/src/lib/{capability.ts → core/capability.ts} +4 -4
- package/src/lib/{module.ts → core/module.ts} +10 -10
- package/src/lib/{queue.ts → core/queue.ts} +1 -1
- package/src/lib/deploymentChecks.ts +2 -2
- package/src/lib/errors.ts +3 -8
- package/src/lib/filesystemService.ts +1 -1
- package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
- package/src/lib/filter/filter.ts +204 -111
- package/src/lib/finalizer.ts +2 -2
- package/src/lib/helpers.ts +20 -133
- package/src/lib/included-files.ts +1 -1
- package/src/lib/processors/mutate-processor.ts +225 -0
- package/src/lib/{validate-processor.ts → processors/validate-processor.ts} +8 -8
- package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +8 -8
- package/src/lib/telemetry/logger.ts +3 -1
- package/src/lib/tls.ts +5 -1
- package/src/lib/validate-request.ts +4 -4
- package/src/lib.ts +2 -2
- package/src/runtime/controller.ts +2 -2
- package/src/sdk/heredoc.ts +1 -1
- package/dist/lib/capability.d.ts.map +0 -1
- package/dist/lib/module.d.ts.map +0 -1
- package/dist/lib/mutate-processor.d.ts +0 -6
- package/dist/lib/mutate-processor.d.ts.map +0 -1
- package/dist/lib/queue.d.ts.map +0 -1
- package/dist/lib/schedule.d.ts.map +0 -1
- package/dist/lib/storage.d.ts.map +0 -1
- package/dist/lib/validate-processor.d.ts.map +0 -1
- package/dist/lib/watch-processor.d.ts.map +0 -1
- package/src/lib/mutate-processor.ts +0 -165
- /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
- /package/dist/lib/{storage.d.ts → core/storage.d.ts} +0 -0
- /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
- /package/src/lib/{storage.ts → core/storage.ts} +0 -0
package/dist/cli.js
CHANGED
|
@@ -91,9 +91,8 @@ var import_esbuild2 = require("esbuild");
|
|
|
91
91
|
var import_fs9 = require("fs");
|
|
92
92
|
var import_path3 = require("path");
|
|
93
93
|
|
|
94
|
-
// src/lib/assets/
|
|
95
|
-
var
|
|
96
|
-
var import_client_node2 = require("@kubernetes/client-node");
|
|
94
|
+
// src/lib/assets/assets.ts
|
|
95
|
+
var import_crypto2 = __toESM(require("crypto"));
|
|
97
96
|
|
|
98
97
|
// src/lib/tls.ts
|
|
99
98
|
var import_node_forge = __toESM(require("node-forge"));
|
|
@@ -152,453 +151,529 @@ function genCert(key, name2, issuer) {
|
|
|
152
151
|
return crt;
|
|
153
152
|
}
|
|
154
153
|
|
|
155
|
-
// src/lib/assets/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
};
|
|
169
|
-
var transport = isPrettyLog ? pretty : void 0;
|
|
170
|
-
var pinoTimeFunction = process.env.PINO_TIME_STAMP === "iso" ? () => import_pino.stdTimeFunctions.isoTime() : () => import_pino.stdTimeFunctions.epochTime();
|
|
171
|
-
var Log = (0, import_pino.pino)({
|
|
172
|
-
transport,
|
|
173
|
-
timestamp: pinoTimeFunction
|
|
174
|
-
});
|
|
175
|
-
if (process.env.LOG_LEVEL) {
|
|
176
|
-
Log.level = process.env.LOG_LEVEL;
|
|
177
|
-
}
|
|
178
|
-
var logger_default = Log;
|
|
179
|
-
|
|
180
|
-
// src/lib/assets/networking.ts
|
|
181
|
-
function apiTokenSecret(name2, apiToken) {
|
|
182
|
-
return {
|
|
183
|
-
apiVersion: "v1",
|
|
184
|
-
kind: "Secret",
|
|
185
|
-
metadata: {
|
|
186
|
-
name: `${name2}-api-token`,
|
|
187
|
-
namespace: "pepr-system"
|
|
188
|
-
},
|
|
189
|
-
type: "Opaque",
|
|
190
|
-
data: {
|
|
191
|
-
value: Buffer.from(apiToken).toString("base64")
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
function tlsSecret(name2, tls) {
|
|
196
|
-
return {
|
|
197
|
-
apiVersion: "v1",
|
|
198
|
-
kind: "Secret",
|
|
199
|
-
metadata: {
|
|
200
|
-
name: `${name2}-tls`,
|
|
201
|
-
namespace: "pepr-system"
|
|
202
|
-
},
|
|
203
|
-
type: "kubernetes.io/tls",
|
|
204
|
-
data: {
|
|
205
|
-
"tls.crt": tls.crt,
|
|
206
|
-
"tls.key": tls.key
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function service(name2) {
|
|
211
|
-
return {
|
|
212
|
-
apiVersion: "v1",
|
|
213
|
-
kind: "Service",
|
|
214
|
-
metadata: {
|
|
215
|
-
name: name2,
|
|
216
|
-
namespace: "pepr-system",
|
|
217
|
-
labels: {
|
|
218
|
-
"pepr.dev/controller": "admission"
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
spec: {
|
|
222
|
-
selector: {
|
|
223
|
-
app: name2,
|
|
224
|
-
"pepr.dev/controller": "admission"
|
|
225
|
-
},
|
|
226
|
-
ports: [
|
|
227
|
-
{
|
|
228
|
-
port: 443,
|
|
229
|
-
targetPort: 3e3
|
|
230
|
-
}
|
|
231
|
-
]
|
|
232
|
-
}
|
|
233
|
-
};
|
|
154
|
+
// src/lib/assets/helm.ts
|
|
155
|
+
function clusterRoleTemplate() {
|
|
156
|
+
return `
|
|
157
|
+
apiVersion: rbac.authorization.k8s.io/v1
|
|
158
|
+
kind: ClusterRole
|
|
159
|
+
metadata:
|
|
160
|
+
name: {{ .Values.uuid }}
|
|
161
|
+
namespace: pepr-system
|
|
162
|
+
rules:
|
|
163
|
+
{{- if .Values.rbac }}
|
|
164
|
+
{{- toYaml .Values.rbac | nindent 2 }}
|
|
165
|
+
{{- end }}
|
|
166
|
+
`;
|
|
234
167
|
}
|
|
235
|
-
function
|
|
236
|
-
return
|
|
237
|
-
apiVersion:
|
|
238
|
-
kind:
|
|
239
|
-
metadata:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
251
|
-
ports: [
|
|
252
|
-
{
|
|
253
|
-
port: 443,
|
|
254
|
-
targetPort: 3e3
|
|
255
|
-
}
|
|
256
|
-
]
|
|
257
|
-
}
|
|
258
|
-
};
|
|
168
|
+
function namespaceTemplate() {
|
|
169
|
+
return `
|
|
170
|
+
apiVersion: v1
|
|
171
|
+
kind: Namespace
|
|
172
|
+
metadata:
|
|
173
|
+
name: pepr-system
|
|
174
|
+
{{- if .Values.namespace.annotations }}
|
|
175
|
+
annotations:
|
|
176
|
+
{{- toYaml .Values.namespace.annotations | nindent 6 }}
|
|
177
|
+
{{- end }}
|
|
178
|
+
{{- if .Values.namespace.labels }}
|
|
179
|
+
labels:
|
|
180
|
+
{{- toYaml .Values.namespace.labels | nindent 6 }}
|
|
181
|
+
{{- end }}
|
|
182
|
+
`;
|
|
259
183
|
}
|
|
184
|
+
function chartYaml(name2, description) {
|
|
185
|
+
return `
|
|
186
|
+
apiVersion: v2
|
|
187
|
+
name: ${name2}
|
|
188
|
+
description: ${description || ""}
|
|
260
189
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
190
|
+
# A chart can be either an 'application' or a 'library' chart.
|
|
191
|
+
#
|
|
192
|
+
# Application charts are a collection of templates that can be packaged into versioned archives
|
|
193
|
+
# to be deployed.
|
|
194
|
+
#
|
|
195
|
+
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
|
196
|
+
# a dependency of application charts to inject those utilities and functions into the rendering
|
|
197
|
+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
|
198
|
+
type: application
|
|
269
199
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
(0, import_ramda.defaultTo)("")
|
|
275
|
-
);
|
|
276
|
-
var declaredGroup = (0, import_ramda.pipe)(
|
|
277
|
-
(request) => request?.kind?.group,
|
|
278
|
-
(0, import_ramda.defaultTo)("")
|
|
279
|
-
);
|
|
280
|
-
var declaredVersion = (0, import_ramda.pipe)(
|
|
281
|
-
(request) => request?.kind?.version,
|
|
282
|
-
(0, import_ramda.defaultTo)("")
|
|
283
|
-
);
|
|
284
|
-
var declaredKind = (0, import_ramda.pipe)(
|
|
285
|
-
(request) => request?.kind?.kind,
|
|
286
|
-
(0, import_ramda.defaultTo)("")
|
|
287
|
-
);
|
|
288
|
-
var declaredUid = (0, import_ramda.pipe)((request) => request?.uid, (0, import_ramda.defaultTo)(""));
|
|
289
|
-
var carriesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
290
|
-
(kubernetesObject) => !!kubernetesObject.metadata?.deletionTimestamp,
|
|
291
|
-
(0, import_ramda.defaultTo)(false)
|
|
292
|
-
);
|
|
293
|
-
var missingDeletionTimestamp = (0, import_ramda.complement)(carriesDeletionTimestamp);
|
|
294
|
-
var carriedKind = (0, import_ramda.pipe)(
|
|
295
|
-
(kubernetesObject) => kubernetesObject?.kind,
|
|
296
|
-
(0, import_ramda.defaultTo)("not set")
|
|
297
|
-
);
|
|
298
|
-
var carriedVersion = (0, import_ramda.pipe)(
|
|
299
|
-
(kubernetesObject) => kubernetesObject?.metadata?.resourceVersion,
|
|
300
|
-
(0, import_ramda.defaultTo)("not set")
|
|
301
|
-
);
|
|
302
|
-
var carriedName = (0, import_ramda.pipe)(
|
|
303
|
-
(kubernetesObject) => kubernetesObject?.metadata?.name,
|
|
304
|
-
(0, import_ramda.defaultTo)("")
|
|
305
|
-
);
|
|
306
|
-
var carriesName = (0, import_ramda.pipe)(carriedName, (0, import_ramda.equals)(""), import_ramda.not);
|
|
307
|
-
var missingName = (0, import_ramda.complement)(carriesName);
|
|
308
|
-
var carriedNamespace = (0, import_ramda.pipe)(
|
|
309
|
-
(kubernetesObject) => kubernetesObject?.metadata?.namespace,
|
|
310
|
-
(0, import_ramda.defaultTo)("")
|
|
311
|
-
);
|
|
312
|
-
var carriesNamespace = (0, import_ramda.pipe)(carriedNamespace, (0, import_ramda.equals)(""), import_ramda.not);
|
|
313
|
-
var carriedAnnotations = (0, import_ramda.pipe)(
|
|
314
|
-
(kubernetesObject) => kubernetesObject?.metadata?.annotations,
|
|
315
|
-
(0, import_ramda.defaultTo)({})
|
|
316
|
-
);
|
|
317
|
-
var carriesAnnotations = (0, import_ramda.pipe)(carriedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
|
|
318
|
-
var carriedLabels = (0, import_ramda.pipe)(
|
|
319
|
-
(kubernetesObject) => kubernetesObject?.metadata?.labels,
|
|
320
|
-
(0, import_ramda.defaultTo)({})
|
|
321
|
-
);
|
|
322
|
-
var carriesLabels = (0, import_ramda.pipe)(carriedLabels, (0, import_ramda.equals)({}), import_ramda.not);
|
|
323
|
-
var definesDeletionTimestamp = (0, import_ramda.pipe)(
|
|
324
|
-
(binding) => binding?.filters?.deletionTimestamp ?? false,
|
|
325
|
-
(0, import_ramda.defaultTo)(false)
|
|
326
|
-
);
|
|
327
|
-
var ignoresDeletionTimestamp = (0, import_ramda.complement)(definesDeletionTimestamp);
|
|
328
|
-
var definedName = (0, import_ramda.pipe)((binding) => {
|
|
329
|
-
return binding.filters.name;
|
|
330
|
-
}, (0, import_ramda.defaultTo)(""));
|
|
331
|
-
var definesName = (0, import_ramda.pipe)(definedName, (0, import_ramda.equals)(""), import_ramda.not);
|
|
332
|
-
var ignoresName = (0, import_ramda.complement)(definesName);
|
|
333
|
-
var definedNameRegex = (0, import_ramda.pipe)(
|
|
334
|
-
(binding) => binding.filters?.regexName,
|
|
335
|
-
(0, import_ramda.defaultTo)("")
|
|
336
|
-
);
|
|
337
|
-
var definesNameRegex = (0, import_ramda.pipe)(definedNameRegex, (0, import_ramda.equals)(""), import_ramda.not);
|
|
338
|
-
var definedNamespaces = (0, import_ramda.pipe)((binding) => binding?.filters?.namespaces, (0, import_ramda.defaultTo)([]));
|
|
339
|
-
var definesNamespaces = (0, import_ramda.pipe)(definedNamespaces, (0, import_ramda.equals)([]), import_ramda.not);
|
|
340
|
-
var definedNamespaceRegexes = (0, import_ramda.pipe)((binding) => binding?.filters?.regexNamespaces, (0, import_ramda.defaultTo)([]));
|
|
341
|
-
var definesNamespaceRegexes = (0, import_ramda.pipe)(definedNamespaceRegexes, (0, import_ramda.equals)([]), import_ramda.not);
|
|
342
|
-
var definedAnnotations = (0, import_ramda.pipe)((binding) => binding?.filters?.annotations, (0, import_ramda.defaultTo)({}));
|
|
343
|
-
var definesAnnotations = (0, import_ramda.pipe)(definedAnnotations, (0, import_ramda.equals)({}), import_ramda.not);
|
|
344
|
-
var definedLabels = (0, import_ramda.pipe)((binding) => binding?.filters?.labels, (0, import_ramda.defaultTo)({}));
|
|
345
|
-
var definesLabels = (0, import_ramda.pipe)(definedLabels, (0, import_ramda.equals)({}), import_ramda.not);
|
|
346
|
-
var definedEvent = (binding) => {
|
|
347
|
-
return binding.event;
|
|
348
|
-
};
|
|
349
|
-
var definesDelete = (0, import_ramda.pipe)(definedEvent, (0, import_ramda.equals)("DELETE" /* DELETE */));
|
|
350
|
-
var definedGroup = (0, import_ramda.pipe)((binding) => binding?.kind?.group, (0, import_ramda.defaultTo)(""));
|
|
351
|
-
var definesGroup = (0, import_ramda.pipe)(definedGroup, (0, import_ramda.equals)(""), import_ramda.not);
|
|
352
|
-
var definedVersion = (0, import_ramda.pipe)(
|
|
353
|
-
(binding) => binding?.kind?.version,
|
|
354
|
-
(0, import_ramda.defaultTo)("")
|
|
355
|
-
);
|
|
356
|
-
var definesVersion = (0, import_ramda.pipe)(definedVersion, (0, import_ramda.equals)(""), import_ramda.not);
|
|
357
|
-
var definedKind = (0, import_ramda.pipe)((binding) => binding?.kind?.kind, (0, import_ramda.defaultTo)(""));
|
|
358
|
-
var definesKind = (0, import_ramda.pipe)(definedKind, (0, import_ramda.equals)(""), import_ramda.not);
|
|
359
|
-
var definedCallback = (binding) => {
|
|
360
|
-
return binding.isFinalize ? binding.finalizeCallback : binding.isWatch ? binding.watchCallback : binding.isMutate ? binding.mutateCallback : binding.isValidate ? binding.validateCallback : null;
|
|
361
|
-
};
|
|
362
|
-
var definedCallbackName = (0, import_ramda.pipe)(definedCallback, (0, import_ramda.defaultTo)({ name: "" }), (callback) => callback.name);
|
|
363
|
-
var mismatchedDeletionTimestamp = (0, import_ramda.allPass)([
|
|
364
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesDeletionTimestamp),
|
|
365
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), missingDeletionTimestamp)
|
|
366
|
-
]);
|
|
367
|
-
var mismatchedName = (0, import_ramda.allPass)([
|
|
368
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesName),
|
|
369
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => definedName(binding) !== carriedName(kubernetesObject))
|
|
370
|
-
]);
|
|
371
|
-
var mismatchedNameRegex = (0, import_ramda.allPass)([
|
|
372
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNameRegex),
|
|
373
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => new RegExp(definedNameRegex(binding)).test(carriedName(kubernetesObject)), import_ramda.not)
|
|
374
|
-
]);
|
|
375
|
-
var bindsToKind = (0, import_ramda.curry)(
|
|
376
|
-
(0, import_ramda.allPass)([(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definedKind, (0, import_ramda.equals)(""), import_ramda.not), (0, import_ramda.pipe)((binding, kind8) => definedKind(binding) === kind8)])
|
|
377
|
-
);
|
|
378
|
-
var bindsToNamespace = (0, import_ramda.curry)((0, import_ramda.pipe)(bindsToKind(import_ramda.__, "Namespace")));
|
|
379
|
-
var misboundNamespace = (0, import_ramda.allPass)([bindsToNamespace, definesNamespaces]);
|
|
380
|
-
var mismatchedNamespace = (0, import_ramda.allPass)([
|
|
381
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaces),
|
|
382
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => definedNamespaces(binding).includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
383
|
-
]);
|
|
384
|
-
var mismatchedNamespaceRegex = (0, import_ramda.allPass)([
|
|
385
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesNamespaceRegexes),
|
|
386
|
-
(0, import_ramda.pipe)(
|
|
387
|
-
(binding, kubernetesObject) => (0, import_ramda.pipe)(
|
|
388
|
-
(0, import_ramda.any)((regEx) => new RegExp(regEx).test(carriedNamespace(kubernetesObject))),
|
|
389
|
-
import_ramda.not
|
|
390
|
-
)(definedNamespaceRegexes(binding))
|
|
391
|
-
)
|
|
392
|
-
]);
|
|
393
|
-
var metasMismatch = (0, import_ramda.pipe)(
|
|
394
|
-
(defined, carried) => {
|
|
395
|
-
const result = { defined, carried, unalike: {} };
|
|
396
|
-
result.unalike = Object.entries(result.defined).map(([key, value]) => {
|
|
397
|
-
const keyMissing = !Object.hasOwn(result.carried, key);
|
|
398
|
-
const noValue = !value;
|
|
399
|
-
const valMissing = !result.carried[key];
|
|
400
|
-
const valDiffers = result.carried[key] !== result.defined[key];
|
|
401
|
-
return keyMissing ? { [key]: value } : noValue ? {} : valMissing ? { [key]: value } : valDiffers ? { [key]: value } : {};
|
|
402
|
-
}).reduce((acc, cur) => ({ ...acc, ...cur }), {});
|
|
403
|
-
return result.unalike;
|
|
404
|
-
},
|
|
405
|
-
(unalike) => Object.keys(unalike).length > 0
|
|
406
|
-
);
|
|
407
|
-
var mismatchedAnnotations = (0, import_ramda.allPass)([
|
|
408
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesAnnotations),
|
|
409
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedAnnotations(binding), carriedAnnotations(kubernetesObject)))
|
|
410
|
-
]);
|
|
411
|
-
var mismatchedLabels = (0, import_ramda.allPass)([
|
|
412
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesLabels),
|
|
413
|
-
(0, import_ramda.pipe)((binding, kubernetesObject) => metasMismatch(definedLabels(binding), carriedLabels(kubernetesObject)))
|
|
414
|
-
]);
|
|
415
|
-
var uncarryableNamespace = (0, import_ramda.allPass)([
|
|
416
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
417
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
418
|
-
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)), import_ramda.not)
|
|
419
|
-
]);
|
|
420
|
-
var missingCarriableNamespace = (0, import_ramda.allPass)([
|
|
421
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
422
|
-
(0, import_ramda.pipe)(
|
|
423
|
-
(namespaceSelector, kubernetesObject) => kubernetesObject.kind === "Namespace" ? !namespaceSelector.includes(kubernetesObject.metadata.name) : !carriesNamespace(kubernetesObject)
|
|
424
|
-
)
|
|
425
|
-
]);
|
|
426
|
-
var carriesIgnoredNamespace = (0, import_ramda.allPass)([
|
|
427
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
428
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), carriesNamespace),
|
|
429
|
-
(0, import_ramda.pipe)((namespaceSelector, kubernetesObject) => namespaceSelector.includes(carriedNamespace(kubernetesObject)))
|
|
430
|
-
]);
|
|
431
|
-
var unbindableNamespaces = (0, import_ramda.allPass)([
|
|
432
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), import_ramda.length, (0, import_ramda.gt)(import_ramda.__, 0)),
|
|
433
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), definesNamespaces),
|
|
434
|
-
(0, import_ramda.pipe)(
|
|
435
|
-
(namespaceSelector, binding) => (0, import_ramda.difference)(definedNamespaces(binding), namespaceSelector),
|
|
436
|
-
import_ramda.length,
|
|
437
|
-
(0, import_ramda.equals)(0),
|
|
438
|
-
import_ramda.not
|
|
439
|
-
)
|
|
440
|
-
]);
|
|
441
|
-
var misboundDeleteWithDeletionTimestamp = (0, import_ramda.allPass)([definesDelete, definesDeletionTimestamp]);
|
|
442
|
-
var operationMatchesEvent = (0, import_ramda.anyPass)([
|
|
443
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(1), (0, import_ramda.equals)("*" /* ANY */)),
|
|
444
|
-
(0, import_ramda.pipe)((operation, event) => operation.valueOf() === event.valueOf()),
|
|
445
|
-
(0, import_ramda.pipe)((operation, event) => operation ? event.includes(operation) : false)
|
|
446
|
-
]);
|
|
447
|
-
var mismatchedEvent = (0, import_ramda.pipe)(
|
|
448
|
-
(binding, request) => operationMatchesEvent(declaredOperation(request), definedEvent(binding)),
|
|
449
|
-
import_ramda.not
|
|
450
|
-
);
|
|
451
|
-
var mismatchedGroup = (0, import_ramda.allPass)([
|
|
452
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesGroup),
|
|
453
|
-
(0, import_ramda.pipe)((binding, request) => definedGroup(binding) !== declaredGroup(request))
|
|
454
|
-
]);
|
|
455
|
-
var mismatchedVersion = (0, import_ramda.allPass)([
|
|
456
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesVersion),
|
|
457
|
-
(0, import_ramda.pipe)((binding, request) => definedVersion(binding) !== declaredVersion(request))
|
|
458
|
-
]);
|
|
459
|
-
var mismatchedKind = (0, import_ramda.allPass)([
|
|
460
|
-
(0, import_ramda.pipe)((0, import_ramda.nthArg)(0), definesKind),
|
|
461
|
-
(0, import_ramda.pipe)((binding, request) => definedKind(binding) !== declaredKind(request))
|
|
462
|
-
]);
|
|
200
|
+
# This is the chart version. This version number should be incremented each time you make changes
|
|
201
|
+
# to the chart and its templates, including the app version.
|
|
202
|
+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
|
203
|
+
version: 0.1.0
|
|
463
204
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
function validateCapabilityNames(capabilities) {
|
|
471
|
-
if (capabilities && capabilities.length > 0) {
|
|
472
|
-
for (let i = 0; i < capabilities.length; i++) {
|
|
473
|
-
if (capabilities[i].name !== sanitizeResourceName(capabilities[i].name)) {
|
|
474
|
-
throw new ValidationError(`Capability name is not a valid Kubernetes resource name: ${capabilities[i].name}`);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
function createRBACMap(capabilities) {
|
|
480
|
-
return capabilities.reduce((acc, capability) => {
|
|
481
|
-
capability.bindings.forEach((binding) => {
|
|
482
|
-
const key = `${binding.kind.group}/${binding.kind.version}/${binding.kind.kind}`;
|
|
483
|
-
acc["pepr.dev/v1/peprstore"] = {
|
|
484
|
-
verbs: ["create", "get", "patch", "watch"],
|
|
485
|
-
plural: "peprstores"
|
|
486
|
-
};
|
|
487
|
-
acc["apiextensions.k8s.io/v1/customresourcedefinition"] = {
|
|
488
|
-
verbs: ["patch", "create"],
|
|
489
|
-
plural: "customresourcedefinitions"
|
|
490
|
-
};
|
|
491
|
-
if (!acc[key] && binding.isWatch) {
|
|
492
|
-
acc[key] = {
|
|
493
|
-
verbs: ["watch"],
|
|
494
|
-
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
if (binding.isFinalize) {
|
|
498
|
-
acc[key] = {
|
|
499
|
-
verbs: ["patch"],
|
|
500
|
-
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
return acc;
|
|
505
|
-
}, {});
|
|
506
|
-
}
|
|
507
|
-
function hasEveryOverlap(array1, array2) {
|
|
508
|
-
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
return array1.every((element) => array2.includes(element));
|
|
512
|
-
}
|
|
513
|
-
function hasAnyOverlap(array1, array2) {
|
|
514
|
-
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
515
|
-
return false;
|
|
516
|
-
}
|
|
517
|
-
return array1.some((element) => array2.includes(element));
|
|
518
|
-
}
|
|
519
|
-
function ignoredNamespaceConflict(ignoreNamespaces, bindingNamespaces) {
|
|
520
|
-
return hasAnyOverlap(bindingNamespaces, ignoreNamespaces);
|
|
521
|
-
}
|
|
522
|
-
function bindingAndCapabilityNSConflict(bindingNamespaces, capabilityNamespaces) {
|
|
523
|
-
if (!capabilityNamespaces) {
|
|
524
|
-
return false;
|
|
525
|
-
}
|
|
526
|
-
return capabilityNamespaces.length !== 0 && !hasEveryOverlap(bindingNamespaces, capabilityNamespaces);
|
|
527
|
-
}
|
|
528
|
-
function generateWatchNamespaceError(ignoredNamespaces, bindingNamespaces, capabilityNamespaces) {
|
|
529
|
-
let err = "";
|
|
530
|
-
if (ignoredNamespaceConflict(ignoredNamespaces, bindingNamespaces)) {
|
|
531
|
-
err += `Binding uses a Pepr ignored namespace: ignoredNamespaces: [${ignoredNamespaces.join(
|
|
532
|
-
", "
|
|
533
|
-
)}] bindingNamespaces: [${bindingNamespaces.join(", ")}].`;
|
|
534
|
-
}
|
|
535
|
-
if (bindingAndCapabilityNSConflict(bindingNamespaces, capabilityNamespaces)) {
|
|
536
|
-
err += `Binding uses namespace not governed by capability: bindingNamespaces: [${bindingNamespaces.join(
|
|
537
|
-
", "
|
|
538
|
-
)}] capabilityNamespaces: [${capabilityNamespaces.join(", ")}].`;
|
|
539
|
-
}
|
|
540
|
-
return err.replace(/\.([^ ])/g, ". $1");
|
|
205
|
+
# This is the version number of the application being deployed. This version number should be
|
|
206
|
+
# incremented each time you make changes to the application. Versions are not expected to
|
|
207
|
+
# follow Semantic Versioning. They should reflect the version the application is using.
|
|
208
|
+
# It is recommended to use it with quotes.
|
|
209
|
+
appVersion: "1.16.0"
|
|
210
|
+
`;
|
|
541
211
|
}
|
|
542
|
-
function
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
212
|
+
function watcherDeployTemplate(buildTimestamp) {
|
|
213
|
+
return `
|
|
214
|
+
apiVersion: apps/v1
|
|
215
|
+
kind: Deployment
|
|
216
|
+
metadata:
|
|
217
|
+
name: {{ .Values.uuid }}-watcher
|
|
218
|
+
namespace: pepr-system
|
|
219
|
+
annotations:
|
|
220
|
+
{{- toYaml .Values.watcher.annotations | nindent 4 }}
|
|
221
|
+
labels:
|
|
222
|
+
{{- toYaml .Values.watcher.labels | nindent 4 }}
|
|
223
|
+
spec:
|
|
224
|
+
replicas: 1
|
|
225
|
+
strategy:
|
|
226
|
+
type: Recreate
|
|
227
|
+
selector:
|
|
228
|
+
matchLabels:
|
|
229
|
+
app: {{ .Values.uuid }}-watcher
|
|
230
|
+
pepr.dev/controller: watcher
|
|
231
|
+
template:
|
|
232
|
+
metadata:
|
|
233
|
+
annotations:
|
|
234
|
+
buildTimestamp: "${buildTimestamp}"
|
|
235
|
+
{{- if .Values.watcher.podAnnotations }}
|
|
236
|
+
{{- toYaml .Values.watcher.podAnnotations | nindent 8 }}
|
|
237
|
+
{{- end }}
|
|
238
|
+
labels:
|
|
239
|
+
app: {{ .Values.uuid }}-watcher
|
|
240
|
+
pepr.dev/controller: watcher
|
|
241
|
+
spec:
|
|
242
|
+
terminationGracePeriodSeconds: {{ .Values.watcher.terminationGracePeriodSeconds }}
|
|
243
|
+
serviceAccountName: {{ .Values.uuid }}
|
|
244
|
+
securityContext:
|
|
245
|
+
{{- toYaml .Values.admission.securityContext | nindent 8 }}
|
|
246
|
+
containers:
|
|
247
|
+
- name: watcher
|
|
248
|
+
image: {{ .Values.watcher.image }}
|
|
249
|
+
imagePullPolicy: IfNotPresent
|
|
250
|
+
command:
|
|
251
|
+
- node
|
|
252
|
+
- /app/node_modules/pepr/dist/controller.js
|
|
253
|
+
- {{ .Values.hash }}
|
|
254
|
+
readinessProbe:
|
|
255
|
+
{{- toYaml .Values.watcher.readinessProbe | nindent 12 }}
|
|
256
|
+
livenessProbe:
|
|
257
|
+
{{- toYaml .Values.watcher.livenessProbe | nindent 12 }}
|
|
258
|
+
ports:
|
|
259
|
+
- containerPort: 3000
|
|
260
|
+
resources:
|
|
261
|
+
{{- toYaml .Values.watcher.resources | nindent 12 }}
|
|
262
|
+
env:
|
|
263
|
+
{{- toYaml .Values.watcher.env | nindent 12 }}
|
|
264
|
+
- name: PEPR_WATCH_MODE
|
|
265
|
+
value: "true"
|
|
266
|
+
envFrom:
|
|
267
|
+
{{- toYaml .Values.watcher.envFrom | nindent 12 }}
|
|
268
|
+
securityContext:
|
|
269
|
+
{{- toYaml .Values.watcher.containerSecurityContext | nindent 12 }}
|
|
270
|
+
volumeMounts:
|
|
271
|
+
- name: tls-certs
|
|
272
|
+
mountPath: /etc/certs
|
|
273
|
+
readOnly: true
|
|
274
|
+
- name: module
|
|
275
|
+
mountPath: /app/load
|
|
276
|
+
readOnly: true
|
|
277
|
+
{{- if .Values.watcher.extraVolumeMounts }}
|
|
278
|
+
{{- toYaml .Values.watcher.extraVolumeMounts | nindent 12 }}
|
|
279
|
+
{{- end }}
|
|
280
|
+
volumes:
|
|
281
|
+
- name: tls-certs
|
|
282
|
+
secret:
|
|
283
|
+
secretName: {{ .Values.uuid }}-tls
|
|
284
|
+
- name: module
|
|
285
|
+
secret:
|
|
286
|
+
secretName: {{ .Values.uuid }}-module
|
|
287
|
+
{{- if .Values.watcher.extraVolumes }}
|
|
288
|
+
{{- toYaml .Values.watcher.extraVolumes | nindent 8 }}
|
|
289
|
+
{{- end }}
|
|
290
|
+
`;
|
|
291
|
+
}
|
|
292
|
+
function admissionDeployTemplate(buildTimestamp) {
|
|
293
|
+
return `
|
|
294
|
+
apiVersion: apps/v1
|
|
295
|
+
kind: Deployment
|
|
296
|
+
metadata:
|
|
297
|
+
name: {{ .Values.uuid }}
|
|
298
|
+
namespace: pepr-system
|
|
299
|
+
annotations:
|
|
300
|
+
{{- toYaml .Values.admission.annotations | nindent 4 }}
|
|
301
|
+
labels:
|
|
302
|
+
{{- toYaml .Values.admission.labels | nindent 4 }}
|
|
303
|
+
spec:
|
|
304
|
+
replicas: 2
|
|
305
|
+
selector:
|
|
306
|
+
matchLabels:
|
|
307
|
+
app: {{ .Values.uuid }}
|
|
308
|
+
pepr.dev/controller: admission
|
|
309
|
+
template:
|
|
310
|
+
metadata:
|
|
311
|
+
annotations:
|
|
312
|
+
buildTimestamp: "${buildTimestamp}"
|
|
313
|
+
{{- if .Values.admission.podAnnotations }}
|
|
314
|
+
{{- toYaml .Values.admission.podAnnotations | nindent 8 }}
|
|
315
|
+
{{- end }}
|
|
316
|
+
labels:
|
|
317
|
+
app: {{ .Values.uuid }}
|
|
318
|
+
pepr.dev/controller: admission
|
|
319
|
+
spec:
|
|
320
|
+
terminationGracePeriodSeconds: {{ .Values.admission.terminationGracePeriodSeconds }}
|
|
321
|
+
priorityClassName: system-node-critical
|
|
322
|
+
serviceAccountName: {{ .Values.uuid }}
|
|
323
|
+
securityContext:
|
|
324
|
+
{{- toYaml .Values.admission.securityContext | nindent 8 }}
|
|
325
|
+
containers:
|
|
326
|
+
- name: server
|
|
327
|
+
image: {{ .Values.admission.image }}
|
|
328
|
+
imagePullPolicy: IfNotPresent
|
|
329
|
+
command:
|
|
330
|
+
- node
|
|
331
|
+
- /app/node_modules/pepr/dist/controller.js
|
|
332
|
+
- {{ .Values.hash }}
|
|
333
|
+
readinessProbe:
|
|
334
|
+
{{- toYaml .Values.admission.readinessProbe | nindent 12 }}
|
|
335
|
+
livenessProbe:
|
|
336
|
+
{{- toYaml .Values.admission.livenessProbe | nindent 12 }}
|
|
337
|
+
ports:
|
|
338
|
+
- containerPort: 3000
|
|
339
|
+
resources:
|
|
340
|
+
{{- toYaml .Values.admission.resources | nindent 12 }}
|
|
341
|
+
env:
|
|
342
|
+
{{- toYaml .Values.admission.env | nindent 12 }}
|
|
343
|
+
- name: PEPR_WATCH_MODE
|
|
344
|
+
value: "false"
|
|
345
|
+
envFrom:
|
|
346
|
+
{{- toYaml .Values.admission.envFrom | nindent 12 }}
|
|
347
|
+
securityContext:
|
|
348
|
+
{{- toYaml .Values.admission.containerSecurityContext | nindent 12 }}
|
|
349
|
+
volumeMounts:
|
|
350
|
+
- name: tls-certs
|
|
351
|
+
mountPath: /etc/certs
|
|
352
|
+
readOnly: true
|
|
353
|
+
- name: api-token
|
|
354
|
+
mountPath: /app/api-token
|
|
355
|
+
readOnly: true
|
|
356
|
+
- name: module
|
|
357
|
+
mountPath: /app/load
|
|
358
|
+
readOnly: true
|
|
359
|
+
{{- if .Values.admission.extraVolumeMounts }}
|
|
360
|
+
{{- toYaml .Values.admission.extraVolumeMounts | nindent 12 }}
|
|
361
|
+
{{- end }}
|
|
362
|
+
volumes:
|
|
363
|
+
- name: tls-certs
|
|
364
|
+
secret:
|
|
365
|
+
secretName: {{ .Values.uuid }}-tls
|
|
366
|
+
- name: api-token
|
|
367
|
+
secret:
|
|
368
|
+
secretName: {{ .Values.uuid }}-api-token
|
|
369
|
+
- name: module
|
|
370
|
+
secret:
|
|
371
|
+
secretName: {{ .Values.uuid }}-module
|
|
372
|
+
{{- if .Values.admission.extraVolumes }}
|
|
373
|
+
{{- toYaml .Values.admission.extraVolumes | nindent 8 }}
|
|
374
|
+
{{- end }}
|
|
375
|
+
`;
|
|
376
|
+
}
|
|
377
|
+
function serviceMonitorTemplate(name2) {
|
|
378
|
+
return `
|
|
379
|
+
{{- if .Values.${name2}.serviceMonitor.enabled }}
|
|
380
|
+
apiVersion: monitoring.coreos.com/v1
|
|
381
|
+
kind: ServiceMonitor
|
|
382
|
+
metadata:
|
|
383
|
+
name: ${name2}
|
|
384
|
+
annotations:
|
|
385
|
+
{{- toYaml .Values.${name2}.serviceMonitor.annotations | nindent 4 }}
|
|
386
|
+
labels:
|
|
387
|
+
{{- toYaml .Values.${name2}.serviceMonitor.labels | nindent 4 }}
|
|
388
|
+
spec:
|
|
389
|
+
selector:
|
|
390
|
+
matchLabels:
|
|
391
|
+
pepr.dev/controller: ${name2}
|
|
392
|
+
namespaceSelector:
|
|
393
|
+
matchNames:
|
|
394
|
+
- pepr-system
|
|
395
|
+
endpoints:
|
|
396
|
+
- targetPort: 3000
|
|
397
|
+
scheme: https
|
|
398
|
+
tlsConfig:
|
|
399
|
+
insecureSkipVerify: true
|
|
400
|
+
{{- end }}
|
|
401
|
+
`;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/lib/filesystemService.ts
|
|
405
|
+
var import_fs = require("fs");
|
|
406
|
+
async function createDirectoryIfNotExists(path) {
|
|
407
|
+
try {
|
|
408
|
+
await import_fs.promises.access(path);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
if (error.code === "ENOENT") {
|
|
411
|
+
await import_fs.promises.mkdir(path, { recursive: true });
|
|
412
|
+
} else {
|
|
413
|
+
throw error;
|
|
577
414
|
}
|
|
578
415
|
}
|
|
579
416
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
var
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
throw new Error("Value must be an integer.");
|
|
594
|
-
} else if (parsedValue < 1 || parsedValue > 30) {
|
|
595
|
-
throw new Error("Number must be between 1 and 30.");
|
|
417
|
+
|
|
418
|
+
// src/lib/assets/deploy.ts
|
|
419
|
+
var import_crypto = __toESM(require("crypto"));
|
|
420
|
+
var import_fs2 = require("fs");
|
|
421
|
+
var import_kubernetes_fluent_client3 = require("kubernetes-fluent-client");
|
|
422
|
+
|
|
423
|
+
// src/lib/telemetry/logger.ts
|
|
424
|
+
var import_pino = require("pino");
|
|
425
|
+
var isPrettyLog = true;
|
|
426
|
+
var pretty = {
|
|
427
|
+
target: "pino-pretty",
|
|
428
|
+
options: {
|
|
429
|
+
colorize: true
|
|
596
430
|
}
|
|
597
|
-
return parsedValue;
|
|
598
431
|
};
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
432
|
+
var transport = isPrettyLog ? pretty : void 0;
|
|
433
|
+
var pinoTimeFunction = process.env.PINO_TIME_STAMP === "iso" ? () => import_pino.stdTimeFunctions.isoTime() : () => import_pino.stdTimeFunctions.epochTime();
|
|
434
|
+
var Log = (0, import_pino.pino)({
|
|
435
|
+
transport,
|
|
436
|
+
timestamp: pinoTimeFunction
|
|
437
|
+
});
|
|
438
|
+
if (process.env.LOG_LEVEL) {
|
|
439
|
+
Log.level = process.env.LOG_LEVEL;
|
|
440
|
+
}
|
|
441
|
+
var logger_default = Log;
|
|
442
|
+
|
|
443
|
+
// src/lib/assets/networking.ts
|
|
444
|
+
function apiTokenSecret(name2, apiToken) {
|
|
445
|
+
return {
|
|
446
|
+
apiVersion: "v1",
|
|
447
|
+
kind: "Secret",
|
|
448
|
+
metadata: {
|
|
449
|
+
name: `${name2}-api-token`,
|
|
450
|
+
namespace: "pepr-system"
|
|
451
|
+
},
|
|
452
|
+
type: "Opaque",
|
|
453
|
+
data: {
|
|
454
|
+
value: Buffer.from(apiToken).toString("base64")
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
function tlsSecret(name2, tls) {
|
|
459
|
+
return {
|
|
460
|
+
apiVersion: "v1",
|
|
461
|
+
kind: "Secret",
|
|
462
|
+
metadata: {
|
|
463
|
+
name: `${name2}-tls`,
|
|
464
|
+
namespace: "pepr-system"
|
|
465
|
+
},
|
|
466
|
+
type: "kubernetes.io/tls",
|
|
467
|
+
data: {
|
|
468
|
+
"tls.crt": tls.crt,
|
|
469
|
+
"tls.key": tls.key
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
function service(name2) {
|
|
474
|
+
return {
|
|
475
|
+
apiVersion: "v1",
|
|
476
|
+
kind: "Service",
|
|
477
|
+
metadata: {
|
|
478
|
+
name: name2,
|
|
479
|
+
namespace: "pepr-system",
|
|
480
|
+
labels: {
|
|
481
|
+
"pepr.dev/controller": "admission"
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
spec: {
|
|
485
|
+
selector: {
|
|
486
|
+
app: name2,
|
|
487
|
+
"pepr.dev/controller": "admission"
|
|
488
|
+
},
|
|
489
|
+
ports: [
|
|
490
|
+
{
|
|
491
|
+
port: 443,
|
|
492
|
+
targetPort: 3e3
|
|
493
|
+
}
|
|
494
|
+
]
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function watcherService(name2) {
|
|
499
|
+
return {
|
|
500
|
+
apiVersion: "v1",
|
|
501
|
+
kind: "Service",
|
|
502
|
+
metadata: {
|
|
503
|
+
name: `${name2}-watcher`,
|
|
504
|
+
namespace: "pepr-system",
|
|
505
|
+
labels: {
|
|
506
|
+
"pepr.dev/controller": "watcher"
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
spec: {
|
|
510
|
+
selector: {
|
|
511
|
+
app: `${name2}-watcher`,
|
|
512
|
+
"pepr.dev/controller": "watcher"
|
|
513
|
+
},
|
|
514
|
+
ports: [
|
|
515
|
+
{
|
|
516
|
+
port: 443,
|
|
517
|
+
targetPort: 3e3
|
|
518
|
+
}
|
|
519
|
+
]
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// src/lib/assets/pods.ts
|
|
525
|
+
var import_zlib = require("zlib");
|
|
526
|
+
|
|
527
|
+
// src/sdk/sdk.ts
|
|
528
|
+
var import_kubernetes_fluent_client = require("kubernetes-fluent-client");
|
|
529
|
+
function sanitizeResourceName(name2) {
|
|
530
|
+
return name2.toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 250).replace(/^[^a-z]+|[^a-z]+$/g, "");
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// src/lib/helpers.ts
|
|
534
|
+
function matchesRegex(pattern, testString) {
|
|
535
|
+
return new RegExp(pattern).test(testString);
|
|
536
|
+
}
|
|
537
|
+
var ValidationError = class extends Error {
|
|
538
|
+
};
|
|
539
|
+
function validateCapabilityNames(capabilities) {
|
|
540
|
+
if (capabilities && capabilities.length > 0) {
|
|
541
|
+
for (let i = 0; i < capabilities.length; i++) {
|
|
542
|
+
if (capabilities[i].name !== sanitizeResourceName(capabilities[i].name)) {
|
|
543
|
+
throw new ValidationError(`Capability name is not a valid Kubernetes resource name: ${capabilities[i].name}`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
function createRBACMap(capabilities) {
|
|
549
|
+
return capabilities.reduce((acc, capability) => {
|
|
550
|
+
capability.bindings.forEach((binding) => {
|
|
551
|
+
const key = `${binding.kind.group}/${binding.kind.version}/${binding.kind.kind}`;
|
|
552
|
+
acc["pepr.dev/v1/peprstore"] = {
|
|
553
|
+
verbs: ["create", "get", "patch", "watch"],
|
|
554
|
+
plural: "peprstores"
|
|
555
|
+
};
|
|
556
|
+
acc["apiextensions.k8s.io/v1/customresourcedefinition"] = {
|
|
557
|
+
verbs: ["patch", "create"],
|
|
558
|
+
plural: "customresourcedefinitions"
|
|
559
|
+
};
|
|
560
|
+
if (!acc[key] && binding.isWatch) {
|
|
561
|
+
acc[key] = {
|
|
562
|
+
verbs: ["watch"],
|
|
563
|
+
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
if (binding.isFinalize) {
|
|
567
|
+
acc[key] = {
|
|
568
|
+
verbs: ["patch"],
|
|
569
|
+
plural: binding.kind.plural || `${binding.kind.kind.toLowerCase()}s`
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
return acc;
|
|
574
|
+
}, {});
|
|
575
|
+
}
|
|
576
|
+
function hasEveryOverlap(array1, array2) {
|
|
577
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
return array1.every((element) => array2.includes(element));
|
|
581
|
+
}
|
|
582
|
+
function hasAnyOverlap(array1, array2) {
|
|
583
|
+
if (!Array.isArray(array1) || !Array.isArray(array2)) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
return array1.some((element) => array2.includes(element));
|
|
587
|
+
}
|
|
588
|
+
function ignoredNamespaceConflict(ignoreNamespaces, bindingNamespaces) {
|
|
589
|
+
return hasAnyOverlap(bindingNamespaces, ignoreNamespaces);
|
|
590
|
+
}
|
|
591
|
+
function bindingAndCapabilityNSConflict(bindingNamespaces, capabilityNamespaces) {
|
|
592
|
+
if (!capabilityNamespaces) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
return capabilityNamespaces.length !== 0 && !hasEveryOverlap(bindingNamespaces, capabilityNamespaces);
|
|
596
|
+
}
|
|
597
|
+
function generateWatchNamespaceError(ignoredNamespaces, bindingNamespaces, capabilityNamespaces) {
|
|
598
|
+
let err = "";
|
|
599
|
+
if (ignoredNamespaceConflict(ignoredNamespaces, bindingNamespaces)) {
|
|
600
|
+
err += `Binding uses a Pepr ignored namespace: ignoredNamespaces: [${ignoredNamespaces.join(
|
|
601
|
+
", "
|
|
602
|
+
)}] bindingNamespaces: [${bindingNamespaces.join(", ")}].`;
|
|
603
|
+
}
|
|
604
|
+
if (bindingAndCapabilityNSConflict(bindingNamespaces, capabilityNamespaces)) {
|
|
605
|
+
err += `Binding uses namespace not governed by capability: bindingNamespaces: [${bindingNamespaces.join(
|
|
606
|
+
", "
|
|
607
|
+
)}] capabilityNamespaces: [${capabilityNamespaces.join(", ")}].`;
|
|
608
|
+
}
|
|
609
|
+
return err.replace(/\.([^ ])/g, ". $1");
|
|
610
|
+
}
|
|
611
|
+
function namespaceComplianceValidator(capability, ignoredNamespaces) {
|
|
612
|
+
const { namespaces: capabilityNamespaces, bindings, name: name2 } = capability;
|
|
613
|
+
const bindingNamespaces = bindings.flatMap((binding) => binding.filters.namespaces);
|
|
614
|
+
const bindingRegexNamespaces = bindings.flatMap(
|
|
615
|
+
(binding) => binding.filters.regexNamespaces || []
|
|
616
|
+
);
|
|
617
|
+
const namespaceError = generateWatchNamespaceError(
|
|
618
|
+
ignoredNamespaces ? ignoredNamespaces : [],
|
|
619
|
+
bindingNamespaces,
|
|
620
|
+
capabilityNamespaces ? capabilityNamespaces : []
|
|
621
|
+
);
|
|
622
|
+
if (namespaceError !== "") {
|
|
623
|
+
throw new Error(
|
|
624
|
+
`Error in ${name2} capability. A binding violates namespace rules. Please check ignoredNamespaces and capability namespaces: ${namespaceError}`
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
matchRegexToCapababilityNamespace(bindingRegexNamespaces, capabilityNamespaces);
|
|
628
|
+
checkRegexNamespaces(bindingRegexNamespaces, ignoredNamespaces);
|
|
629
|
+
}
|
|
630
|
+
var matchRegexToCapababilityNamespace = (bindingRegexNamespaces, capabilityNamespaces) => {
|
|
631
|
+
if (bindingRegexNamespaces.length > 0 && capabilityNamespaces && capabilityNamespaces.length > 0) {
|
|
632
|
+
for (const regexNamespace of bindingRegexNamespaces) {
|
|
633
|
+
let matches = false;
|
|
634
|
+
matches = regexNamespace !== "" && capabilityNamespaces.some((capabilityNamespace) => matchesRegex(regexNamespace, capabilityNamespace));
|
|
635
|
+
if (!matches) {
|
|
636
|
+
throw new Error(
|
|
637
|
+
`Ignoring Watch Callback: Object namespace does not match any capability namespace with regex ${regexNamespace}.`
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
var checkRegexNamespaces = (bindingRegexNamespaces, ignoredNamespaces) => {
|
|
644
|
+
if (bindingRegexNamespaces.length > 0 && ignoredNamespaces && ignoredNamespaces.length > 0) {
|
|
645
|
+
for (const regexNamespace of bindingRegexNamespaces) {
|
|
646
|
+
const matchedNS = ignoredNamespaces.find((ignoredNS) => matchesRegex(regexNamespace, ignoredNS));
|
|
647
|
+
if (matchedNS) {
|
|
648
|
+
throw new Error(
|
|
649
|
+
`Ignoring Watch Callback: Regex namespace: ${regexNamespace}, is an ignored namespace: ${matchedNS}.`
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
function secretOverLimit(str) {
|
|
656
|
+
const encoder = new TextEncoder();
|
|
657
|
+
const encoded = encoder.encode(str);
|
|
658
|
+
const sizeInBytes = encoded.length;
|
|
659
|
+
const oneMiBInBytes = 1048576;
|
|
660
|
+
return sizeInBytes > oneMiBInBytes;
|
|
661
|
+
}
|
|
662
|
+
var parseTimeout = (value) => {
|
|
663
|
+
const parsedValue = parseInt(value, 10);
|
|
664
|
+
const floatValue = parseFloat(value);
|
|
665
|
+
if (isNaN(parsedValue)) {
|
|
666
|
+
throw new Error("Not a number.");
|
|
667
|
+
} else if (parsedValue !== floatValue) {
|
|
668
|
+
throw new Error("Value must be an integer.");
|
|
669
|
+
} else if (parsedValue < 1 || parsedValue > 30) {
|
|
670
|
+
throw new Error("Number must be between 1 and 30.");
|
|
671
|
+
}
|
|
672
|
+
return parsedValue;
|
|
673
|
+
};
|
|
674
|
+
function dedent(file) {
|
|
675
|
+
const lines = file.split("\n");
|
|
676
|
+
if (lines[0].trim() === "") {
|
|
602
677
|
lines.shift();
|
|
603
678
|
file = lines.join("\n");
|
|
604
679
|
}
|
|
@@ -1118,51 +1193,35 @@ var peprStoreCRD = {
|
|
|
1118
1193
|
};
|
|
1119
1194
|
|
|
1120
1195
|
// src/lib/assets/webhooks.ts
|
|
1121
|
-
var
|
|
1122
|
-
var peprIgnoreLabel = {
|
|
1123
|
-
key: "pepr.dev",
|
|
1124
|
-
operator: "NotIn",
|
|
1125
|
-
values: ["ignore"]
|
|
1126
|
-
};
|
|
1196
|
+
var import_ramda = require("ramda");
|
|
1127
1197
|
var peprIgnoreNamespaces = ["kube-system", "pepr-system"];
|
|
1198
|
+
var validateRule = (binding, isMutateWebhook) => {
|
|
1199
|
+
const { event, kind: kind8, isMutate, isValidate } = binding;
|
|
1200
|
+
if (isMutateWebhook && !isMutate || !isMutateWebhook && !isValidate) {
|
|
1201
|
+
return void 0;
|
|
1202
|
+
}
|
|
1203
|
+
const operations = event === "CREATEORUPDATE" /* CREATE_OR_UPDATE */ ? ["CREATE" /* CREATE */, "UPDATE" /* UPDATE */] : [event];
|
|
1204
|
+
const resource = kind8.plural || `${kind8.kind.toLowerCase()}s`;
|
|
1205
|
+
const ruleObject = {
|
|
1206
|
+
apiGroups: [kind8.group],
|
|
1207
|
+
apiVersions: [kind8.version || "*"],
|
|
1208
|
+
operations,
|
|
1209
|
+
resources: [resource, ...resource === "pods" ? ["pods/ephemeralcontainers"] : []]
|
|
1210
|
+
};
|
|
1211
|
+
return ruleObject;
|
|
1212
|
+
};
|
|
1128
1213
|
async function generateWebhookRules(assets, isMutateWebhook) {
|
|
1129
1214
|
const { config, capabilities } = assets;
|
|
1130
|
-
const rules =
|
|
1131
|
-
for (const capability of capabilities) {
|
|
1215
|
+
const rules = capabilities.flatMap((capability) => {
|
|
1132
1216
|
console.info(`Module ${config.uuid} has capability: ${capability.name}`);
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
continue;
|
|
1137
|
-
}
|
|
1138
|
-
if (!isMutateWebhook && !isValidate) {
|
|
1139
|
-
continue;
|
|
1140
|
-
}
|
|
1141
|
-
const operations = [];
|
|
1142
|
-
if (event === "CREATEORUPDATE" /* CREATE_OR_UPDATE */) {
|
|
1143
|
-
operations.push("CREATE" /* CREATE */, "UPDATE" /* UPDATE */);
|
|
1144
|
-
} else {
|
|
1145
|
-
operations.push(event);
|
|
1146
|
-
}
|
|
1147
|
-
const resource = kind8.plural || `${kind8.kind.toLowerCase()}s`;
|
|
1148
|
-
const ruleObject = {
|
|
1149
|
-
apiGroups: [kind8.group],
|
|
1150
|
-
apiVersions: [kind8.version || "*"],
|
|
1151
|
-
operations,
|
|
1152
|
-
resources: [resource]
|
|
1153
|
-
};
|
|
1154
|
-
if (resource === "pods") {
|
|
1155
|
-
ruleObject.resources.push("pods/ephemeralcontainers");
|
|
1156
|
-
}
|
|
1157
|
-
rules.push(ruleObject);
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
return (0, import_ramda2.uniqWith)(import_ramda2.equals, rules);
|
|
1217
|
+
return capability.bindings.map((binding) => validateRule(binding, isMutateWebhook)).filter((rule) => !!rule);
|
|
1218
|
+
});
|
|
1219
|
+
return (0, import_ramda.uniqWith)(import_ramda.equals, rules);
|
|
1161
1220
|
}
|
|
1162
1221
|
async function webhookConfig(assets, mutateOrValidate, timeoutSeconds = 10) {
|
|
1163
|
-
const ignore = [
|
|
1222
|
+
const ignore = [];
|
|
1164
1223
|
const { name: name2, tls, config, apiToken, host } = assets;
|
|
1165
|
-
const ignoreNS = (0,
|
|
1224
|
+
const ignoreNS = (0, import_ramda.concat)(peprIgnoreNamespaces, config?.alwaysIgnore?.namespaces || []);
|
|
1166
1225
|
if (ignoreNS) {
|
|
1167
1226
|
ignore.push({
|
|
1168
1227
|
key: "kubernetes.io/metadata.name",
|
|
@@ -1203,9 +1262,6 @@ async function webhookConfig(assets, mutateOrValidate, timeoutSeconds = 10) {
|
|
|
1203
1262
|
namespaceSelector: {
|
|
1204
1263
|
matchExpressions: ignore
|
|
1205
1264
|
},
|
|
1206
|
-
objectSelector: {
|
|
1207
|
-
matchExpressions: ignore
|
|
1208
|
-
},
|
|
1209
1265
|
rules,
|
|
1210
1266
|
// @todo: track side effects state
|
|
1211
1267
|
sideEffects: "None"
|
|
@@ -1252,666 +1308,396 @@ async function deploy(assets, force, webhookTimeout) {
|
|
|
1252
1308
|
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.MutatingWebhookConfiguration).Apply(mutateWebhook, { force });
|
|
1253
1309
|
} else {
|
|
1254
1310
|
logger_default.info("Mutating webhook not needed, removing if it exists");
|
|
1255
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.MutatingWebhookConfiguration).Delete(name2);
|
|
1256
|
-
}
|
|
1257
|
-
const validateWebhook = await webhookConfig(assets, "validate", webhookTimeout);
|
|
1258
|
-
if (validateWebhook) {
|
|
1259
|
-
logger_default.info("Applying validating webhook");
|
|
1260
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ValidatingWebhookConfiguration).Apply(validateWebhook, { force });
|
|
1261
|
-
} else {
|
|
1262
|
-
logger_default.info("Validating webhook not needed, removing if it exists");
|
|
1263
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ValidatingWebhookConfiguration).Delete(name2);
|
|
1264
|
-
}
|
|
1265
|
-
logger_default.info("Applying the Pepr Store CRD if it doesn't exist");
|
|
1266
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.CustomResourceDefinition).Apply(peprStoreCRD, { force });
|
|
1267
|
-
if (host) {
|
|
1268
|
-
return;
|
|
1269
|
-
}
|
|
1270
|
-
const code = await
|
|
1271
|
-
const hash = import_crypto.default.createHash("sha256").update(code).digest("hex");
|
|
1272
|
-
if (code.length < 1) {
|
|
1273
|
-
throw new Error("No code provided");
|
|
1274
|
-
}
|
|
1275
|
-
await setupRBAC(name2, assets.capabilities, force, assets.config);
|
|
1276
|
-
await setupController(assets, code, hash, force);
|
|
1277
|
-
await setupWatcher(assets, hash, force);
|
|
1278
|
-
}
|
|
1279
|
-
async function setupRBAC(name2, capabilities, force, config) {
|
|
1280
|
-
const { rbacMode, rbac } = config;
|
|
1281
|
-
logger_default.info("Applying cluster role binding");
|
|
1282
|
-
const crb = clusterRoleBinding(name2);
|
|
1283
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ClusterRoleBinding).Apply(crb, { force });
|
|
1284
|
-
logger_default.info("Applying cluster role");
|
|
1285
|
-
const cr = clusterRole(name2, capabilities, rbacMode, rbac);
|
|
1286
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ClusterRole).Apply(cr, { force });
|
|
1287
|
-
logger_default.info("Applying service account");
|
|
1288
|
-
const sa = serviceAccount(name2);
|
|
1289
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ServiceAccount).Apply(sa, { force });
|
|
1290
|
-
logger_default.info("Applying store role");
|
|
1291
|
-
const role = storeRole(name2);
|
|
1292
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Role).Apply(role, { force });
|
|
1293
|
-
logger_default.info("Applying store role binding");
|
|
1294
|
-
const roleBinding = storeRoleBinding(name2);
|
|
1295
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.RoleBinding).Apply(roleBinding, { force });
|
|
1296
|
-
}
|
|
1297
|
-
async function setupController(assets, code, hash, force) {
|
|
1298
|
-
const { name: name2 } = assets;
|
|
1299
|
-
logger_default.info("Applying module secret");
|
|
1300
|
-
const mod = getModuleSecret(name2, code, hash);
|
|
1301
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(mod, { force });
|
|
1302
|
-
logger_default.info("Applying controller service");
|
|
1303
|
-
const svc = service(name2);
|
|
1304
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Service).Apply(svc, { force });
|
|
1305
|
-
logger_default.info("Applying TLS secret");
|
|
1306
|
-
const tls = tlsSecret(name2, assets.tls);
|
|
1307
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(tls, { force });
|
|
1308
|
-
logger_default.info("Applying API token secret");
|
|
1309
|
-
const apiToken = apiTokenSecret(name2, assets.apiToken);
|
|
1310
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(apiToken, { force });
|
|
1311
|
-
logger_default.info("Applying deployment");
|
|
1312
|
-
const dep = getDeployment(assets, hash, assets.buildTimestamp);
|
|
1313
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(dep, { force });
|
|
1314
|
-
}
|
|
1315
|
-
async function setupWatcher(assets, hash, force) {
|
|
1316
|
-
const watchDeployment = getWatcher(assets, hash, assets.buildTimestamp);
|
|
1317
|
-
if (watchDeployment) {
|
|
1318
|
-
logger_default.info("Applying watcher deployment");
|
|
1319
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(watchDeployment, { force });
|
|
1320
|
-
logger_default.info("Applying watcher service");
|
|
1321
|
-
const watchSvc = watcherService(assets.name);
|
|
1322
|
-
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Service).Apply(watchSvc, { force });
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
// src/lib/assets/loader.ts
|
|
1327
|
-
var import_child_process = require("child_process");
|
|
1328
|
-
function loadCapabilities(path) {
|
|
1329
|
-
return new Promise((resolve6, reject) => {
|
|
1330
|
-
const program2 = (0, import_child_process.fork)(path, {
|
|
1331
|
-
env: {
|
|
1332
|
-
...process.env,
|
|
1333
|
-
LOG_LEVEL: "warn",
|
|
1334
|
-
PEPR_MODE: "build",
|
|
1335
|
-
NODE_OPTIONS: "--disable-warning=DEP0040"
|
|
1336
|
-
}
|
|
1337
|
-
});
|
|
1338
|
-
program2.on("message", (message) => {
|
|
1339
|
-
const capabilities = message.valueOf();
|
|
1340
|
-
for (const capability of capabilities) {
|
|
1341
|
-
console.info(`Registered Pepr Capability "${capability.name}"`);
|
|
1342
|
-
}
|
|
1343
|
-
resolve6(capabilities);
|
|
1344
|
-
});
|
|
1345
|
-
program2.on("error", (error) => {
|
|
1346
|
-
reject(error);
|
|
1347
|
-
});
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
// src/lib/assets/yaml.ts
|
|
1352
|
-
var import_client_node = require("@kubernetes/client-node");
|
|
1353
|
-
var import_crypto2 = __toESM(require("crypto"));
|
|
1354
|
-
var import_fs2 = require("fs");
|
|
1355
|
-
async function overridesFile({ hash, name: name2, image, config, apiToken, capabilities }, path) {
|
|
1356
|
-
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
1357
|
-
const overrides = {
|
|
1358
|
-
rbac: rbacOverrides,
|
|
1359
|
-
secrets: {
|
|
1360
|
-
apiToken: Buffer.from(apiToken).toString("base64")
|
|
1361
|
-
},
|
|
1362
|
-
hash,
|
|
1363
|
-
namespace: {
|
|
1364
|
-
annotations: {},
|
|
1365
|
-
labels: {
|
|
1366
|
-
"pepr.dev": ""
|
|
1367
|
-
}
|
|
1368
|
-
},
|
|
1369
|
-
uuid: name2,
|
|
1370
|
-
admission: {
|
|
1371
|
-
terminationGracePeriodSeconds: 5,
|
|
1372
|
-
failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
|
|
1373
|
-
webhookTimeout: config.webhookTimeout,
|
|
1374
|
-
env: genEnv(config, false, true),
|
|
1375
|
-
envFrom: [],
|
|
1376
|
-
image,
|
|
1377
|
-
annotations: {
|
|
1378
|
-
"pepr.dev/description": `${config.description}` || ""
|
|
1379
|
-
},
|
|
1380
|
-
labels: {
|
|
1381
|
-
app: name2,
|
|
1382
|
-
"pepr.dev/controller": "admission",
|
|
1383
|
-
"pepr.dev/uuid": config.uuid
|
|
1384
|
-
},
|
|
1385
|
-
securityContext: {
|
|
1386
|
-
runAsUser: 65532,
|
|
1387
|
-
runAsGroup: 65532,
|
|
1388
|
-
runAsNonRoot: true,
|
|
1389
|
-
fsGroup: 65532
|
|
1390
|
-
},
|
|
1391
|
-
readinessProbe: {
|
|
1392
|
-
httpGet: {
|
|
1393
|
-
path: "/healthz",
|
|
1394
|
-
port: 3e3,
|
|
1395
|
-
scheme: "HTTPS"
|
|
1396
|
-
},
|
|
1397
|
-
initialDelaySeconds: 10
|
|
1398
|
-
},
|
|
1399
|
-
livenessProbe: {
|
|
1400
|
-
httpGet: {
|
|
1401
|
-
path: "/healthz",
|
|
1402
|
-
port: 3e3,
|
|
1403
|
-
scheme: "HTTPS"
|
|
1404
|
-
},
|
|
1405
|
-
initialDelaySeconds: 10
|
|
1406
|
-
},
|
|
1407
|
-
resources: {
|
|
1408
|
-
requests: {
|
|
1409
|
-
memory: "256Mi",
|
|
1410
|
-
cpu: "200m"
|
|
1411
|
-
},
|
|
1412
|
-
limits: {
|
|
1413
|
-
memory: "512Mi",
|
|
1414
|
-
cpu: "500m"
|
|
1415
|
-
}
|
|
1416
|
-
},
|
|
1417
|
-
containerSecurityContext: {
|
|
1418
|
-
runAsUser: 65532,
|
|
1419
|
-
runAsGroup: 65532,
|
|
1420
|
-
runAsNonRoot: true,
|
|
1421
|
-
allowPrivilegeEscalation: false,
|
|
1422
|
-
capabilities: {
|
|
1423
|
-
drop: ["ALL"]
|
|
1424
|
-
}
|
|
1425
|
-
},
|
|
1426
|
-
podAnnotations: {},
|
|
1427
|
-
nodeSelector: {},
|
|
1428
|
-
tolerations: [],
|
|
1429
|
-
extraVolumeMounts: [],
|
|
1430
|
-
extraVolumes: [],
|
|
1431
|
-
affinity: {},
|
|
1432
|
-
serviceMonitor: {
|
|
1433
|
-
enabled: false,
|
|
1434
|
-
labels: {},
|
|
1435
|
-
annotations: {}
|
|
1436
|
-
}
|
|
1437
|
-
},
|
|
1438
|
-
watcher: {
|
|
1439
|
-
terminationGracePeriodSeconds: 5,
|
|
1440
|
-
env: genEnv(config, true, true),
|
|
1441
|
-
envFrom: [],
|
|
1442
|
-
image,
|
|
1443
|
-
annotations: {
|
|
1444
|
-
"pepr.dev/description": `${config.description}` || ""
|
|
1445
|
-
},
|
|
1446
|
-
labels: {
|
|
1447
|
-
app: `${name2}-watcher`,
|
|
1448
|
-
"pepr.dev/controller": "watcher",
|
|
1449
|
-
"pepr.dev/uuid": config.uuid
|
|
1450
|
-
},
|
|
1451
|
-
securityContext: {
|
|
1452
|
-
runAsUser: 65532,
|
|
1453
|
-
runAsGroup: 65532,
|
|
1454
|
-
runAsNonRoot: true,
|
|
1455
|
-
fsGroup: 65532
|
|
1456
|
-
},
|
|
1457
|
-
readinessProbe: {
|
|
1458
|
-
httpGet: {
|
|
1459
|
-
path: "/healthz",
|
|
1460
|
-
port: 3e3,
|
|
1461
|
-
scheme: "HTTPS"
|
|
1462
|
-
},
|
|
1463
|
-
initialDelaySeconds: 10
|
|
1464
|
-
},
|
|
1465
|
-
livenessProbe: {
|
|
1466
|
-
httpGet: {
|
|
1467
|
-
path: "/healthz",
|
|
1468
|
-
port: 3e3,
|
|
1469
|
-
scheme: "HTTPS"
|
|
1470
|
-
},
|
|
1471
|
-
initialDelaySeconds: 10
|
|
1472
|
-
},
|
|
1473
|
-
resources: {
|
|
1474
|
-
requests: {
|
|
1475
|
-
memory: "256Mi",
|
|
1476
|
-
cpu: "200m"
|
|
1477
|
-
},
|
|
1478
|
-
limits: {
|
|
1479
|
-
memory: "512Mi",
|
|
1480
|
-
cpu: "500m"
|
|
1481
|
-
}
|
|
1482
|
-
},
|
|
1483
|
-
containerSecurityContext: {
|
|
1484
|
-
runAsUser: 65532,
|
|
1485
|
-
runAsGroup: 65532,
|
|
1486
|
-
runAsNonRoot: true,
|
|
1487
|
-
allowPrivilegeEscalation: false,
|
|
1488
|
-
capabilities: {
|
|
1489
|
-
drop: ["ALL"]
|
|
1490
|
-
}
|
|
1491
|
-
},
|
|
1492
|
-
nodeSelector: {},
|
|
1493
|
-
tolerations: [],
|
|
1494
|
-
extraVolumeMounts: [],
|
|
1495
|
-
extraVolumes: [],
|
|
1496
|
-
affinity: {},
|
|
1497
|
-
podAnnotations: {},
|
|
1498
|
-
serviceMonitor: {
|
|
1499
|
-
enabled: false,
|
|
1500
|
-
labels: {},
|
|
1501
|
-
annotations: {}
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
};
|
|
1505
|
-
await import_fs2.promises.writeFile(path, (0, import_client_node.dumpYaml)(overrides, { noRefs: true, forceQuotes: true }));
|
|
1506
|
-
}
|
|
1507
|
-
function zarfYaml({ name: name2, image, config }, path) {
|
|
1508
|
-
const zarfCfg = {
|
|
1509
|
-
kind: "ZarfPackageConfig",
|
|
1510
|
-
metadata: {
|
|
1511
|
-
name: name2,
|
|
1512
|
-
description: `Pepr Module: ${config.description}`,
|
|
1513
|
-
url: "https://github.com/defenseunicorns/pepr",
|
|
1514
|
-
version: `${config.appVersion || "0.0.1"}`
|
|
1515
|
-
},
|
|
1516
|
-
components: [
|
|
1517
|
-
{
|
|
1518
|
-
name: "module",
|
|
1519
|
-
required: true,
|
|
1520
|
-
manifests: [
|
|
1521
|
-
{
|
|
1522
|
-
name: "module",
|
|
1523
|
-
namespace: "pepr-system",
|
|
1524
|
-
files: [path]
|
|
1525
|
-
}
|
|
1526
|
-
],
|
|
1527
|
-
images: [image]
|
|
1528
|
-
}
|
|
1529
|
-
]
|
|
1530
|
-
};
|
|
1531
|
-
return (0, import_client_node.dumpYaml)(zarfCfg, { noRefs: true });
|
|
1532
|
-
}
|
|
1533
|
-
function zarfYamlChart({ name: name2, image, config }, path) {
|
|
1534
|
-
const zarfCfg = {
|
|
1535
|
-
kind: "ZarfPackageConfig",
|
|
1536
|
-
metadata: {
|
|
1537
|
-
name: name2,
|
|
1538
|
-
description: `Pepr Module: ${config.description}`,
|
|
1539
|
-
url: "https://github.com/defenseunicorns/pepr",
|
|
1540
|
-
version: `${config.appVersion || "0.0.1"}`
|
|
1541
|
-
},
|
|
1542
|
-
components: [
|
|
1543
|
-
{
|
|
1544
|
-
name: "module",
|
|
1545
|
-
required: true,
|
|
1546
|
-
charts: [
|
|
1547
|
-
{
|
|
1548
|
-
name: "module",
|
|
1549
|
-
namespace: "pepr-system",
|
|
1550
|
-
version: `${config.appVersion || "0.0.1"}`,
|
|
1551
|
-
localPath: path
|
|
1552
|
-
}
|
|
1553
|
-
],
|
|
1554
|
-
images: [image]
|
|
1555
|
-
}
|
|
1556
|
-
]
|
|
1557
|
-
};
|
|
1558
|
-
return (0, import_client_node.dumpYaml)(zarfCfg, { noRefs: true });
|
|
1559
|
-
}
|
|
1560
|
-
async function allYaml(assets, imagePullSecret) {
|
|
1561
|
-
const { name: name2, tls, apiToken, path, config } = assets;
|
|
1562
|
-
const code = await import_fs2.promises.readFile(path);
|
|
1563
|
-
assets.hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
1564
|
-
const mutateWebhook = await webhookConfig(assets, "mutate", assets.config.webhookTimeout);
|
|
1565
|
-
const validateWebhook = await webhookConfig(assets, "validate", assets.config.webhookTimeout);
|
|
1566
|
-
const watchDeployment = getWatcher(assets, assets.hash, assets.buildTimestamp, imagePullSecret);
|
|
1567
|
-
const resources = [
|
|
1568
|
-
getNamespace(assets.config.customLabels?.namespace),
|
|
1569
|
-
clusterRole(name2, assets.capabilities, config.rbacMode, config.rbac),
|
|
1570
|
-
clusterRoleBinding(name2),
|
|
1571
|
-
serviceAccount(name2),
|
|
1572
|
-
apiTokenSecret(name2, apiToken),
|
|
1573
|
-
tlsSecret(name2, tls),
|
|
1574
|
-
getDeployment(assets, assets.hash, assets.buildTimestamp, imagePullSecret),
|
|
1575
|
-
service(name2),
|
|
1576
|
-
watcherService(name2),
|
|
1577
|
-
getModuleSecret(name2, code, assets.hash),
|
|
1578
|
-
storeRole(name2),
|
|
1579
|
-
storeRoleBinding(name2)
|
|
1580
|
-
];
|
|
1581
|
-
if (mutateWebhook) {
|
|
1582
|
-
resources.push(mutateWebhook);
|
|
1583
|
-
}
|
|
1584
|
-
if (validateWebhook) {
|
|
1585
|
-
resources.push(validateWebhook);
|
|
1586
|
-
}
|
|
1587
|
-
if (watchDeployment) {
|
|
1588
|
-
resources.push(watchDeployment);
|
|
1589
|
-
}
|
|
1590
|
-
return resources.map((r) => (0, import_client_node.dumpYaml)(r, { noRefs: true })).join("---\n");
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
// src/lib/assets/index.ts
|
|
1594
|
-
var import_path = require("path");
|
|
1595
|
-
|
|
1596
|
-
// src/lib/assets/helm.ts
|
|
1597
|
-
function clusterRoleTemplate() {
|
|
1598
|
-
return `
|
|
1599
|
-
apiVersion: rbac.authorization.k8s.io/v1
|
|
1600
|
-
kind: ClusterRole
|
|
1601
|
-
metadata:
|
|
1602
|
-
name: {{ .Values.uuid }}
|
|
1603
|
-
namespace: pepr-system
|
|
1604
|
-
rules:
|
|
1605
|
-
{{- if .Values.rbac }}
|
|
1606
|
-
{{- toYaml .Values.rbac | nindent 2 }}
|
|
1607
|
-
{{- end }}
|
|
1608
|
-
`;
|
|
1609
|
-
}
|
|
1610
|
-
function namespaceTemplate() {
|
|
1611
|
-
return `
|
|
1612
|
-
apiVersion: v1
|
|
1613
|
-
kind: Namespace
|
|
1614
|
-
metadata:
|
|
1615
|
-
name: pepr-system
|
|
1616
|
-
{{- if .Values.namespace.annotations }}
|
|
1617
|
-
annotations:
|
|
1618
|
-
{{- toYaml .Values.namespace.annotations | nindent 6 }}
|
|
1619
|
-
{{- end }}
|
|
1620
|
-
{{- if .Values.namespace.labels }}
|
|
1621
|
-
labels:
|
|
1622
|
-
{{- toYaml .Values.namespace.labels | nindent 6 }}
|
|
1623
|
-
{{- end }}
|
|
1624
|
-
`;
|
|
1625
|
-
}
|
|
1626
|
-
function chartYaml(name2, description) {
|
|
1627
|
-
return `
|
|
1628
|
-
apiVersion: v2
|
|
1629
|
-
name: ${name2}
|
|
1630
|
-
description: ${description || ""}
|
|
1631
|
-
|
|
1632
|
-
# A chart can be either an 'application' or a 'library' chart.
|
|
1633
|
-
#
|
|
1634
|
-
# Application charts are a collection of templates that can be packaged into versioned archives
|
|
1635
|
-
# to be deployed.
|
|
1636
|
-
#
|
|
1637
|
-
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
|
1638
|
-
# a dependency of application charts to inject those utilities and functions into the rendering
|
|
1639
|
-
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
|
1640
|
-
type: application
|
|
1641
|
-
|
|
1642
|
-
# This is the chart version. This version number should be incremented each time you make changes
|
|
1643
|
-
# to the chart and its templates, including the app version.
|
|
1644
|
-
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
|
1645
|
-
version: 0.1.0
|
|
1646
|
-
|
|
1647
|
-
# This is the version number of the application being deployed. This version number should be
|
|
1648
|
-
# incremented each time you make changes to the application. Versions are not expected to
|
|
1649
|
-
# follow Semantic Versioning. They should reflect the version the application is using.
|
|
1650
|
-
# It is recommended to use it with quotes.
|
|
1651
|
-
appVersion: "1.16.0"
|
|
1652
|
-
`;
|
|
1653
|
-
}
|
|
1654
|
-
function watcherDeployTemplate(buildTimestamp) {
|
|
1655
|
-
return `
|
|
1656
|
-
apiVersion: apps/v1
|
|
1657
|
-
kind: Deployment
|
|
1658
|
-
metadata:
|
|
1659
|
-
name: {{ .Values.uuid }}-watcher
|
|
1660
|
-
namespace: pepr-system
|
|
1661
|
-
annotations:
|
|
1662
|
-
{{- toYaml .Values.watcher.annotations | nindent 4 }}
|
|
1663
|
-
labels:
|
|
1664
|
-
{{- toYaml .Values.watcher.labels | nindent 4 }}
|
|
1665
|
-
spec:
|
|
1666
|
-
replicas: 1
|
|
1667
|
-
strategy:
|
|
1668
|
-
type: Recreate
|
|
1669
|
-
selector:
|
|
1670
|
-
matchLabels:
|
|
1671
|
-
app: {{ .Values.uuid }}-watcher
|
|
1672
|
-
pepr.dev/controller: watcher
|
|
1673
|
-
template:
|
|
1674
|
-
metadata:
|
|
1675
|
-
annotations:
|
|
1676
|
-
buildTimestamp: "${buildTimestamp}"
|
|
1677
|
-
{{- if .Values.watcher.podAnnotations }}
|
|
1678
|
-
{{- toYaml .Values.watcher.podAnnotations | nindent 8 }}
|
|
1679
|
-
{{- end }}
|
|
1680
|
-
labels:
|
|
1681
|
-
app: {{ .Values.uuid }}-watcher
|
|
1682
|
-
pepr.dev/controller: watcher
|
|
1683
|
-
spec:
|
|
1684
|
-
terminationGracePeriodSeconds: {{ .Values.watcher.terminationGracePeriodSeconds }}
|
|
1685
|
-
serviceAccountName: {{ .Values.uuid }}
|
|
1686
|
-
securityContext:
|
|
1687
|
-
{{- toYaml .Values.admission.securityContext | nindent 8 }}
|
|
1688
|
-
containers:
|
|
1689
|
-
- name: watcher
|
|
1690
|
-
image: {{ .Values.watcher.image }}
|
|
1691
|
-
imagePullPolicy: IfNotPresent
|
|
1692
|
-
command:
|
|
1693
|
-
- node
|
|
1694
|
-
- /app/node_modules/pepr/dist/controller.js
|
|
1695
|
-
- {{ .Values.hash }}
|
|
1696
|
-
readinessProbe:
|
|
1697
|
-
{{- toYaml .Values.watcher.readinessProbe | nindent 12 }}
|
|
1698
|
-
livenessProbe:
|
|
1699
|
-
{{- toYaml .Values.watcher.livenessProbe | nindent 12 }}
|
|
1700
|
-
ports:
|
|
1701
|
-
- containerPort: 3000
|
|
1702
|
-
resources:
|
|
1703
|
-
{{- toYaml .Values.watcher.resources | nindent 12 }}
|
|
1704
|
-
env:
|
|
1705
|
-
{{- toYaml .Values.watcher.env | nindent 12 }}
|
|
1706
|
-
- name: PEPR_WATCH_MODE
|
|
1707
|
-
value: "true"
|
|
1708
|
-
envFrom:
|
|
1709
|
-
{{- toYaml .Values.watcher.envFrom | nindent 12 }}
|
|
1710
|
-
securityContext:
|
|
1711
|
-
{{- toYaml .Values.watcher.containerSecurityContext | nindent 12 }}
|
|
1712
|
-
volumeMounts:
|
|
1713
|
-
- name: tls-certs
|
|
1714
|
-
mountPath: /etc/certs
|
|
1715
|
-
readOnly: true
|
|
1716
|
-
- name: module
|
|
1717
|
-
mountPath: /app/load
|
|
1718
|
-
readOnly: true
|
|
1719
|
-
{{- if .Values.watcher.extraVolumeMounts }}
|
|
1720
|
-
{{- toYaml .Values.watcher.extraVolumeMounts | nindent 12 }}
|
|
1721
|
-
{{- end }}
|
|
1722
|
-
volumes:
|
|
1723
|
-
- name: tls-certs
|
|
1724
|
-
secret:
|
|
1725
|
-
secretName: {{ .Values.uuid }}-tls
|
|
1726
|
-
- name: module
|
|
1727
|
-
secret:
|
|
1728
|
-
secretName: {{ .Values.uuid }}-module
|
|
1729
|
-
{{- if .Values.watcher.extraVolumes }}
|
|
1730
|
-
{{- toYaml .Values.watcher.extraVolumes | nindent 8 }}
|
|
1731
|
-
{{- end }}
|
|
1732
|
-
`;
|
|
1733
|
-
}
|
|
1734
|
-
function admissionDeployTemplate(buildTimestamp) {
|
|
1735
|
-
return `
|
|
1736
|
-
apiVersion: apps/v1
|
|
1737
|
-
kind: Deployment
|
|
1738
|
-
metadata:
|
|
1739
|
-
name: {{ .Values.uuid }}
|
|
1740
|
-
namespace: pepr-system
|
|
1741
|
-
annotations:
|
|
1742
|
-
{{- toYaml .Values.admission.annotations | nindent 4 }}
|
|
1743
|
-
labels:
|
|
1744
|
-
{{- toYaml .Values.admission.labels | nindent 4 }}
|
|
1745
|
-
spec:
|
|
1746
|
-
replicas: 2
|
|
1747
|
-
selector:
|
|
1748
|
-
matchLabels:
|
|
1749
|
-
app: {{ .Values.uuid }}
|
|
1750
|
-
pepr.dev/controller: admission
|
|
1751
|
-
template:
|
|
1752
|
-
metadata:
|
|
1753
|
-
annotations:
|
|
1754
|
-
buildTimestamp: "${buildTimestamp}"
|
|
1755
|
-
{{- if .Values.admission.podAnnotations }}
|
|
1756
|
-
{{- toYaml .Values.admission.podAnnotations | nindent 8 }}
|
|
1757
|
-
{{- end }}
|
|
1758
|
-
labels:
|
|
1759
|
-
app: {{ .Values.uuid }}
|
|
1760
|
-
pepr.dev/controller: admission
|
|
1761
|
-
spec:
|
|
1762
|
-
terminationGracePeriodSeconds: {{ .Values.admission.terminationGracePeriodSeconds }}
|
|
1763
|
-
priorityClassName: system-node-critical
|
|
1764
|
-
serviceAccountName: {{ .Values.uuid }}
|
|
1765
|
-
securityContext:
|
|
1766
|
-
{{- toYaml .Values.admission.securityContext | nindent 8 }}
|
|
1767
|
-
containers:
|
|
1768
|
-
- name: server
|
|
1769
|
-
image: {{ .Values.admission.image }}
|
|
1770
|
-
imagePullPolicy: IfNotPresent
|
|
1771
|
-
command:
|
|
1772
|
-
- node
|
|
1773
|
-
- /app/node_modules/pepr/dist/controller.js
|
|
1774
|
-
- {{ .Values.hash }}
|
|
1775
|
-
readinessProbe:
|
|
1776
|
-
{{- toYaml .Values.admission.readinessProbe | nindent 12 }}
|
|
1777
|
-
livenessProbe:
|
|
1778
|
-
{{- toYaml .Values.admission.livenessProbe | nindent 12 }}
|
|
1779
|
-
ports:
|
|
1780
|
-
- containerPort: 3000
|
|
1781
|
-
resources:
|
|
1782
|
-
{{- toYaml .Values.admission.resources | nindent 12 }}
|
|
1783
|
-
env:
|
|
1784
|
-
{{- toYaml .Values.admission.env | nindent 12 }}
|
|
1785
|
-
- name: PEPR_WATCH_MODE
|
|
1786
|
-
value: "false"
|
|
1787
|
-
envFrom:
|
|
1788
|
-
{{- toYaml .Values.admission.envFrom | nindent 12 }}
|
|
1789
|
-
securityContext:
|
|
1790
|
-
{{- toYaml .Values.admission.containerSecurityContext | nindent 12 }}
|
|
1791
|
-
volumeMounts:
|
|
1792
|
-
- name: tls-certs
|
|
1793
|
-
mountPath: /etc/certs
|
|
1794
|
-
readOnly: true
|
|
1795
|
-
- name: api-token
|
|
1796
|
-
mountPath: /app/api-token
|
|
1797
|
-
readOnly: true
|
|
1798
|
-
- name: module
|
|
1799
|
-
mountPath: /app/load
|
|
1800
|
-
readOnly: true
|
|
1801
|
-
{{- if .Values.admission.extraVolumeMounts }}
|
|
1802
|
-
{{- toYaml .Values.admission.extraVolumeMounts | nindent 12 }}
|
|
1803
|
-
{{- end }}
|
|
1804
|
-
volumes:
|
|
1805
|
-
- name: tls-certs
|
|
1806
|
-
secret:
|
|
1807
|
-
secretName: {{ .Values.uuid }}-tls
|
|
1808
|
-
- name: api-token
|
|
1809
|
-
secret:
|
|
1810
|
-
secretName: {{ .Values.uuid }}-api-token
|
|
1811
|
-
- name: module
|
|
1812
|
-
secret:
|
|
1813
|
-
secretName: {{ .Values.uuid }}-module
|
|
1814
|
-
{{- if .Values.admission.extraVolumes }}
|
|
1815
|
-
{{- toYaml .Values.admission.extraVolumes | nindent 8 }}
|
|
1816
|
-
{{- end }}
|
|
1817
|
-
`;
|
|
1311
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.MutatingWebhookConfiguration).Delete(name2);
|
|
1312
|
+
}
|
|
1313
|
+
const validateWebhook = await webhookConfig(assets, "validate", webhookTimeout);
|
|
1314
|
+
if (validateWebhook) {
|
|
1315
|
+
logger_default.info("Applying validating webhook");
|
|
1316
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ValidatingWebhookConfiguration).Apply(validateWebhook, { force });
|
|
1317
|
+
} else {
|
|
1318
|
+
logger_default.info("Validating webhook not needed, removing if it exists");
|
|
1319
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ValidatingWebhookConfiguration).Delete(name2);
|
|
1320
|
+
}
|
|
1321
|
+
logger_default.info("Applying the Pepr Store CRD if it doesn't exist");
|
|
1322
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.CustomResourceDefinition).Apply(peprStoreCRD, { force });
|
|
1323
|
+
if (host) {
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
const code = await import_fs2.promises.readFile(path);
|
|
1327
|
+
const hash = import_crypto.default.createHash("sha256").update(code).digest("hex");
|
|
1328
|
+
if (code.length < 1) {
|
|
1329
|
+
throw new Error("No code provided");
|
|
1330
|
+
}
|
|
1331
|
+
await setupRBAC(name2, assets.capabilities, force, assets.config);
|
|
1332
|
+
await setupController(assets, code, hash, force);
|
|
1333
|
+
await setupWatcher(assets, hash, force);
|
|
1818
1334
|
}
|
|
1819
|
-
function
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1335
|
+
async function setupRBAC(name2, capabilities, force, config) {
|
|
1336
|
+
const { rbacMode, rbac } = config;
|
|
1337
|
+
logger_default.info("Applying cluster role binding");
|
|
1338
|
+
const crb = clusterRoleBinding(name2);
|
|
1339
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ClusterRoleBinding).Apply(crb, { force });
|
|
1340
|
+
logger_default.info("Applying cluster role");
|
|
1341
|
+
const cr = clusterRole(name2, capabilities, rbacMode, rbac);
|
|
1342
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ClusterRole).Apply(cr, { force });
|
|
1343
|
+
logger_default.info("Applying service account");
|
|
1344
|
+
const sa = serviceAccount(name2);
|
|
1345
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.ServiceAccount).Apply(sa, { force });
|
|
1346
|
+
logger_default.info("Applying store role");
|
|
1347
|
+
const role = storeRole(name2);
|
|
1348
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Role).Apply(role, { force });
|
|
1349
|
+
logger_default.info("Applying store role binding");
|
|
1350
|
+
const roleBinding = storeRoleBinding(name2);
|
|
1351
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.RoleBinding).Apply(roleBinding, { force });
|
|
1352
|
+
}
|
|
1353
|
+
async function setupController(assets, code, hash, force) {
|
|
1354
|
+
const { name: name2 } = assets;
|
|
1355
|
+
logger_default.info("Applying module secret");
|
|
1356
|
+
const mod = getModuleSecret(name2, code, hash);
|
|
1357
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(mod, { force });
|
|
1358
|
+
logger_default.info("Applying controller service");
|
|
1359
|
+
const svc = service(name2);
|
|
1360
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Service).Apply(svc, { force });
|
|
1361
|
+
logger_default.info("Applying TLS secret");
|
|
1362
|
+
const tls = tlsSecret(name2, assets.tls);
|
|
1363
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(tls, { force });
|
|
1364
|
+
logger_default.info("Applying API token secret");
|
|
1365
|
+
const apiToken = apiTokenSecret(name2, assets.apiToken);
|
|
1366
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Secret).Apply(apiToken, { force });
|
|
1367
|
+
logger_default.info("Applying deployment");
|
|
1368
|
+
const dep = getDeployment(assets, hash, assets.buildTimestamp);
|
|
1369
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(dep, { force });
|
|
1370
|
+
}
|
|
1371
|
+
async function setupWatcher(assets, hash, force) {
|
|
1372
|
+
const watchDeployment = getWatcher(assets, hash, assets.buildTimestamp);
|
|
1373
|
+
if (watchDeployment) {
|
|
1374
|
+
logger_default.info("Applying watcher deployment");
|
|
1375
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Deployment).Apply(watchDeployment, { force });
|
|
1376
|
+
logger_default.info("Applying watcher service");
|
|
1377
|
+
const watchSvc = watcherService(assets.name);
|
|
1378
|
+
await (0, import_kubernetes_fluent_client3.K8s)(import_kubernetes_fluent_client3.kind.Service).Apply(watchSvc, { force });
|
|
1379
|
+
}
|
|
1844
1380
|
}
|
|
1845
1381
|
|
|
1846
1382
|
// src/lib/assets/index.ts
|
|
1847
|
-
var
|
|
1383
|
+
var import_client_node = require("@kubernetes/client-node");
|
|
1384
|
+
var import_path = require("path");
|
|
1385
|
+
function toYaml(obj) {
|
|
1386
|
+
return (0, import_client_node.dumpYaml)(obj, { noRefs: true });
|
|
1387
|
+
}
|
|
1388
|
+
function createWebhookYaml(name2, config, webhookConfiguration) {
|
|
1389
|
+
const yaml = toYaml(webhookConfiguration);
|
|
1390
|
+
return replaceString(
|
|
1391
|
+
replaceString(
|
|
1392
|
+
replaceString(yaml, name2, "{{ .Values.uuid }}"),
|
|
1393
|
+
config.onError === "reject" ? "Fail" : "Ignore",
|
|
1394
|
+
"{{ .Values.admission.failurePolicy }}"
|
|
1395
|
+
),
|
|
1396
|
+
`${config.webhookTimeout}` || "10",
|
|
1397
|
+
"{{ .Values.admission.webhookTimeout }}"
|
|
1398
|
+
);
|
|
1399
|
+
}
|
|
1400
|
+
function helmLayout(basePath, unique) {
|
|
1401
|
+
const helm = {
|
|
1402
|
+
dirs: {
|
|
1403
|
+
chart: (0, import_path.resolve)(`${basePath}/${unique}-chart`)
|
|
1404
|
+
},
|
|
1405
|
+
files: {}
|
|
1406
|
+
};
|
|
1407
|
+
helm.dirs = {
|
|
1408
|
+
...helm.dirs,
|
|
1409
|
+
charts: `${helm.dirs.chart}/charts`,
|
|
1410
|
+
tmpls: `${helm.dirs.chart}/templates`
|
|
1411
|
+
};
|
|
1412
|
+
helm.files = {
|
|
1413
|
+
...helm.files,
|
|
1414
|
+
valuesYaml: `${helm.dirs.chart}/values.yaml`,
|
|
1415
|
+
chartYaml: `${helm.dirs.chart}/Chart.yaml`,
|
|
1416
|
+
namespaceYaml: `${helm.dirs.tmpls}/namespace.yaml`,
|
|
1417
|
+
watcherServiceYaml: `${helm.dirs.tmpls}/watcher-service.yaml`,
|
|
1418
|
+
admissionServiceYaml: `${helm.dirs.tmpls}/admission-service.yaml`,
|
|
1419
|
+
mutationWebhookYaml: `${helm.dirs.tmpls}/mutation-webhook.yaml`,
|
|
1420
|
+
validationWebhookYaml: `${helm.dirs.tmpls}/validation-webhook.yaml`,
|
|
1421
|
+
admissionDeploymentYaml: `${helm.dirs.tmpls}/admission-deployment.yaml`,
|
|
1422
|
+
admissionServiceMonitorYaml: `${helm.dirs.tmpls}/admission-service-monitor.yaml`,
|
|
1423
|
+
watcherDeploymentYaml: `${helm.dirs.tmpls}/watcher-deployment.yaml`,
|
|
1424
|
+
watcherServiceMonitorYaml: `${helm.dirs.tmpls}/watcher-service-monitor.yaml`,
|
|
1425
|
+
tlsSecretYaml: `${helm.dirs.tmpls}/tls-secret.yaml`,
|
|
1426
|
+
apiTokenSecretYaml: `${helm.dirs.tmpls}/api-token-secret.yaml`,
|
|
1427
|
+
moduleSecretYaml: `${helm.dirs.tmpls}/module-secret.yaml`,
|
|
1428
|
+
storeRoleYaml: `${helm.dirs.tmpls}/store-role.yaml`,
|
|
1429
|
+
storeRoleBindingYaml: `${helm.dirs.tmpls}/store-role-binding.yaml`,
|
|
1430
|
+
clusterRoleYaml: `${helm.dirs.tmpls}/cluster-role.yaml`,
|
|
1431
|
+
clusterRoleBindingYaml: `${helm.dirs.tmpls}/cluster-role-binding.yaml`,
|
|
1432
|
+
serviceAccountYaml: `${helm.dirs.tmpls}/service-account.yaml`
|
|
1433
|
+
};
|
|
1434
|
+
return helm;
|
|
1435
|
+
}
|
|
1848
1436
|
|
|
1849
|
-
// src/lib/
|
|
1437
|
+
// src/lib/assets/loader.ts
|
|
1438
|
+
var import_child_process = require("child_process");
|
|
1439
|
+
function loadCapabilities(path) {
|
|
1440
|
+
return new Promise((resolve6, reject) => {
|
|
1441
|
+
const program2 = (0, import_child_process.fork)(path, {
|
|
1442
|
+
env: {
|
|
1443
|
+
...process.env,
|
|
1444
|
+
LOG_LEVEL: "warn",
|
|
1445
|
+
PEPR_MODE: "build",
|
|
1446
|
+
NODE_OPTIONS: "--disable-warning=DEP0040"
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1449
|
+
program2.on("message", (message) => {
|
|
1450
|
+
const capabilities = message.valueOf();
|
|
1451
|
+
for (const capability of capabilities) {
|
|
1452
|
+
console.info(`Registered Pepr Capability "${capability.name}"`);
|
|
1453
|
+
}
|
|
1454
|
+
resolve6(capabilities);
|
|
1455
|
+
});
|
|
1456
|
+
program2.on("error", (error) => {
|
|
1457
|
+
reject(error);
|
|
1458
|
+
});
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
// src/lib/assets/yaml.ts
|
|
1463
|
+
var import_client_node2 = require("@kubernetes/client-node");
|
|
1850
1464
|
var import_fs3 = require("fs");
|
|
1851
|
-
async function
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1465
|
+
async function overridesFile({ hash, name: name2, image, config, apiToken, capabilities }, path) {
|
|
1466
|
+
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
1467
|
+
const overrides = {
|
|
1468
|
+
rbac: rbacOverrides,
|
|
1469
|
+
secrets: {
|
|
1470
|
+
apiToken: Buffer.from(apiToken).toString("base64")
|
|
1471
|
+
},
|
|
1472
|
+
hash,
|
|
1473
|
+
namespace: {
|
|
1474
|
+
annotations: {},
|
|
1475
|
+
labels: {
|
|
1476
|
+
"pepr.dev": ""
|
|
1477
|
+
}
|
|
1478
|
+
},
|
|
1479
|
+
uuid: name2,
|
|
1480
|
+
admission: {
|
|
1481
|
+
terminationGracePeriodSeconds: 5,
|
|
1482
|
+
failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
|
|
1483
|
+
webhookTimeout: config.webhookTimeout,
|
|
1484
|
+
env: genEnv(config, false, true),
|
|
1485
|
+
envFrom: [],
|
|
1486
|
+
image,
|
|
1487
|
+
annotations: {
|
|
1488
|
+
"pepr.dev/description": `${config.description}` || ""
|
|
1489
|
+
},
|
|
1490
|
+
labels: {
|
|
1491
|
+
app: name2,
|
|
1492
|
+
"pepr.dev/controller": "admission",
|
|
1493
|
+
"pepr.dev/uuid": config.uuid
|
|
1494
|
+
},
|
|
1495
|
+
securityContext: {
|
|
1496
|
+
runAsUser: 65532,
|
|
1497
|
+
runAsGroup: 65532,
|
|
1498
|
+
runAsNonRoot: true,
|
|
1499
|
+
fsGroup: 65532
|
|
1500
|
+
},
|
|
1501
|
+
readinessProbe: {
|
|
1502
|
+
httpGet: {
|
|
1503
|
+
path: "/healthz",
|
|
1504
|
+
port: 3e3,
|
|
1505
|
+
scheme: "HTTPS"
|
|
1506
|
+
},
|
|
1507
|
+
initialDelaySeconds: 10
|
|
1508
|
+
},
|
|
1509
|
+
livenessProbe: {
|
|
1510
|
+
httpGet: {
|
|
1511
|
+
path: "/healthz",
|
|
1512
|
+
port: 3e3,
|
|
1513
|
+
scheme: "HTTPS"
|
|
1514
|
+
},
|
|
1515
|
+
initialDelaySeconds: 10
|
|
1516
|
+
},
|
|
1517
|
+
resources: {
|
|
1518
|
+
requests: {
|
|
1519
|
+
memory: "256Mi",
|
|
1520
|
+
cpu: "200m"
|
|
1521
|
+
},
|
|
1522
|
+
limits: {
|
|
1523
|
+
memory: "512Mi",
|
|
1524
|
+
cpu: "500m"
|
|
1525
|
+
}
|
|
1526
|
+
},
|
|
1527
|
+
containerSecurityContext: {
|
|
1528
|
+
runAsUser: 65532,
|
|
1529
|
+
runAsGroup: 65532,
|
|
1530
|
+
runAsNonRoot: true,
|
|
1531
|
+
allowPrivilegeEscalation: false,
|
|
1532
|
+
capabilities: {
|
|
1533
|
+
drop: ["ALL"]
|
|
1534
|
+
}
|
|
1535
|
+
},
|
|
1536
|
+
podAnnotations: {},
|
|
1537
|
+
nodeSelector: {},
|
|
1538
|
+
tolerations: [],
|
|
1539
|
+
extraVolumeMounts: [],
|
|
1540
|
+
extraVolumes: [],
|
|
1541
|
+
affinity: {},
|
|
1542
|
+
serviceMonitor: {
|
|
1543
|
+
enabled: false,
|
|
1544
|
+
labels: {},
|
|
1545
|
+
annotations: {}
|
|
1546
|
+
}
|
|
1547
|
+
},
|
|
1548
|
+
watcher: {
|
|
1549
|
+
terminationGracePeriodSeconds: 5,
|
|
1550
|
+
env: genEnv(config, true, true),
|
|
1551
|
+
envFrom: [],
|
|
1552
|
+
image,
|
|
1553
|
+
annotations: {
|
|
1554
|
+
"pepr.dev/description": `${config.description}` || ""
|
|
1555
|
+
},
|
|
1556
|
+
labels: {
|
|
1557
|
+
app: `${name2}-watcher`,
|
|
1558
|
+
"pepr.dev/controller": "watcher",
|
|
1559
|
+
"pepr.dev/uuid": config.uuid
|
|
1560
|
+
},
|
|
1561
|
+
securityContext: {
|
|
1562
|
+
runAsUser: 65532,
|
|
1563
|
+
runAsGroup: 65532,
|
|
1564
|
+
runAsNonRoot: true,
|
|
1565
|
+
fsGroup: 65532
|
|
1566
|
+
},
|
|
1567
|
+
readinessProbe: {
|
|
1568
|
+
httpGet: {
|
|
1569
|
+
path: "/healthz",
|
|
1570
|
+
port: 3e3,
|
|
1571
|
+
scheme: "HTTPS"
|
|
1572
|
+
},
|
|
1573
|
+
initialDelaySeconds: 10
|
|
1574
|
+
},
|
|
1575
|
+
livenessProbe: {
|
|
1576
|
+
httpGet: {
|
|
1577
|
+
path: "/healthz",
|
|
1578
|
+
port: 3e3,
|
|
1579
|
+
scheme: "HTTPS"
|
|
1580
|
+
},
|
|
1581
|
+
initialDelaySeconds: 10
|
|
1582
|
+
},
|
|
1583
|
+
resources: {
|
|
1584
|
+
requests: {
|
|
1585
|
+
memory: "256Mi",
|
|
1586
|
+
cpu: "200m"
|
|
1587
|
+
},
|
|
1588
|
+
limits: {
|
|
1589
|
+
memory: "512Mi",
|
|
1590
|
+
cpu: "500m"
|
|
1591
|
+
}
|
|
1592
|
+
},
|
|
1593
|
+
containerSecurityContext: {
|
|
1594
|
+
runAsUser: 65532,
|
|
1595
|
+
runAsGroup: 65532,
|
|
1596
|
+
runAsNonRoot: true,
|
|
1597
|
+
allowPrivilegeEscalation: false,
|
|
1598
|
+
capabilities: {
|
|
1599
|
+
drop: ["ALL"]
|
|
1600
|
+
}
|
|
1601
|
+
},
|
|
1602
|
+
nodeSelector: {},
|
|
1603
|
+
tolerations: [],
|
|
1604
|
+
extraVolumeMounts: [],
|
|
1605
|
+
extraVolumes: [],
|
|
1606
|
+
affinity: {},
|
|
1607
|
+
podAnnotations: {},
|
|
1608
|
+
serviceMonitor: {
|
|
1609
|
+
enabled: false,
|
|
1610
|
+
labels: {},
|
|
1611
|
+
annotations: {}
|
|
1612
|
+
}
|
|
1859
1613
|
}
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
|
-
// src/lib/assets/index.ts
|
|
1864
|
-
function toYaml(obj) {
|
|
1865
|
-
return (0, import_client_node2.dumpYaml)(obj, { noRefs: true });
|
|
1866
|
-
}
|
|
1867
|
-
function createWebhookYaml(assets, webhookConfiguration) {
|
|
1868
|
-
const yaml = toYaml(webhookConfiguration);
|
|
1869
|
-
return replaceString(
|
|
1870
|
-
replaceString(
|
|
1871
|
-
replaceString(yaml, assets.name, "{{ .Values.uuid }}"),
|
|
1872
|
-
assets.config.onError === "reject" ? "Fail" : "Ignore",
|
|
1873
|
-
"{{ .Values.admission.failurePolicy }}"
|
|
1874
|
-
),
|
|
1875
|
-
`${assets.config.webhookTimeout}` || "10",
|
|
1876
|
-
"{{ .Values.admission.webhookTimeout }}"
|
|
1877
|
-
);
|
|
1614
|
+
};
|
|
1615
|
+
await import_fs3.promises.writeFile(path, (0, import_client_node2.dumpYaml)(overrides, { noRefs: true, forceQuotes: true }));
|
|
1878
1616
|
}
|
|
1879
|
-
function
|
|
1880
|
-
const
|
|
1881
|
-
|
|
1882
|
-
|
|
1617
|
+
function generateZarfYaml(name2, image, config, path) {
|
|
1618
|
+
const zarfCfg = {
|
|
1619
|
+
kind: "ZarfPackageConfig",
|
|
1620
|
+
metadata: {
|
|
1621
|
+
name: name2,
|
|
1622
|
+
description: `Pepr Module: ${config.description}`,
|
|
1623
|
+
url: "https://github.com/defenseunicorns/pepr",
|
|
1624
|
+
version: `${config.appVersion || "0.0.1"}`
|
|
1883
1625
|
},
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1626
|
+
components: [
|
|
1627
|
+
{
|
|
1628
|
+
name: "module",
|
|
1629
|
+
required: true,
|
|
1630
|
+
manifests: [
|
|
1631
|
+
{
|
|
1632
|
+
name: "module",
|
|
1633
|
+
namespace: "pepr-system",
|
|
1634
|
+
files: [path]
|
|
1635
|
+
}
|
|
1636
|
+
],
|
|
1637
|
+
images: [image]
|
|
1638
|
+
}
|
|
1639
|
+
]
|
|
1890
1640
|
};
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1641
|
+
return (0, import_client_node2.dumpYaml)(zarfCfg, { noRefs: true });
|
|
1642
|
+
}
|
|
1643
|
+
function generateZarfYamlChart(name2, image, config, path) {
|
|
1644
|
+
const zarfCfg = {
|
|
1645
|
+
kind: "ZarfPackageConfig",
|
|
1646
|
+
metadata: {
|
|
1647
|
+
name: name2,
|
|
1648
|
+
description: `Pepr Module: ${config.description}`,
|
|
1649
|
+
url: "https://github.com/defenseunicorns/pepr",
|
|
1650
|
+
version: `${config.appVersion || "0.0.1"}`
|
|
1651
|
+
},
|
|
1652
|
+
components: [
|
|
1653
|
+
{
|
|
1654
|
+
name: "module",
|
|
1655
|
+
required: true,
|
|
1656
|
+
charts: [
|
|
1657
|
+
{
|
|
1658
|
+
name: "module",
|
|
1659
|
+
namespace: "pepr-system",
|
|
1660
|
+
version: `${config.appVersion || "0.0.1"}`,
|
|
1661
|
+
localPath: path
|
|
1662
|
+
}
|
|
1663
|
+
],
|
|
1664
|
+
images: [image]
|
|
1665
|
+
}
|
|
1666
|
+
]
|
|
1912
1667
|
};
|
|
1913
|
-
return
|
|
1668
|
+
return (0, import_client_node2.dumpYaml)(zarfCfg, { noRefs: true });
|
|
1669
|
+
}
|
|
1670
|
+
async function generateAllYaml(webhooks, deployments, assets) {
|
|
1671
|
+
const { name: name2, tls, hash, apiToken, path, config } = assets;
|
|
1672
|
+
const code = await import_fs3.promises.readFile(path);
|
|
1673
|
+
const resources = [
|
|
1674
|
+
getNamespace(assets.config.customLabels?.namespace),
|
|
1675
|
+
clusterRole(name2, assets.capabilities, config.rbacMode, config.rbac),
|
|
1676
|
+
clusterRoleBinding(name2),
|
|
1677
|
+
serviceAccount(name2),
|
|
1678
|
+
apiTokenSecret(name2, apiToken),
|
|
1679
|
+
tlsSecret(name2, tls),
|
|
1680
|
+
deployments.default,
|
|
1681
|
+
service(name2),
|
|
1682
|
+
watcherService(name2),
|
|
1683
|
+
getModuleSecret(name2, code, hash),
|
|
1684
|
+
storeRole(name2),
|
|
1685
|
+
storeRoleBinding(name2)
|
|
1686
|
+
];
|
|
1687
|
+
if (webhooks.mutate) {
|
|
1688
|
+
resources.push(webhooks.mutate);
|
|
1689
|
+
}
|
|
1690
|
+
if (webhooks.validate) {
|
|
1691
|
+
resources.push(webhooks.validate);
|
|
1692
|
+
}
|
|
1693
|
+
if (deployments.watch) {
|
|
1694
|
+
resources.push(deployments.watch);
|
|
1695
|
+
}
|
|
1696
|
+
return resources.map((r) => (0, import_client_node2.dumpYaml)(r, { noRefs: true })).join("---\n");
|
|
1914
1697
|
}
|
|
1698
|
+
|
|
1699
|
+
// src/lib/assets/assets.ts
|
|
1700
|
+
var import_fs4 = require("fs");
|
|
1915
1701
|
var Assets = class {
|
|
1916
1702
|
constructor(config, path, host) {
|
|
1917
1703
|
this.config = config;
|
|
@@ -1923,7 +1709,7 @@ var Assets = class {
|
|
|
1923
1709
|
this.image = `ghcr.io/defenseunicorns/pepr/controller:v${config.peprVersion}`;
|
|
1924
1710
|
this.hash = "";
|
|
1925
1711
|
this.tls = genTLS(this.host || `${this.name}.pepr-system.svc`);
|
|
1926
|
-
this.apiToken =
|
|
1712
|
+
this.apiToken = import_crypto2.default.randomBytes(32).toString("hex");
|
|
1927
1713
|
}
|
|
1928
1714
|
name;
|
|
1929
1715
|
tls;
|
|
@@ -1940,16 +1726,46 @@ var Assets = class {
|
|
|
1940
1726
|
this.capabilities = await loadCapabilities(this.path);
|
|
1941
1727
|
await deploy(this, force, webhookTimeout);
|
|
1942
1728
|
};
|
|
1943
|
-
zarfYaml = (path) =>
|
|
1944
|
-
zarfYamlChart = (path) =>
|
|
1729
|
+
zarfYaml = (path) => generateZarfYaml(this.name, this.image, this.config, path);
|
|
1730
|
+
zarfYamlChart = (path) => generateZarfYamlChart(this.name, this.image, this.config, path);
|
|
1945
1731
|
allYaml = async (imagePullSecret) => {
|
|
1946
1732
|
this.capabilities = await loadCapabilities(this.path);
|
|
1947
1733
|
for (const capability of this.capabilities) {
|
|
1948
1734
|
namespaceComplianceValidator(capability, this.alwaysIgnore?.namespaces);
|
|
1949
1735
|
}
|
|
1950
|
-
|
|
1736
|
+
const webhooks = {
|
|
1737
|
+
mutate: await webhookConfig(this, "mutate", this.config.webhookTimeout),
|
|
1738
|
+
validate: await webhookConfig(this, "validate", this.config.webhookTimeout)
|
|
1739
|
+
};
|
|
1740
|
+
const code = await import_fs4.promises.readFile(this.path);
|
|
1741
|
+
this.hash = import_crypto2.default.createHash("sha256").update(code).digest("hex");
|
|
1742
|
+
const deployments = {
|
|
1743
|
+
default: getDeployment(this, this.hash, this.buildTimestamp, imagePullSecret),
|
|
1744
|
+
watch: getWatcher(this, this.hash, this.buildTimestamp, imagePullSecret)
|
|
1745
|
+
};
|
|
1746
|
+
const assetsInputs = {
|
|
1747
|
+
apiToken: this.apiToken,
|
|
1748
|
+
capabilities: this.capabilities,
|
|
1749
|
+
config: this.config,
|
|
1750
|
+
hash: this.hash,
|
|
1751
|
+
name: this.name,
|
|
1752
|
+
path: this.path,
|
|
1753
|
+
tls: this.tls
|
|
1754
|
+
};
|
|
1755
|
+
return generateAllYaml(webhooks, deployments, assetsInputs);
|
|
1756
|
+
};
|
|
1757
|
+
writeWebhookFiles = async (validateWebhook, mutateWebhook, helm) => {
|
|
1758
|
+
if (validateWebhook || mutateWebhook) {
|
|
1759
|
+
await import_fs4.promises.writeFile(helm.files.admissionDeploymentYaml, dedent(admissionDeployTemplate(this.buildTimestamp)));
|
|
1760
|
+
await import_fs4.promises.writeFile(helm.files.admissionServiceMonitorYaml, dedent(serviceMonitorTemplate("admission")));
|
|
1761
|
+
}
|
|
1762
|
+
if (mutateWebhook) {
|
|
1763
|
+
await import_fs4.promises.writeFile(helm.files.mutationWebhookYaml, createWebhookYaml(this.name, this.config, mutateWebhook));
|
|
1764
|
+
}
|
|
1765
|
+
if (validateWebhook) {
|
|
1766
|
+
await import_fs4.promises.writeFile(helm.files.validationWebhookYaml, createWebhookYaml(this.name, this.config, validateWebhook));
|
|
1767
|
+
}
|
|
1951
1768
|
};
|
|
1952
|
-
/* eslint max-statements: ["warn", 21] */
|
|
1953
1769
|
generateHelmChart = async (basePath) => {
|
|
1954
1770
|
const helm = helmLayout(basePath, this.config.uuid);
|
|
1955
1771
|
try {
|
|
@@ -1972,21 +1788,20 @@ var Assets = class {
|
|
|
1972
1788
|
[helm.files.moduleSecretYaml, () => toYaml(getModuleSecret(this.name, code, this.hash))]
|
|
1973
1789
|
];
|
|
1974
1790
|
await Promise.all(pairs.map(async ([file, content]) => await import_fs4.promises.writeFile(file, content())));
|
|
1975
|
-
|
|
1791
|
+
const overrideData = {
|
|
1792
|
+
hash: this.hash,
|
|
1793
|
+
name: this.name,
|
|
1794
|
+
image: this.image,
|
|
1795
|
+
config: this.config,
|
|
1796
|
+
apiToken: this.apiToken,
|
|
1797
|
+
capabilities: this.capabilities
|
|
1798
|
+
};
|
|
1799
|
+
await overridesFile(overrideData, helm.files.valuesYaml);
|
|
1976
1800
|
const [mutateWebhook, validateWebhook] = await Promise.all([
|
|
1977
1801
|
webhookConfig(this, "mutate", this.config.webhookTimeout),
|
|
1978
1802
|
webhookConfig(this, "validate", this.config.webhookTimeout)
|
|
1979
1803
|
]);
|
|
1980
|
-
|
|
1981
|
-
await import_fs4.promises.writeFile(helm.files.admissionDeploymentYaml, dedent(admissionDeployTemplate(this.buildTimestamp)));
|
|
1982
|
-
await import_fs4.promises.writeFile(helm.files.admissionServiceMonitorYaml, dedent(serviceMonitorTemplate("admission")));
|
|
1983
|
-
}
|
|
1984
|
-
if (mutateWebhook) {
|
|
1985
|
-
await import_fs4.promises.writeFile(helm.files.mutationWebhookYaml, createWebhookYaml(this, mutateWebhook));
|
|
1986
|
-
}
|
|
1987
|
-
if (validateWebhook) {
|
|
1988
|
-
await import_fs4.promises.writeFile(helm.files.validationWebhookYaml, createWebhookYaml(this, validateWebhook));
|
|
1989
|
-
}
|
|
1804
|
+
await this.writeWebhookFiles(validateWebhook, mutateWebhook, helm);
|
|
1990
1805
|
const watchDeployment = getWatcher(this, this.hash, this.buildTimestamp);
|
|
1991
1806
|
if (watchDeployment) {
|
|
1992
1807
|
await import_fs4.promises.writeFile(helm.files.watcherDeploymentYaml, dedent(watcherDeployTemplate(this.buildTimestamp)));
|
|
@@ -2206,7 +2021,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
2206
2021
|
var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
|
|
2207
2022
|
var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
|
|
2208
2023
|
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\nimport { MockAgent, setGlobalDispatcher } from "undici";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://icanhazdadjoke.com/");\n * const joke = await fetch("https://icanhazdadjoke.com/") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://icanhazdadjoke.com")\n * ```\n */\ninterface TheChuckNorrisJoke {\n id: string;\n joke: string;\n status: number;\n}\n\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("chuck-norris")\n .Mutate(cm => cm.SetLabel("got-jokes", "true"))\n .Watch(async cm => {\n const jokeURL = "https://icanhazdadjoke.com";\n\n const mockAgent: MockAgent = new MockAgent();\n setGlobalDispatcher(mockAgent);\n const mockClient = mockAgent.get(jokeURL);\n mockClient.intercept({ path: "/", method: "GET" }).reply(\n 200,\n {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\n },\n {\n headers: {\n "Content-Type": "application/json; charset=utf-8",\n },\n },\n );\n\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(jokeURL, {\n headers: {\n Accept: "application/json",\n },\n });\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n const { joke } = response.data;\n // Add Joke to the Store\n await Store.setItemAndWait(jokeURL, joke);\n // Add the Chuck Norris joke to the configmap\n try {\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: cm.metadata.name,\n namespace: cm.metadata.namespace,\n },\n data: {\n "chuck-says": Store.getItem(jokeURL),\n },\n });\n } catch (error) {\n Log.error(error, "Failed to apply ConfigMap using server-side apply.", {\n cm,\n });\n }\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
|
|
2209
|
-
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!dist/**/*.test.d.ts*"], version: "0.42.
|
|
2024
|
+
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!dist/**/*.test.d.ts*"], version: "0.42.3", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", version: "node scripts/set-version.js", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns='cosign.e2e.test.ts'", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey:prep": "if [ ! -d ./pepr-upgrade-test ]; then git clone https://github.com/defenseunicorns/pepr-upgrade-test.git ; fi", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:prep && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "4.21.2", "fast-json-patch": "3.1.1", "follow-redirects": "1.15.9", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.3.7", pino: "9.6.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.0.0" }, devDependencies: { "@commitlint/cli": "19.6.1", "@commitlint/config-conventional": "19.6.0", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.0", "@types/follow-redirects": "1.14.4", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^3.19.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", "ts-jest": "29.2.5", undici: "^7.0.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "7.18.0", "@typescript-eslint/parser": "7.18.0", "@types/prompts": "2.4.9", eslint: "8.57.0", commander: "12.1.0", esbuild: "0.24.0", "node-forge": "1.3.1", prettier: "3.4.2", prompts: "2.4.2", typescript: "^5.3.3", uuid: "11.0.3" } };
|
|
2210
2025
|
|
|
2211
2026
|
// src/templates/pepr.code-snippets.json
|
|
2212
2027
|
var pepr_code_snippets_default = {
|
|
@@ -2393,8 +2208,27 @@ var import_commander = require("commander");
|
|
|
2393
2208
|
|
|
2394
2209
|
// src/cli/format.ts
|
|
2395
2210
|
var import_eslint = require("eslint");
|
|
2211
|
+
|
|
2212
|
+
// src/cli/format.helpers.ts
|
|
2396
2213
|
var import_fs6 = require("fs");
|
|
2397
2214
|
var import_prettier = require("prettier");
|
|
2215
|
+
async function formatWithPrettier(results, validateOnly) {
|
|
2216
|
+
let hasFailure = false;
|
|
2217
|
+
for (const { filePath } of results) {
|
|
2218
|
+
const content = await import_fs6.promises.readFile(filePath, "utf8");
|
|
2219
|
+
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
2220
|
+
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
2221
|
+
if (validateOnly && formatted !== content) {
|
|
2222
|
+
hasFailure = true;
|
|
2223
|
+
console.error(`File ${filePath} is not formatted correctly`);
|
|
2224
|
+
} else {
|
|
2225
|
+
await import_fs6.promises.writeFile(filePath, formatted);
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
return hasFailure;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// src/cli/format.ts
|
|
2398
2232
|
function format_default(program2) {
|
|
2399
2233
|
program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
|
|
2400
2234
|
const success = await peprFormat(opts.validateOnly);
|
|
@@ -2425,17 +2259,7 @@ async function peprFormat(validateOnly) {
|
|
|
2425
2259
|
if (!validateOnly) {
|
|
2426
2260
|
await import_eslint.ESLint.outputFixes(results);
|
|
2427
2261
|
}
|
|
2428
|
-
|
|
2429
|
-
const content = await import_fs6.promises.readFile(filePath, "utf8");
|
|
2430
|
-
const cfg = await (0, import_prettier.resolveConfig)(filePath);
|
|
2431
|
-
const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
|
|
2432
|
-
if (validateOnly && formatted !== content) {
|
|
2433
|
-
hasFailure = true;
|
|
2434
|
-
console.error(`File ${filePath} is not formatted correctly`);
|
|
2435
|
-
} else {
|
|
2436
|
-
await import_fs6.promises.writeFile(filePath, formatted);
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2262
|
+
hasFailure = await formatWithPrettier(results, validateOnly);
|
|
2439
2263
|
return !hasFailure;
|
|
2440
2264
|
} catch (e) {
|
|
2441
2265
|
console.error(`Error formatting module:`, e);
|
|
@@ -2804,66 +2628,92 @@ async function namespaceDeploymentsReady(namespace = "pepr-system") {
|
|
|
2804
2628
|
}
|
|
2805
2629
|
|
|
2806
2630
|
// src/cli/deploy.ts
|
|
2631
|
+
function validateImagePullSecretDetails(details) {
|
|
2632
|
+
if (!details.pullSecret) {
|
|
2633
|
+
return { valid: true };
|
|
2634
|
+
}
|
|
2635
|
+
if (details.pullSecret !== sanitizeName(details.pullSecret)) {
|
|
2636
|
+
return {
|
|
2637
|
+
valid: false,
|
|
2638
|
+
error: `Invalid --pullSecret. Must be valid name as defined in RFC 1123.`
|
|
2639
|
+
};
|
|
2640
|
+
}
|
|
2641
|
+
const missing = [];
|
|
2642
|
+
if (!details.dockerEmail) {
|
|
2643
|
+
missing.push("--docker-email");
|
|
2644
|
+
}
|
|
2645
|
+
if (!details.dockerServer) {
|
|
2646
|
+
missing.push("--docker-server");
|
|
2647
|
+
}
|
|
2648
|
+
if (!details.dockerUsername) {
|
|
2649
|
+
missing.push("--docker-username");
|
|
2650
|
+
}
|
|
2651
|
+
if (!details.dockerPassword) {
|
|
2652
|
+
missing.push("--docker-password");
|
|
2653
|
+
}
|
|
2654
|
+
if (missing.length > 0) {
|
|
2655
|
+
return {
|
|
2656
|
+
valid: false,
|
|
2657
|
+
error: `Error: Must provide ${missing.join(", ")} when providing --pullSecret`
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
return { valid: true };
|
|
2661
|
+
}
|
|
2662
|
+
function generateImagePullSecret(details) {
|
|
2663
|
+
const auth = Buffer.from(`${details.dockerUsername}:${details.dockerPassword}`).toString(
|
|
2664
|
+
"base64"
|
|
2665
|
+
);
|
|
2666
|
+
return {
|
|
2667
|
+
auths: {
|
|
2668
|
+
[details.dockerServer]: {
|
|
2669
|
+
username: details.dockerUsername,
|
|
2670
|
+
password: details.dockerPassword,
|
|
2671
|
+
email: details.dockerEmail,
|
|
2672
|
+
auth
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
async function getUserConfirmation(opts) {
|
|
2678
|
+
if (opts.confirm) {
|
|
2679
|
+
return true;
|
|
2680
|
+
}
|
|
2681
|
+
const confirm2 = await (0, import_prompts.default)({
|
|
2682
|
+
type: "confirm",
|
|
2683
|
+
name: "confirm",
|
|
2684
|
+
message: "This will remove and redeploy the module. Continue?"
|
|
2685
|
+
});
|
|
2686
|
+
return confirm2.confirm ? true : false;
|
|
2687
|
+
}
|
|
2807
2688
|
function deploy_default(program2) {
|
|
2808
2689
|
program2.command("deploy").description("Deploy a Pepr Module").option("-i, --image [image]", "Override the image tag").option("--confirm", "Skip confirmation prompt").option("--pullSecret <name>", "Deploy imagePullSecret for Controller private registry").option("--docker-server <server>", "Docker server address").option("--docker-username <username>", "Docker registry username").option("--docker-email <email>", "Email for Docker registry").option("--docker-password <password>", "Password for Docker registry").option("--force", "Force deploy the module, override manager field").action(async (opts) => {
|
|
2809
|
-
|
|
2810
|
-
if (
|
|
2811
|
-
console.error(
|
|
2812
|
-
"Error: Must provide docker server, username, email, and password when providing pull secret"
|
|
2813
|
-
);
|
|
2814
|
-
process.exit(1);
|
|
2815
|
-
} else if (opts.pullSecret && opts.pullSecret !== sanitizeName(opts.pullSecret)) {
|
|
2816
|
-
console.error(
|
|
2817
|
-
"Invalid imagePullSecret name. Please provide a valid name as defined in RFC 1123."
|
|
2818
|
-
);
|
|
2690
|
+
const valResp = validateImagePullSecretDetails(opts);
|
|
2691
|
+
if (!valResp.valid) {
|
|
2692
|
+
console.error(valResp.error);
|
|
2819
2693
|
process.exit(1);
|
|
2820
|
-
}
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
[opts.dockerServer]: {
|
|
2824
|
-
username: opts.dockerUsername,
|
|
2825
|
-
password: opts.dockerPassword,
|
|
2826
|
-
email: opts.dockerEmail,
|
|
2827
|
-
auth: Buffer.from(`${opts.dockerUsername}:${opts.dockerPassword}`).toString("base64")
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
};
|
|
2831
|
-
await deployImagePullSecret(imagePullSecret, opts.pullSecret);
|
|
2694
|
+
}
|
|
2695
|
+
if (opts.pullSecret) {
|
|
2696
|
+
await deployImagePullSecret(generateImagePullSecret(opts), opts.pullSecret);
|
|
2832
2697
|
return;
|
|
2833
2698
|
}
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
message: "This will remove and redeploy the module. Continue?"
|
|
2839
|
-
});
|
|
2840
|
-
if (!confirm2.confirm) {
|
|
2841
|
-
process.exit(0);
|
|
2842
|
-
}
|
|
2699
|
+
await getUserConfirmation(opts) || process.exit(0);
|
|
2700
|
+
const builtModule = await buildModule();
|
|
2701
|
+
if (!builtModule) {
|
|
2702
|
+
return;
|
|
2843
2703
|
}
|
|
2844
|
-
const
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
);
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
const timeout = cfg.pepr.webhookTimeout ? cfg.pepr.webhookTimeout : 10;
|
|
2858
|
-
try {
|
|
2859
|
-
await webhook.deploy(opts.force, timeout);
|
|
2860
|
-
validateCapabilityNames(webhook.capabilities);
|
|
2861
|
-
await namespaceDeploymentsReady();
|
|
2862
|
-
console.info(`\u2705 Module deployed successfully`);
|
|
2863
|
-
} catch (e) {
|
|
2864
|
-
console.error(`Error deploying module:`, e);
|
|
2865
|
-
process.exit(1);
|
|
2866
|
-
}
|
|
2704
|
+
const webhook = new Assets(
|
|
2705
|
+
{ ...builtModule.cfg.pepr, description: builtModule.cfg.description },
|
|
2706
|
+
builtModule.path
|
|
2707
|
+
);
|
|
2708
|
+
webhook.image = opts.image ?? webhook.image;
|
|
2709
|
+
try {
|
|
2710
|
+
await webhook.deploy(opts.force, builtModule.cfg.pepr.webhookTimeout ?? 10);
|
|
2711
|
+
validateCapabilityNames(webhook.capabilities);
|
|
2712
|
+
await namespaceDeploymentsReady();
|
|
2713
|
+
console.info(`\u2705 Module deployed successfully`);
|
|
2714
|
+
} catch (e) {
|
|
2715
|
+
console.error(`Error deploying module:`, e);
|
|
2716
|
+
process.exit(1);
|
|
2867
2717
|
}
|
|
2868
2718
|
});
|
|
2869
2719
|
}
|
|
@@ -3051,13 +2901,16 @@ var import_prompts4 = __toESM(require("prompts"));
|
|
|
3051
2901
|
var import_fs11 = require("fs");
|
|
3052
2902
|
var import_prompts3 = __toESM(require("prompts"));
|
|
3053
2903
|
|
|
2904
|
+
// src/cli/init/enums.ts
|
|
2905
|
+
var OnError = /* @__PURE__ */ ((OnError2) => {
|
|
2906
|
+
OnError2["AUDIT"] = "audit";
|
|
2907
|
+
OnError2["IGNORE"] = "ignore";
|
|
2908
|
+
OnError2["REJECT"] = "reject";
|
|
2909
|
+
return OnError2;
|
|
2910
|
+
})(OnError || {});
|
|
2911
|
+
|
|
3054
2912
|
// src/lib/errors.ts
|
|
3055
|
-
var
|
|
3056
|
-
audit: "audit",
|
|
3057
|
-
ignore: "ignore",
|
|
3058
|
-
reject: "reject"
|
|
3059
|
-
};
|
|
3060
|
-
var ErrorList = Object.values(Errors);
|
|
2913
|
+
var ErrorList = Object.values(OnError);
|
|
3061
2914
|
|
|
3062
2915
|
// src/cli/init/walkthrough.ts
|
|
3063
2916
|
async function walkthrough(opts) {
|
|
@@ -3113,18 +2966,18 @@ async function setErrorBehavior(errorBehavior) {
|
|
|
3113
2966
|
choices: [
|
|
3114
2967
|
{
|
|
3115
2968
|
title: "Reject the operation",
|
|
3116
|
-
value:
|
|
2969
|
+
value: "reject" /* REJECT */,
|
|
3117
2970
|
description: "In the event that Pepr is down or other module errors occur, the operation will not be allowed to continue. (Recommended for production.)"
|
|
3118
2971
|
},
|
|
3119
2972
|
{
|
|
3120
2973
|
title: "Ignore",
|
|
3121
|
-
value:
|
|
2974
|
+
value: "ignore" /* IGNORE */,
|
|
3122
2975
|
description: "In the event that Pepr is down or other module errors occur, an entry will be generated in the Pepr Controller Log and the operation will be allowed to continue. (Recommended for development, not for production.)",
|
|
3123
2976
|
selected: true
|
|
3124
2977
|
},
|
|
3125
2978
|
{
|
|
3126
2979
|
title: "Log an audit event",
|
|
3127
|
-
value:
|
|
2980
|
+
value: "audit" /* AUDIT */,
|
|
3128
2981
|
description: "Pepr will continue processing and generate an entry in the Pepr Controller log as well as an audit event in the cluster."
|
|
3129
2982
|
}
|
|
3130
2983
|
]
|
|
@@ -3172,7 +3025,7 @@ ${packageJSON2.print.replace(/^/gm, " \u2502 ")}
|
|
|
3172
3025
|
function init_default(program2) {
|
|
3173
3026
|
let response = {};
|
|
3174
3027
|
let pkgOverride = "";
|
|
3175
|
-
program2.command("init").description("Initialize a new Pepr Module").option("--confirm", "Skip verification prompt when creating a new module.").option("--description <string>", "Explain the purpose of the new module.").option("--name <string>", "Set the name of the new module.").option("--skip-post-init", "Skip npm install, git init, and VSCode launch.").option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.",
|
|
3028
|
+
program2.command("init").description("Initialize a new Pepr Module").option("--confirm", "Skip verification prompt when creating a new module.").option("--description <string>", "Explain the purpose of the new module.").option("--name <string>", "Set the name of the new module.").option("--skip-post-init", "Skip npm install, git init, and VSCode launch.").option(`--errorBehavior <${ErrorList.join("|")}>`, "Set an errorBehavior.", "reject" /* REJECT */).hook("preAction", async (thisCommand) => {
|
|
3176
3029
|
if (process.env.TEST_MODE === "true") {
|
|
3177
3030
|
import_prompts4.default.inject(["pepr-test-module", "A test module for Pepr", "ignore", "y"]);
|
|
3178
3031
|
pkgOverride = "file:../pepr-0.0.0-development.tgz";
|