Skip to content

Commit

Permalink
CLI/SDK packaging optimizations + enhance SDK transparency (#84)
Browse files Browse the repository at this point in the history
Several changes to improve the number of dependencies in each use case
(CLI/SDK/K8s Controller) as well as provide real Typescript again for
better DevX:

- Resolve issue with combinations of ESModule and CommonJS imports when
creating capabilities
- Leverage `peerDependencies` to separately track dependencies to
exclude from the controller, reducing image size and size for SBOM
- Readme fixes + use SVG vs mermaid for module diagram (several NPM
sites don't support mermaid)
- Run unit tests against transpiled code vs pure typescript (closer to
the real behavior)
- Stop emitting typescript defs and instead include actual typescript
for use in the SDK
- Remove TSNode with it's bad opinions on typescript in NPM packages
- Add `strict:true` for tsconfig in the core project for tighter control
of the codebase
- Remove `commander` use by the controller `run.js` entrypoint
- Gracefully handle controller termination
- Fix hotreload behavior when using `pepr dev`
- Switch to `fork` vs `spawn` and `require` where able
- Only watch `pepr.ts` and `capabilities/` for typescript file changes
on `pepr dev`
  • Loading branch information
jeff-mccoy authored May 7, 2023
1 parent c321395 commit 8c90415
Show file tree
Hide file tree
Showing 32 changed files with 484 additions and 689 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"rules": {
"sort-imports": ["error", { "ignoreDeclarationSort": true }]
},
"ignorePatterns": ["node_modules", "dist", "src/cli/init/templates/data.json"]
"ignorePatterns": ["node_modules", "dist", "src/cli/init/templates/data.json", "hack"]
}
1 change: 1 addition & 0 deletions .images/modules.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ insecure*
rollup.config.mjs
tsconfig.json
tsconfig.build.json
/src
/src/cli
/fixtures
/*.ts
/hack
pepr-test-module
*.toml
docs/
dist/fixtures
*.test.*
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /app
COPY --chown=node:node ./package*.json ./

# Install the dependencies in production mode
RUN npm ci --omit=dev
RUN npm ci --omit=dev --omit=peer

# Sync the pepr dist files
COPY --chown=node:node ./dist/ ./node_modules/pepr/dist/
Expand Down
49 changes: 3 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Pepr is on a mission to save Kubernetes from the tyranny of YAML, intimidating g
- Zero-config K8s webhook mutations and [validations soon](https://github.com/defenseunicorns/pepr/issues/73).
- Human-readable fluent API for generating [Pepr Capabilities](#capability)
- Generate new K8s resources based off of cluster resource changes
- Perform other exec/API calls based off of cluster resources changes or any other abitrary schedule
- Perform other exec/API calls based off of cluster resources changes or any other arbitrary schedule
- Out of the box airgap support with [Zarf](https://zarf.dev)
- Entire NPM ecosystem available for advanced operations
- Realtime K8s debugging system for testing/reacting to cluster changes
Expand Down Expand Up @@ -76,7 +76,7 @@ https://user-images.githubusercontent.com/882485/230895880-c5623077-f811-4870-bb

### Module

A module is the top-level collection of capabilities. It is a single, complete TypeScript project that includes an entry point to load all the configuration and capabilities, along with their CapabilityActions. During the Pepr build process, each module produces a unique Kubernetes MutatingWebhookConfiguration and ValidatingWebhookConfiguration, along with a secret containing the transpiled and compressed TypeScript code. The webhooks and secret are deployed into the Kubernetes cluster for processing by a common Pepr controller.
A module is the top-level collection of capabilities. It is a single, complete TypeScript project that includes an entry point to load all the configuration and capabilities, along with their CapabilityActions. During the Pepr build process, each module produces a unique Kubernetes MutatingWebhookConfiguration and ValidatingWebhookConfiguration, along with a secret containing the transpiled and compressed TypeScript code. The webhooks and secret are deployed into the Kubernetes cluster with their own isolated controller.

See [Module](./docs/module.md) for more details.

Expand All @@ -95,50 +95,7 @@ For example, a CapabilityAction could be responsible for adding a specific label
See [CapabilityActions](./docs/actions.md) for more details.

## Logical Pepr Flow

```mermaid
graph LR
subgraph "Module 3 (Validate Only)"
direction LR
Q[entrypoint 3] --> R[Validate Webhook];
R --> S[Capability a <br><i>- action 1<br>- action 2</i>];
S --> T[Capability b <br><i>- action 1<br>- action 2</i>];
end
subgraph "Module 2 (Mutate Only)"
direction LR
K[entrypoint 2] --> L[Mutate Webhook];
L --> M[Capability a <br><i>- action 1<br>- action 2</i>];
M --> N[Capability b <br><i>- action 1<br>- action 2<br>- action 3</i>];
N --> O[Capability c <br><i>- action 1</i>];
end
subgraph "Module 1 (Mutate & Validate)"
direction LR
A[entrypoint 1] --> B[Mutate Webhook];
A --> C[Validate Webhook];
B --> D[Capability a <br><i>- action 1</i>];
D --> E[Capability b <br><i>- action 1<br>- action 2</i>];
E --> F[Capability c <br><i>- action 1<br>- action 2</i>];
C --> G[Capability d <br><i>- action 1<br>- action 2</i>];
G --> H[Capability e <br><i>- action 1</i>];
H --> I[Capability f <br><i>- action 1<br>- action 2<br>- action 3</i>];
end
%% Defining node styles
classDef Validate fill:#66ff66,color:#000;
classDef Mutate fill:#5786ea,color:#000;
class L,M,N,O Mutate;
class B,D,E,F Mutate;
class R,S,T Validate;
class C,G,H,I Validate;
```
![Module Diagram](./.images/modules.svg)

## TypeScript

Expand Down
2 changes: 0 additions & 2 deletions cli.ts

This file was deleted.

9 changes: 0 additions & 9 deletions fixtures/pepr.ts

This file was deleted.

92 changes: 0 additions & 92 deletions fixtures/test-mutations/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions hack/build-template-data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// This is a helper script to collect the contents of the template files before building the CLI

/* eslint-disable */
const fs = require("fs");
const path = require("path");

Expand Down
6 changes: 4 additions & 2 deletions hack/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ let expectedLines = [
"hello-pepr: V1ConfigMap Binding created",
"hello-pepr: V1ConfigMap Binding action created",
"Server listening on port 3000",
"Using beforeHook: req => pepr_1.Log.debug(`beforeHook: ${req.uid}`)",
"Using afterHook: res => pepr_1.Log.debug(`afterHook: ${res.uid}`)",
"Using beforeHook: req => pepr$1.Log.debug(`beforeHook: ${req.uid}`)",
"Using afterHook: res => pepr$1.Log.debug(`afterHook: ${res.uid}`)",
];

function stripAnsiCodes(input) {
Expand Down Expand Up @@ -165,6 +165,8 @@ function peprDev(resolve, reject) {
return !data.replace(/\s+/g, " ").includes(expectedLine);
});

console.log("\x1b[36m%s\x1b[0m'", "Remaining expected lines:" + JSON.stringify(expectedLines, null, 2));

// If all expected lines are found, resolve the promise
if (expectedLines.length < 1) {
cmd.kill();
Expand Down
Loading

0 comments on commit 8c90415

Please sign in to comment.