pepr 0.1.19 → 0.1.20

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pepr
2
2
 
3
- <img align="right" width="350" src=".images/pepr.png" />
3
+ <img align="right" width="40%" src=".images/pepr.png" />
4
4
 
5
5
  Pepr is an open-source project that helps IT Ops teams of all skill levels manage and modify resources in a Kubernetes (K8s) cluster using TypeScript. Kubernetes simplifies the management of multiple computers working together to run and scale applications. Pepr acts as a smart assistant, automatically changing or validating parts of the system as needed.
6
6
 
package/dist/pepr-cli.js CHANGED
@@ -7,6 +7,7 @@ var typescript = require('@rollup/plugin-typescript');
7
7
  var fs = require('fs');
8
8
  var path = require('path');
9
9
  var rollup = require('rollup');
10
+ var types = require('./types-672dd6e4.js');
10
11
  require('@kubernetes/client-node/dist');
11
12
  require('ramda');
12
13
  require('fast-json-patch');
@@ -20,7 +21,7 @@ var uuid = require('uuid');
20
21
  var commander = require('commander');
21
22
  var chokidar = require('chokidar');
22
23
 
23
- var version = "0.1.19";
24
+ var version = "0.1.20";
24
25
 
25
26
  // SPDX-License-Identifier: Apache-2.0
26
27
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
@@ -90,165 +91,6 @@ const banner = `    [38;5;
90
91
                                                                                                                                             
91
92
  `;
92
93
 
93
- // SPDX-License-Identifier: Apache-2.0
94
- // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
95
- /**
96
- * Enumeration representing different logging levels.
97
- */
98
- var LogLevel;
99
- (function (LogLevel) {
100
- LogLevel[LogLevel["debug"] = 0] = "debug";
101
- LogLevel[LogLevel["info"] = 1] = "info";
102
- LogLevel[LogLevel["warn"] = 2] = "warn";
103
- LogLevel[LogLevel["error"] = 3] = "error";
104
- })(LogLevel || (LogLevel = {}));
105
- var ConsoleColors;
106
- (function (ConsoleColors) {
107
- ConsoleColors["Reset"] = "\u001B[0m";
108
- ConsoleColors["Bright"] = "\u001B[1m";
109
- ConsoleColors["Dim"] = "\u001B[2m";
110
- ConsoleColors["Underscore"] = "\u001B[4m";
111
- ConsoleColors["Blink"] = "\u001B[5m";
112
- ConsoleColors["Reverse"] = "\u001B[7m";
113
- ConsoleColors["Hidden"] = "\u001B[8m";
114
- ConsoleColors["FgBlack"] = "\u001B[30m";
115
- ConsoleColors["FgRed"] = "\u001B[31m";
116
- ConsoleColors["FgGreen"] = "\u001B[32m";
117
- ConsoleColors["FgYellow"] = "\u001B[33m";
118
- ConsoleColors["FgBlue"] = "\u001B[34m";
119
- ConsoleColors["FgMagenta"] = "\u001B[35m";
120
- ConsoleColors["FgCyan"] = "\u001B[36m";
121
- ConsoleColors["FgWhite"] = "\u001B[37m";
122
- ConsoleColors["BgBlack"] = "\u001B[40m";
123
- ConsoleColors["BgRed"] = "\u001B[41m";
124
- ConsoleColors["BgGreen"] = "\u001B[42m";
125
- ConsoleColors["BgYellow"] = "\u001B[43m";
126
- ConsoleColors["BgBlue"] = "\u001B[44m";
127
- ConsoleColors["BgMagenta"] = "\u001B[45m";
128
- ConsoleColors["BgCyan"] = "\u001B[46m";
129
- ConsoleColors["BgWhite"] = "\u001B[47m";
130
- })(ConsoleColors || (ConsoleColors = {}));
131
- /**
132
- * Simple logger class that logs messages at different log levels.
133
- */
134
- class Logger {
135
- /**
136
- * Create a new logger instance.
137
- * @param logLevel - The minimum log level to log messages for.
138
- */
139
- constructor(logLevel) {
140
- this._logLevel = logLevel;
141
- }
142
- /**
143
- * Change the log level of the logger.
144
- * @param logLevel - The log level to log the message at.
145
- */
146
- SetLogLevel(logLevel) {
147
- this._logLevel = LogLevel[logLevel];
148
- this.debug(`Log level set to ${logLevel}`);
149
- }
150
- /**
151
- * Log a debug message.
152
- * @param message - The message to log.
153
- */
154
- debug(message, prefix) {
155
- this.log(LogLevel.debug, message, prefix);
156
- }
157
- /**
158
- * Log an info message.
159
- * @param message - The message to log.
160
- */
161
- info(message, prefix) {
162
- this.log(LogLevel.info, message, prefix);
163
- }
164
- /**
165
- * Log a warning message.
166
- * @param message - The message to log.
167
- */
168
- warn(message, prefix) {
169
- this.log(LogLevel.warn, message, prefix);
170
- }
171
- /**
172
- * Log an error message.
173
- * @param message - The message to log.
174
- */
175
- error(message, prefix) {
176
- this.log(LogLevel.error, message, prefix);
177
- }
178
- /**
179
- * Log a message at the specified log level.
180
- * @param logLevel - The log level of the message.
181
- * @param message - The message to log.
182
- */
183
- log(logLevel, message, callerPrefix = "") {
184
- const color = {
185
- [LogLevel.debug]: ConsoleColors.FgBlack,
186
- [LogLevel.info]: ConsoleColors.FgCyan,
187
- [LogLevel.warn]: ConsoleColors.FgYellow,
188
- [LogLevel.error]: ConsoleColors.FgRed,
189
- };
190
- if (logLevel >= this._logLevel) {
191
- // Prefix the message with the colored log level.
192
- let prefix = "[" + LogLevel[logLevel] + "]\t" + callerPrefix;
193
- prefix = this.colorize(prefix, color[logLevel]);
194
- // If the message is not a string, use the debug method to log the object.
195
- if (typeof message !== "string") {
196
- console.log(prefix);
197
- console.debug("%o", message);
198
- }
199
- else {
200
- console.log(prefix + "\t" + message);
201
- }
202
- }
203
- }
204
- colorize(text, color) {
205
- return color + text + ConsoleColors.Reset;
206
- }
207
- }
208
- var Log = new Logger(LogLevel.info);
209
-
210
- // SPDX-License-Identifier: Apache-2.0
211
- // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
212
- var Operation;
213
- (function (Operation) {
214
- Operation["CREATE"] = "CREATE";
215
- Operation["UPDATE"] = "UPDATE";
216
- Operation["DELETE"] = "DELETE";
217
- Operation["CONNECT"] = "CONNECT";
218
- })(Operation || (Operation = {}));
219
-
220
- // SPDX-License-Identifier: Apache-2.0
221
- // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
222
- /**
223
- * The behavior of this module when an error occurs.
224
- */
225
- var ErrorBehavior;
226
- (function (ErrorBehavior) {
227
- ErrorBehavior["ignore"] = "ignore";
228
- ErrorBehavior["audit"] = "audit";
229
- ErrorBehavior["reject"] = "reject";
230
- })(ErrorBehavior || (ErrorBehavior = {}));
231
- /**
232
- * The phase of the Kubernetes admission webhook that the capability is registered for.
233
- *
234
- * Currently only `mutate` is supported.
235
- */
236
- var HookPhase;
237
- (function (HookPhase) {
238
- HookPhase["mutate"] = "mutate";
239
- HookPhase["valdiate"] = "validate";
240
- })(HookPhase || (HookPhase = {}));
241
- /**
242
- * The type of Kubernetes mutating webhook event ethat the capability action is registered for.
243
- */
244
- var Event;
245
- (function (Event) {
246
- Event["Create"] = "create";
247
- Event["Update"] = "update";
248
- Event["Delete"] = "delete";
249
- Event["CreateOrUpdate"] = "createOrUpdate";
250
- })(Event || (Event = {}));
251
-
252
94
  // SPDX-License-Identifier: Apache-2.0
253
95
  function genTLS(name) {
254
96
  // Generate a new CA key pair
@@ -301,7 +143,6 @@ const peprIgnore = {
301
143
  class Webhook {
302
144
  constructor(config) {
303
145
  this.config = config;
304
- this.ns = "pepr-system";
305
146
  this.name = `pepr-${config.uuid}`;
306
147
  this.image = `ghcr.io/defenseunicorns/pepr/controller:${config.version}`;
307
148
  // Generate the ephemeral tls things
@@ -444,7 +285,7 @@ class Webhook {
444
285
  },
445
286
  },
446
287
  spec: {
447
- replicas: 2,
288
+ replicas: 1,
448
289
  selector: {
449
290
  matchLabels: {
450
291
  app: this.name,
@@ -587,7 +428,7 @@ class Webhook {
587
428
  return resources.map(r => clientNode.dumpYaml(r, { noRefs: true })).join("---\n");
588
429
  }
589
430
  async deploy(code) {
590
- Log.info("Establishing connection to Kubernetes");
431
+ types.Log.info("Establishing connection to Kubernetes");
591
432
  const namespace = "pepr-system";
592
433
  // Deploy the resources using the k8s API
593
434
  const kubeConfig = new clientNode.KubeConfig();
@@ -598,104 +439,104 @@ class Webhook {
598
439
  const admissionApi = kubeConfig.makeApiClient(clientNode.AdmissionregistrationV1Api);
599
440
  const ns = this.namespace();
600
441
  try {
601
- Log.info("Checking for namespace");
442
+ types.Log.info("Checking for namespace");
602
443
  await coreV1Api.readNamespace(namespace);
603
444
  }
604
445
  catch (e) {
605
- Log.debug(e.body);
606
- Log.info("Creating namespace");
446
+ types.Log.debug(e.body);
447
+ types.Log.info("Creating namespace");
607
448
  await coreV1Api.createNamespace(ns);
608
449
  }
609
450
  const wh = this.mutatingWebhook();
610
451
  try {
611
- Log.info("Creating mutating webhook");
452
+ types.Log.info("Creating mutating webhook");
612
453
  await admissionApi.createMutatingWebhookConfiguration(wh);
613
454
  }
614
455
  catch (e) {
615
- Log.debug(e.body);
616
- Log.info("Removing and re-creating mutating webhook");
456
+ types.Log.debug(e.body);
457
+ types.Log.info("Removing and re-creating mutating webhook");
617
458
  await admissionApi.deleteMutatingWebhookConfiguration(wh.metadata.name);
618
459
  await admissionApi.createMutatingWebhookConfiguration(wh);
619
460
  }
620
461
  const crb = this.clusterRoleBinding();
621
462
  try {
622
- Log.info("Creating cluster role binding");
463
+ types.Log.info("Creating cluster role binding");
623
464
  await rbacApi.createClusterRoleBinding(crb);
624
465
  }
625
466
  catch (e) {
626
- Log.debug(e.body);
627
- Log.info("Removing and re-creating cluster role binding");
467
+ types.Log.debug(e.body);
468
+ types.Log.info("Removing and re-creating cluster role binding");
628
469
  await rbacApi.deleteClusterRoleBinding(crb.metadata.name);
629
470
  await rbacApi.createClusterRoleBinding(crb);
630
471
  }
631
472
  const cr = this.clusterRole();
632
473
  try {
633
- Log.info("Creating cluster role");
474
+ types.Log.info("Creating cluster role");
634
475
  await rbacApi.createClusterRole(cr);
635
476
  }
636
477
  catch (e) {
637
- Log.debug(e.body);
638
- Log.info("Removing and re-creating the cluster role");
478
+ types.Log.debug(e.body);
479
+ types.Log.info("Removing and re-creating the cluster role");
639
480
  try {
640
481
  await rbacApi.deleteClusterRole(cr.metadata.name);
641
482
  await rbacApi.createClusterRole(cr);
642
483
  }
643
484
  catch (e) {
644
- Log.debug(e.body);
485
+ types.Log.debug(e.body);
645
486
  }
646
487
  }
647
488
  const sa = this.serviceAccount();
648
489
  try {
649
- Log.info("Creating service account");
490
+ types.Log.info("Creating service account");
650
491
  await coreV1Api.createNamespacedServiceAccount(namespace, sa);
651
492
  }
652
493
  catch (e) {
653
- Log.debug(e.body);
654
- Log.info("Removing and re-creating service account");
494
+ types.Log.debug(e.body);
495
+ types.Log.info("Removing and re-creating service account");
655
496
  await coreV1Api.deleteNamespacedServiceAccount(sa.metadata.name, namespace);
656
497
  await coreV1Api.createNamespacedServiceAccount(namespace, sa);
657
498
  }
658
499
  const mod = this.moduleSecret(code);
659
500
  try {
660
- Log.info("Creating module secret");
501
+ types.Log.info("Creating module secret");
661
502
  await coreV1Api.createNamespacedSecret(namespace, mod);
662
503
  }
663
504
  catch (e) {
664
- Log.debug(e.body);
665
- Log.info("Removing and re-creating module secret");
505
+ types.Log.debug(e.body);
506
+ types.Log.info("Removing and re-creating module secret");
666
507
  await coreV1Api.deleteNamespacedSecret(mod.metadata.name, namespace);
667
508
  await coreV1Api.createNamespacedSecret(namespace, mod);
668
509
  }
669
510
  const svc = this.service();
670
511
  try {
671
- Log.info("Creating service");
512
+ types.Log.info("Creating service");
672
513
  await coreV1Api.createNamespacedService(namespace, svc);
673
514
  }
674
515
  catch (e) {
675
- Log.debug(e.body);
676
- Log.info("Removing and re-creating service");
516
+ types.Log.debug(e.body);
517
+ types.Log.info("Removing and re-creating service");
677
518
  await coreV1Api.deleteNamespacedService(svc.metadata.name, namespace);
678
519
  await coreV1Api.createNamespacedService(namespace, svc);
679
520
  }
680
521
  const tls = this.tlsSecret();
681
522
  try {
682
- Log.info("Creating TLS secret");
523
+ types.Log.info("Creating TLS secret");
683
524
  await coreV1Api.createNamespacedSecret(namespace, tls);
684
525
  }
685
526
  catch (e) {
686
- Log.debug(e.body);
687
- Log.info("Removing and re-creating TLS secret");
527
+ types.Log.debug(e.body);
528
+ types.Log.info("Removing and re-creating TLS secret");
688
529
  await coreV1Api.deleteNamespacedSecret(tls.metadata.name, namespace);
689
530
  await coreV1Api.createNamespacedSecret(namespace, tls);
690
531
  }
691
532
  const dep = this.deployment();
692
533
  try {
693
- Log.info("Creating deployment");
534
+ types.Log.info("Creating deployment");
694
535
  await appsApi.createNamespacedDeployment(namespace, dep);
695
536
  }
696
537
  catch (e) {
697
- Log.debug(e.body);
698
- Log.info("Removing and re-creating deployment");
538
+ types.Log.debug(e.body);
539
+ types.Log.info("Removing and re-creating deployment");
699
540
  await appsApi.deleteNamespacedDeployment(dep.metadata.name, namespace);
700
541
  await appsApi.createNamespacedDeployment(namespace, dep);
701
542
  }
@@ -725,8 +566,8 @@ function build (program) {
725
566
  const zarf = webhook.zarfYaml(yamlFile);
726
567
  await fs.promises.writeFile(yamlPath, yaml);
727
568
  await fs.promises.writeFile(zarfPath, zarf);
728
- Log.debug(`Module compiled successfully at ${path$1}`);
729
- Log.info(`K8s resource for the module saved to ${yamlPath}`);
569
+ types.Log.debug(`Module compiled successfully at ${path$1}`);
570
+ types.Log.info(`K8s resource for the module saved to ${yamlPath}`);
730
571
  });
731
572
  }
732
573
  const externalLibs = [
@@ -785,8 +626,8 @@ async function buildModule(moduleDir) {
785
626
  }
786
627
  catch (e) {
787
628
  // On any other error, exit with a non-zero exit code
788
- Log.debug(e);
789
- Log.error(e.message);
629
+ types.Log.debug(e);
630
+ types.Log.error(e.message);
790
631
  process.exit(1);
791
632
  }
792
633
  }
@@ -810,16 +651,20 @@ function deploy (program) {
810
651
  .command("deploy")
811
652
  .description("Deploy a Pepr Module")
812
653
  .option("-d, --dir [directory]", "Pepr module directory", ".")
654
+ .option("-i, --image [image]", "Override the image tag")
655
+ .option("-f, --force", "Force redeployment")
813
656
  .action(async (opts) => {
814
- // Prompt the user to confirm
815
- const confirm = await prompt.prompt({
816
- type: "confirm",
817
- name: "confirm",
818
- message: "This will remove and redeploy the module. Continue?",
819
- });
820
- // Exit if the user doesn't confirm
821
- if (!confirm.confirm) {
822
- process.exit(0);
657
+ if (!opts.force) {
658
+ // Prompt the user to confirm
659
+ const confirm = await prompt.prompt({
660
+ type: "confirm",
661
+ name: "confirm",
662
+ message: "This will remove and redeploy the module. Continue?",
663
+ });
664
+ // Exit if the user doesn't confirm
665
+ if (!confirm.confirm) {
666
+ process.exit(0);
667
+ }
823
668
  }
824
669
  // Build the module
825
670
  const { cfg, path } = await buildModule(opts.dir);
@@ -830,12 +675,15 @@ function deploy (program) {
830
675
  ...cfg.pepr,
831
676
  description: cfg.description,
832
677
  });
678
+ if (opts.image) {
679
+ webhook.image = opts.image;
680
+ }
833
681
  try {
834
682
  await webhook.deploy(code);
835
- Log.info(`Module deployed successfully`);
683
+ types.Log.info(`Module deployed successfully`);
836
684
  }
837
685
  catch (e) {
838
- Log.error(`Error deploying module: ${e}`);
686
+ types.Log.error(`Error deploying module: ${e}`);
839
687
  process.exit(1);
840
688
  }
841
689
  });
@@ -1140,23 +988,23 @@ function walkthrough() {
1140
988
  const askErrorBehavior = {
1141
989
  type: "select",
1142
990
  name: "errorBehavior",
1143
- validate: val => ErrorBehavior[val],
991
+ validate: val => types.ErrorBehavior[val],
1144
992
  message: "How do you want Pepr to handle errors encountered during K8s operations?",
1145
993
  choices: [
1146
994
  {
1147
995
  title: "Ignore",
1148
- value: ErrorBehavior.ignore,
996
+ value: types.ErrorBehavior.ignore,
1149
997
  description: "Pepr will continue processing and generate an entry in the Pepr Controller log.",
1150
998
  selected: true,
1151
999
  },
1152
1000
  {
1153
1001
  title: "Log an audit event",
1154
- value: ErrorBehavior.audit,
1002
+ value: types.ErrorBehavior.audit,
1155
1003
  description: "Pepr will continue processing and generate an entry in the Pepr Controller log as well as an audit event in the cluster.",
1156
1004
  },
1157
1005
  {
1158
1006
  title: "Reject the operation",
1159
- value: ErrorBehavior.reject,
1007
+ value: types.ErrorBehavior.reject,
1160
1008
  description: "Pepr will reject the operation and return an error to the client.",
1161
1009
  },
1162
1010
  ],
@@ -1224,8 +1072,8 @@ function init (program) {
1224
1072
  console.log(`Open VSCode or your editor of choice in ${dirName} to get started!`);
1225
1073
  }
1226
1074
  catch (e) {
1227
- Log.debug(e);
1228
- Log.error(e.message);
1075
+ types.Log.debug(e);
1076
+ types.Log.error(e.message);
1229
1077
  process.exit(1);
1230
1078
  }
1231
1079
  }
@@ -1238,7 +1086,7 @@ class RootCmd extends commander.Command {
1238
1086
  const cmd = new commander.Command(name);
1239
1087
  cmd.option("-l, --log-level [level]", "Log level: debug, info, warn, error", "info");
1240
1088
  cmd.hook("preAction", run => {
1241
- Log.SetLogLevel(run.opts().logLevel);
1089
+ types.Log.SetLogLevel(run.opts().logLevel);
1242
1090
  });
1243
1091
  return cmd;
1244
1092
  }
@@ -1253,15 +1101,15 @@ function test (program) {
1253
1101
  .option("-d, --dir [directory]", "Pepr module directory", ".")
1254
1102
  .option("-w, --watch", "Watch for changes and re-run the test")
1255
1103
  .action(async (opts) => {
1256
- Log.info("Test Module");
1104
+ types.Log.info("Test Module");
1257
1105
  await buildAndTest(opts.dir);
1258
1106
  if (opts.watch) {
1259
1107
  const moduleFiles = path.resolve(opts.dir, "**", "*.ts");
1260
1108
  const watcher = chokidar.watch(moduleFiles);
1261
1109
  watcher.on("ready", () => {
1262
- Log.info(`Watching for changes in ${moduleFiles}`);
1110
+ types.Log.info(`Watching for changes in ${moduleFiles}`);
1263
1111
  watcher.on("all", async (event, path) => {
1264
- Log.debug({ event, path }, "File changed");
1112
+ types.Log.debug({ event, path }, "File changed");
1265
1113
  await buildAndTest(opts.dir);
1266
1114
  });
1267
1115
  });
@@ -1270,15 +1118,15 @@ function test (program) {
1270
1118
  }
1271
1119
  async function buildAndTest(dir) {
1272
1120
  const { path } = await buildModule(dir);
1273
- Log.info(`Module built successfully at ${path}`);
1121
+ types.Log.info(`Module built successfully at ${path}`);
1274
1122
  try {
1275
1123
  const { stdout, stderr } = await exec(`node ${path}`);
1276
1124
  console.log(stdout);
1277
1125
  console.log(stderr);
1278
1126
  }
1279
1127
  catch (e) {
1280
- Log.debug(e);
1281
- Log.error(`Error running module: ${e}`);
1128
+ types.Log.debug(e);
1129
+ types.Log.error(`Error running module: ${e}`);
1282
1130
  process.exit(1);
1283
1131
  }
1284
1132
  }
@@ -1300,4 +1148,3 @@ capability(program);
1300
1148
  test(program);
1301
1149
  deploy(program);
1302
1150
  program.parse();
1303
- //# sourceMappingURL=pepr-cli.js.map