pepr 0.52.2 → 0.52.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 → build/build.helpers.d.ts} +4 -4
- package/dist/cli/build/build.helpers.d.ts.map +1 -0
- package/dist/cli/build/buildModule.d.ts +12 -0
- package/dist/cli/build/buildModule.d.ts.map +1 -0
- package/dist/cli/build/index.d.ts +3 -0
- package/dist/cli/build/index.d.ts.map +1 -0
- package/dist/cli/build/loadModule.d.ts +11 -0
- package/dist/cli/build/loadModule.d.ts.map +1 -0
- package/dist/cli/crd/generate/generators.d.ts +1 -28
- package/dist/cli/crd/generate/generators.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts +2 -2
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +0 -1
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/monitor.d.ts +3 -0
- package/dist/cli/monitor.d.ts.map +1 -1
- package/dist/cli/types.d.ts +14 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +997 -982
- package/dist/controller.js +24 -11
- package/dist/lib/assets/environment.d.ts +1 -0
- package/dist/lib/assets/environment.d.ts.map +1 -1
- package/dist/lib/assets/yaml/generateAllYaml.d.ts +1 -2
- package/dist/lib/assets/yaml/generateAllYaml.d.ts.map +1 -1
- package/dist/lib/core/storage.d.ts +2 -1
- package/dist/lib/core/storage.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/binding.d.ts +2 -1
- package/dist/lib/filter/adjudicators/binding.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/kubernetesObject.d.ts +0 -1
- package/dist/lib/filter/adjudicators/kubernetesObject.d.ts.map +1 -1
- package/dist/lib/processors/mutate-processor.d.ts +2 -1
- package/dist/lib/processors/mutate-processor.d.ts.map +1 -1
- package/dist/lib/types.d.ts +0 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib.js +7 -7
- package/dist/lib.js.map +2 -2
- package/dist/runtime/controller.d.ts +1 -1
- package/dist/runtime/controller.d.ts.map +1 -1
- package/package.json +9 -10
- package/src/cli/{build.helpers.ts → build/build.helpers.ts} +12 -12
- package/src/cli/build/buildModule.ts +160 -0
- package/src/cli/build/index.ts +150 -0
- package/src/cli/build/loadModule.ts +54 -0
- package/src/cli/crd/generate/generators.ts +6 -6
- package/src/cli/deploy.ts +5 -4
- package/src/cli/dev.ts +4 -3
- package/src/cli/monitor.ts +2 -2
- package/src/cli/types.ts +26 -0
- package/src/cli/uuid.ts +5 -6
- package/src/lib/assets/deploy.ts +1 -1
- package/src/lib/assets/environment.ts +8 -1
- package/src/lib/assets/loader.ts +1 -1
- package/src/lib/assets/yaml/generateAllYaml.ts +1 -1
- package/src/lib/controller/index.ts +3 -3
- package/src/lib/controller/store.ts +1 -1
- package/src/lib/core/capability.ts +3 -3
- package/src/lib/core/storage.ts +1 -1
- package/src/lib/filter/adjudicators/binding.ts +2 -1
- package/src/lib/filter/adjudicators/kubernetesObject.ts +1 -1
- package/src/lib/processors/mutate-processor.ts +1 -1
- package/src/lib/types.ts +0 -4
- package/src/runtime/controller.ts +8 -14
- package/dist/cli/build.d.ts +0 -34
- package/dist/cli/build.d.ts.map +0 -1
- package/dist/cli/build.helpers.d.ts.map +0 -1
- package/src/cli/build.ts +0 -375
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/runtime/controller.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/runtime/controller.ts"],"names":[],"mappings":";AAoDA,eAAO,MAAM,OAAO,GAAU,MAAM,MAAM,KAAG,OAAO,CAAC,IAAI,CAYxD,CAAC"}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"!src/fixtures/**",
|
|
17
17
|
"!dist/**/*.test.d.ts*"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.52.
|
|
19
|
+
"version": "0.52.3",
|
|
20
20
|
"main": "dist/lib.js",
|
|
21
21
|
"types": "dist/lib.d.ts",
|
|
22
22
|
"scripts": {
|
|
@@ -55,19 +55,18 @@
|
|
|
55
55
|
"test:upgrade:upstream": "npm run test:journey:k3d && npm run test:journey:image && vitest run integration/cluster/upgrade.test.ts"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@types/ramda": "0.
|
|
58
|
+
"@types/ramda": "0.31.0",
|
|
59
59
|
"commander": "14.0.0",
|
|
60
60
|
"express": "5.1.0",
|
|
61
61
|
"fast-json-patch": "3.1.1",
|
|
62
62
|
"heredoc": "^1.3.1",
|
|
63
63
|
"http-status-codes": "^2.3.0",
|
|
64
64
|
"json-pointer": "^0.6.2",
|
|
65
|
-
"kubernetes-fluent-client": "3.
|
|
65
|
+
"kubernetes-fluent-client": "3.10.0",
|
|
66
66
|
"pino": "9.7.0",
|
|
67
|
-
"pino-pretty": "13.
|
|
67
|
+
"pino-pretty": "13.1.1",
|
|
68
68
|
"prom-client": "15.1.3",
|
|
69
69
|
"ramda": "0.31.3",
|
|
70
|
-
"sigstore": "3.1.0",
|
|
71
70
|
"ts-morph": "^26.0.0"
|
|
72
71
|
},
|
|
73
72
|
"devDependencies": {
|
|
@@ -96,12 +95,12 @@
|
|
|
96
95
|
},
|
|
97
96
|
"peerDependencies": {
|
|
98
97
|
"@types/prompts": "2.4.9",
|
|
99
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
100
|
-
"@typescript-eslint/parser": "8.
|
|
101
|
-
"esbuild": "0.25.
|
|
102
|
-
"eslint": "
|
|
98
|
+
"@typescript-eslint/eslint-plugin": "8.38.0",
|
|
99
|
+
"@typescript-eslint/parser": "8.38.0",
|
|
100
|
+
"esbuild": "0.25.8",
|
|
101
|
+
"eslint": "9.32.0",
|
|
103
102
|
"node-forge": "1.3.1",
|
|
104
|
-
"prettier": "3.
|
|
103
|
+
"prettier": "3.6.2",
|
|
105
104
|
"prompts": "2.4.2",
|
|
106
105
|
"typescript": "5.8.3",
|
|
107
106
|
"uuid": "11.1.0"
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { createDirectoryIfNotExists } from "
|
|
2
|
-
import { sanitizeResourceName } from "
|
|
3
|
-
import { createDockerfile } from "
|
|
1
|
+
import { createDirectoryIfNotExists } from "../../lib/filesystemService";
|
|
2
|
+
import { sanitizeResourceName } from "../../sdk/sdk";
|
|
3
|
+
import { createDockerfile } from "../../lib/included-files";
|
|
4
4
|
import { execSync } from "child_process";
|
|
5
|
-
import { CapabilityExport } from "
|
|
6
|
-
import { validateCapabilityNames } from "
|
|
7
|
-
import { BuildOptions,
|
|
8
|
-
import { Assets } from "
|
|
5
|
+
import { CapabilityExport } from "../../lib/types";
|
|
6
|
+
import { validateCapabilityNames } from "../../lib/helpers";
|
|
7
|
+
import { BuildOptions, context, BuildContext } from "esbuild";
|
|
8
|
+
import { Assets } from "../../lib/assets/assets";
|
|
9
9
|
import { resolve } from "path";
|
|
10
10
|
import { promises as fs } from "fs";
|
|
11
|
-
import { generateAllYaml } from "
|
|
12
|
-
import { webhookConfigGenerator } from "
|
|
13
|
-
import { generateZarfYamlGeneric } from "
|
|
11
|
+
import { generateAllYaml } from "../../lib/assets/yaml/generateAllYaml";
|
|
12
|
+
import { webhookConfigGenerator } from "../../lib/assets/webhooks";
|
|
13
|
+
import { generateZarfYamlGeneric } from "../../lib/assets/yaml/generateZarfYaml";
|
|
14
14
|
import {
|
|
15
15
|
getDeployment,
|
|
16
16
|
getModuleSecret,
|
|
17
17
|
getWatcher,
|
|
18
18
|
service,
|
|
19
19
|
watcherService,
|
|
20
|
-
} from "
|
|
20
|
+
} from "../../lib/assets/k8sObjects";
|
|
21
|
+
import { Reloader } from "../types";
|
|
21
22
|
|
|
22
23
|
interface ImageOptions {
|
|
23
24
|
customImage?: string;
|
|
@@ -47,7 +48,6 @@ export function assignImage(imageOptions: ImageOptions): string {
|
|
|
47
48
|
return "";
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
export type Reloader = (opts: BuildResult<BuildOptions>) => void | Promise<void>;
|
|
51
51
|
/**
|
|
52
52
|
* Determine the RBAC mode based on the CLI options and the module's config
|
|
53
53
|
* @param opts CLI options
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
+
|
|
4
|
+
import { execFileSync } from "child_process";
|
|
5
|
+
import { BuildOptions, analyzeMetafile } from "esbuild";
|
|
6
|
+
import { basename, extname, resolve } from "path";
|
|
7
|
+
import { dependencies } from "../init/templates";
|
|
8
|
+
import { peprFormat } from "../format";
|
|
9
|
+
import { watchForChanges } from "./build.helpers";
|
|
10
|
+
import { PeprConfig, Reloader } from "../types";
|
|
11
|
+
import { BuildContext } from "esbuild";
|
|
12
|
+
import { loadModule } from "./loadModule";
|
|
13
|
+
|
|
14
|
+
type BuildModuleReturn = {
|
|
15
|
+
ctx: BuildContext<BuildOptions>;
|
|
16
|
+
path: string;
|
|
17
|
+
cfg: PeprConfig;
|
|
18
|
+
uuid: string;
|
|
19
|
+
};
|
|
20
|
+
// Create a list of external libraries to exclude from the bundle, these are already stored in the container
|
|
21
|
+
const externalLibs = Object.keys(dependencies);
|
|
22
|
+
|
|
23
|
+
// Add the pepr library to the list of external libraries
|
|
24
|
+
externalLibs.push("pepr");
|
|
25
|
+
|
|
26
|
+
// Add the kubernetes client to the list of external libraries as it is pulled in by kubernetes-fluent-client
|
|
27
|
+
externalLibs.push("@kubernetes/client-node");
|
|
28
|
+
|
|
29
|
+
export async function buildModule(
|
|
30
|
+
outputDir: string,
|
|
31
|
+
reloader?: Reloader,
|
|
32
|
+
entryPoint = "pepr.ts",
|
|
33
|
+
embed = true,
|
|
34
|
+
): Promise<BuildModuleReturn | void> {
|
|
35
|
+
try {
|
|
36
|
+
const { cfg, modulePath, path, uuid } = await loadModule(outputDir, entryPoint);
|
|
37
|
+
|
|
38
|
+
await checkFormat();
|
|
39
|
+
// Resolve node_modules folder (in support of npm workspaces!)
|
|
40
|
+
const npmRoot = execFileSync("npm", ["root"]).toString().trim();
|
|
41
|
+
|
|
42
|
+
// Run `tsc` to validate the module's types & output sourcemaps
|
|
43
|
+
const args = ["--project", `${modulePath}/tsconfig.json`, "--outdir", outputDir];
|
|
44
|
+
execFileSync(`${npmRoot}/.bin/tsc`, args);
|
|
45
|
+
|
|
46
|
+
// Common build options for all builds
|
|
47
|
+
const ctxCfg: BuildOptions = {
|
|
48
|
+
bundle: true,
|
|
49
|
+
entryPoints: [entryPoint],
|
|
50
|
+
external: externalLibs,
|
|
51
|
+
format: "cjs",
|
|
52
|
+
keepNames: true,
|
|
53
|
+
legalComments: "external",
|
|
54
|
+
metafile: true,
|
|
55
|
+
minify: true,
|
|
56
|
+
outfile: path,
|
|
57
|
+
plugins: [
|
|
58
|
+
{
|
|
59
|
+
name: "reload-server",
|
|
60
|
+
setup(build): void | Promise<void> {
|
|
61
|
+
build.onEnd(async r => {
|
|
62
|
+
// Print the build size analysis
|
|
63
|
+
if (r?.metafile) {
|
|
64
|
+
console.info(await analyzeMetafile(r.metafile));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// If we're in dev mode, call the reloader function
|
|
68
|
+
if (reloader) {
|
|
69
|
+
await reloader(r);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
platform: "node",
|
|
76
|
+
sourcemap: true,
|
|
77
|
+
treeShaking: true,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (reloader) {
|
|
81
|
+
// Only minify the code if we're not in dev mode
|
|
82
|
+
ctxCfg.minify = false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// If not embedding (i.e. making a library module to be distro'd via NPM)
|
|
86
|
+
if (!embed) {
|
|
87
|
+
// Don't minify
|
|
88
|
+
ctxCfg.minify = false;
|
|
89
|
+
|
|
90
|
+
// Preserve the original file name
|
|
91
|
+
ctxCfg.outfile = resolve(outputDir, basename(entryPoint, extname(entryPoint))) + ".js";
|
|
92
|
+
|
|
93
|
+
// Don't bundle
|
|
94
|
+
ctxCfg.packages = "external";
|
|
95
|
+
|
|
96
|
+
// Don't tree shake
|
|
97
|
+
ctxCfg.treeShaking = false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const ctx = await watchForChanges(ctxCfg, reloader);
|
|
101
|
+
|
|
102
|
+
return { ctx, path, cfg, uuid };
|
|
103
|
+
} catch (e) {
|
|
104
|
+
handleModuleBuildError(e);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface BuildModuleResult {
|
|
109
|
+
stdout?: Buffer;
|
|
110
|
+
stderr: Buffer;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function handleModuleBuildError(e: BuildModuleResult): void {
|
|
114
|
+
console.error(`Error building module:`, e);
|
|
115
|
+
|
|
116
|
+
if (!e.stdout) process.exit(1); // Exit with a non-zero exit code on any other error
|
|
117
|
+
|
|
118
|
+
const out = e.stdout.toString() as string;
|
|
119
|
+
const err = e.stderr.toString();
|
|
120
|
+
|
|
121
|
+
console.info(out);
|
|
122
|
+
console.error(err);
|
|
123
|
+
|
|
124
|
+
// Check for version conflicts
|
|
125
|
+
if (out.includes("Types have separate declarations of a private property '_name'.")) {
|
|
126
|
+
// Try to find the conflicting package
|
|
127
|
+
const pgkErrMatch = /error TS2322: .*? 'import\("\/.*?\/node_modules\/(.*?)\/node_modules/g;
|
|
128
|
+
out.matchAll(pgkErrMatch);
|
|
129
|
+
|
|
130
|
+
// Look for package conflict errors
|
|
131
|
+
const conflicts = [...out.matchAll(pgkErrMatch)];
|
|
132
|
+
|
|
133
|
+
// If the regex didn't match, leave a generic error
|
|
134
|
+
if (conflicts.length < 1) {
|
|
135
|
+
console.info(
|
|
136
|
+
`\n\tOne or more imported Pepr Capabilities seem to be using an incompatible version of Pepr.\n\tTry updating your Pepr Capabilities to their latest versions.`,
|
|
137
|
+
"Version Conflict",
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Otherwise, loop through each conflicting package and print an error
|
|
142
|
+
conflicts.forEach(match => {
|
|
143
|
+
console.info(
|
|
144
|
+
`\n\tPackage '${match[1]}' seems to be incompatible with your current version of Pepr.\n\tTry updating to the latest version.`,
|
|
145
|
+
"Version Conflict",
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function checkFormat(): Promise<void> {
|
|
152
|
+
const validFormat = await peprFormat(true);
|
|
153
|
+
|
|
154
|
+
if (!validFormat) {
|
|
155
|
+
console.info(
|
|
156
|
+
"\x1b[33m%s\x1b[0m",
|
|
157
|
+
"Formatting errors were found. The build will continue, but you may want to run `npx pepr format` to address any issues.",
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
+
|
|
4
|
+
import { Assets } from "../../lib/assets/assets";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { Option } from "commander";
|
|
7
|
+
import { parseTimeout } from "../../lib/helpers";
|
|
8
|
+
import {
|
|
9
|
+
determineRbacMode,
|
|
10
|
+
assignImage,
|
|
11
|
+
createOutputDirectory,
|
|
12
|
+
handleValidCapabilityNames,
|
|
13
|
+
handleCustomImageBuild,
|
|
14
|
+
validImagePullSecret,
|
|
15
|
+
generateYamlAndWriteToDisk,
|
|
16
|
+
} from "./build.helpers";
|
|
17
|
+
import { buildModule } from "./buildModule";
|
|
18
|
+
|
|
19
|
+
export default function (program: Command): void {
|
|
20
|
+
program
|
|
21
|
+
.command("build")
|
|
22
|
+
.description("Build a Pepr Module for deployment")
|
|
23
|
+
.addOption(
|
|
24
|
+
new Option("-M, --rbac-mode <mode>", "Override module config and set RBAC mode.").choices([
|
|
25
|
+
"admin",
|
|
26
|
+
"scoped",
|
|
27
|
+
]),
|
|
28
|
+
)
|
|
29
|
+
.addOption(
|
|
30
|
+
new Option(
|
|
31
|
+
"-I, --registry-info <registry/username>",
|
|
32
|
+
"Provide the image registry and username for building and pushing a custom WASM container. Requires authentication. Conflicts with --custom-image and --registry. Builds and pushes `'<registry/username>/custom-pepr-controller:<current-version>'`.",
|
|
33
|
+
).conflicts(["customImage", "registry"]),
|
|
34
|
+
)
|
|
35
|
+
.option("-P, --with-pull-secret <name>", "Use image pull secret for controller Deployment.", "")
|
|
36
|
+
.addOption(
|
|
37
|
+
new Option(
|
|
38
|
+
"-c, --custom-name <name>",
|
|
39
|
+
"Set name for zarf component and service monitors in helm charts.",
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
.option("-e, --entry-point <file>", "Specify the entry point file to build with.", "pepr.ts")
|
|
43
|
+
.addOption(
|
|
44
|
+
new Option(
|
|
45
|
+
"-i, --custom-image <image>",
|
|
46
|
+
"Specify a custom image with version for deployments. Conflicts with --registry-info and --registry. Example: 'docker.io/username/custom-pepr-controller:v1.0.0'",
|
|
47
|
+
).conflicts(["registryInfo", "registry"]),
|
|
48
|
+
)
|
|
49
|
+
.option(
|
|
50
|
+
"-n, --no-embed",
|
|
51
|
+
"Disable embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM.",
|
|
52
|
+
)
|
|
53
|
+
.option("-o, --output <directory>", "Set output directory.", "dist")
|
|
54
|
+
.addOption(
|
|
55
|
+
new Option(
|
|
56
|
+
"-r, --registry <GitHub|Iron Bank>",
|
|
57
|
+
"Container registry: Choose container registry for deployment manifests. Conflicts with --custom-image and --registry-info.",
|
|
58
|
+
)
|
|
59
|
+
.conflicts(["customImage", "registryInfo"])
|
|
60
|
+
.choices(["GitHub", "Iron Bank"]),
|
|
61
|
+
)
|
|
62
|
+
.option(
|
|
63
|
+
"-t, --timeout <seconds>",
|
|
64
|
+
"How long the API server should wait for a webhook to respond before treating the call as a failure.",
|
|
65
|
+
parseTimeout,
|
|
66
|
+
)
|
|
67
|
+
.addOption(
|
|
68
|
+
new Option("-z, --zarf <manifest|chart>", "Set Zarf package type")
|
|
69
|
+
.choices(["manifest", "chart"])
|
|
70
|
+
.default("manifest"),
|
|
71
|
+
)
|
|
72
|
+
.action(async opts => {
|
|
73
|
+
const outputDir = await createOutputDirectory(opts.output);
|
|
74
|
+
|
|
75
|
+
// Build the module
|
|
76
|
+
const buildModuleResult = await buildModule(
|
|
77
|
+
outputDir,
|
|
78
|
+
undefined,
|
|
79
|
+
opts.entryPoint,
|
|
80
|
+
opts.embed,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const { cfg, path } = buildModuleResult!;
|
|
84
|
+
// override the name if provided
|
|
85
|
+
if (opts.customName) {
|
|
86
|
+
process.env.PEPR_CUSTOM_BUILD_NAME = opts.customName;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const image = assignImage({
|
|
90
|
+
customImage: opts.customImage,
|
|
91
|
+
registryInfo: opts.registryInfo,
|
|
92
|
+
peprVersion: cfg.pepr.peprVersion,
|
|
93
|
+
registry: opts.registry,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Check if there is a custom timeout defined
|
|
97
|
+
if (opts.timeout !== undefined) {
|
|
98
|
+
cfg.pepr.webhookTimeout = opts.timeout;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (opts.registryInfo !== undefined) {
|
|
102
|
+
console.info(`Including ${cfg.pepr.includedFiles.length} files in controller image.`);
|
|
103
|
+
// for journey test to make sure the image is built
|
|
104
|
+
|
|
105
|
+
// only actually build/push if there are files to include
|
|
106
|
+
await handleCustomImageBuild(
|
|
107
|
+
cfg.pepr.includedFiles,
|
|
108
|
+
cfg.pepr.peprVersion,
|
|
109
|
+
cfg.description,
|
|
110
|
+
image,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// If building without embedding, exit after building
|
|
115
|
+
if (!opts.embed) {
|
|
116
|
+
console.info(`Module built successfully at ${path}`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Generate a secret for the module
|
|
121
|
+
const assets = new Assets(
|
|
122
|
+
{
|
|
123
|
+
...cfg.pepr,
|
|
124
|
+
appVersion: cfg.version,
|
|
125
|
+
description: cfg.description,
|
|
126
|
+
alwaysIgnore: {
|
|
127
|
+
namespaces: cfg.pepr.alwaysIgnore?.namespaces,
|
|
128
|
+
},
|
|
129
|
+
// Can override the rbacMode with the CLI option
|
|
130
|
+
rbacMode: determineRbacMode(opts, cfg),
|
|
131
|
+
},
|
|
132
|
+
path,
|
|
133
|
+
opts.withPullSecret === "" ? [] : [opts.withPullSecret],
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (image !== "") assets.image = image;
|
|
137
|
+
|
|
138
|
+
// Ensure imagePullSecret is valid
|
|
139
|
+
validImagePullSecret(opts.withPullSecret);
|
|
140
|
+
|
|
141
|
+
handleValidCapabilityNames(assets.capabilities);
|
|
142
|
+
await generateYamlAndWriteToDisk({
|
|
143
|
+
uuid: cfg.pepr.uuid,
|
|
144
|
+
outputDir,
|
|
145
|
+
imagePullSecret: opts.withPullSecret,
|
|
146
|
+
zarf: opts.zarf,
|
|
147
|
+
assets,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import { resolve, dirname } from "path/posix";
|
|
3
|
+
import { version } from "../init/templates";
|
|
4
|
+
import { PeprConfig } from "../types";
|
|
5
|
+
|
|
6
|
+
export type LoadModuleReturn = {
|
|
7
|
+
cfg: PeprConfig;
|
|
8
|
+
entryPointPath: string;
|
|
9
|
+
modulePath: string;
|
|
10
|
+
name: string;
|
|
11
|
+
path: string;
|
|
12
|
+
uuid: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export async function loadModule(outputDir: string, entryPoint: string): Promise<LoadModuleReturn> {
|
|
16
|
+
// Resolve path to the module / files
|
|
17
|
+
const entryPointPath = resolve(".", entryPoint);
|
|
18
|
+
const modulePath = dirname(entryPointPath);
|
|
19
|
+
const cfgPath = resolve(modulePath, "package.json");
|
|
20
|
+
|
|
21
|
+
// Ensure the module's package.json and entrypoint files exist
|
|
22
|
+
try {
|
|
23
|
+
await fs.access(cfgPath);
|
|
24
|
+
await fs.access(entryPointPath);
|
|
25
|
+
} catch {
|
|
26
|
+
console.error(
|
|
27
|
+
`Could not find ${cfgPath} or ${entryPointPath} in the current directory. Please run this command from the root of your module's directory.`,
|
|
28
|
+
);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Read the module's UUID from the package.json file
|
|
33
|
+
const moduleText = await fs.readFile(cfgPath, { encoding: "utf-8" });
|
|
34
|
+
const cfg = JSON.parse(moduleText);
|
|
35
|
+
const { uuid } = cfg.pepr;
|
|
36
|
+
const name = `pepr-${uuid}.js`;
|
|
37
|
+
|
|
38
|
+
// Set the Pepr version from the current running version
|
|
39
|
+
cfg.pepr.peprVersion = version;
|
|
40
|
+
|
|
41
|
+
// Exit if the module's UUID could not be found
|
|
42
|
+
if (!uuid) {
|
|
43
|
+
throw new Error("Could not load the uuid in package.json");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
cfg,
|
|
48
|
+
entryPointPath,
|
|
49
|
+
modulePath,
|
|
50
|
+
name,
|
|
51
|
+
path: resolve(outputDir, name),
|
|
52
|
+
uuid,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -16,7 +16,7 @@ import { kind as k } from "kubernetes-fluent-client";
|
|
|
16
16
|
import { V1JSONSchemaProps } from "@kubernetes/client-node";
|
|
17
17
|
import { WarningMessages, ErrorMessages } from "./messages";
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
function extractCRDDetails(
|
|
20
20
|
content: string,
|
|
21
21
|
sourceFile: SourceFile,
|
|
22
22
|
): {
|
|
@@ -145,7 +145,7 @@ export function extractDetails(sourceFile: SourceFile): {
|
|
|
145
145
|
throw new Error(ErrorMessages.INVALID_SCOPE(scope));
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
function getJsDocDescription(node: Node): string {
|
|
149
149
|
if (!Node.isPropertySignature(node) && !Node.isPropertyDeclaration(node)) return "";
|
|
150
150
|
return node
|
|
151
151
|
.getJsDocs()
|
|
@@ -155,7 +155,7 @@ export function getJsDocDescription(node: Node): string {
|
|
|
155
155
|
.trim();
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
function getSchemaFromType(decl: InterfaceDeclaration | TypeAliasDeclaration): {
|
|
159
159
|
properties: Record<string, V1JSONSchemaProps>;
|
|
160
160
|
required: string[];
|
|
161
161
|
} {
|
|
@@ -183,7 +183,7 @@ export function getSchemaFromType(decl: InterfaceDeclaration | TypeAliasDeclarat
|
|
|
183
183
|
return { properties, required };
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
function mapTypeToSchema(type: Type): V1JSONSchemaProps {
|
|
187
187
|
if (type.getText() === "Date") return { type: "string", format: "date-time" };
|
|
188
188
|
if (type.isString()) return { type: "string" };
|
|
189
189
|
if (type.isNumber()) return { type: "number" };
|
|
@@ -199,7 +199,7 @@ export function mapTypeToSchema(type: Type): V1JSONSchemaProps {
|
|
|
199
199
|
return { type: "string" };
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
function buildObjectSchema(type: Type): V1JSONSchemaProps {
|
|
203
203
|
const props: Record<string, V1JSONSchemaProps> = {};
|
|
204
204
|
const required: string[] = [];
|
|
205
205
|
|
|
@@ -249,7 +249,7 @@ interface CRDConfig {
|
|
|
249
249
|
conditionSchema: ReturnType<typeof getSchemaFromType>;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
|
|
252
|
+
function buildCRD(config: CRDConfig): k.CustomResourceDefinition {
|
|
253
253
|
return {
|
|
254
254
|
apiVersion: "apiextensions.k8s.io/v1",
|
|
255
255
|
kind: "CustomResourceDefinition",
|
package/src/cli/deploy.ts
CHANGED
|
@@ -6,14 +6,15 @@ import { CapabilityExport } from "../lib/types";
|
|
|
6
6
|
import { Assets } from "../lib/assets/assets";
|
|
7
7
|
import { ImagePullSecret } from "../lib/types";
|
|
8
8
|
import { Command } from "commander";
|
|
9
|
-
import { buildModule } from "./build";
|
|
9
|
+
import { buildModule } from "./build/buildModule";
|
|
10
10
|
import { deployImagePullSecret, deployWebhook } from "../lib/assets/deploy";
|
|
11
11
|
import { namespaceDeploymentsReady } from "../lib/deploymentChecks";
|
|
12
12
|
import { sanitizeName } from "./init/utils";
|
|
13
13
|
import { validateCapabilityNames } from "../lib/helpers";
|
|
14
14
|
import { namespaceComplianceValidator } from "../lib/helpers";
|
|
15
15
|
import { loadCapabilities } from "../lib/assets/loader";
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
interface ImagePullSecretDetails {
|
|
17
18
|
pullSecret?: string;
|
|
18
19
|
dockerServer?: string;
|
|
19
20
|
dockerUsername?: string;
|
|
@@ -61,7 +62,7 @@ export function validateImagePullSecretDetails(details: ImagePullSecretDetails):
|
|
|
61
62
|
return { valid: true };
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
type ValidatedImagePullSecretDetails = Required<ImagePullSecretDetails>;
|
|
65
66
|
|
|
66
67
|
function generateImagePullSecret(details: ValidatedImagePullSecretDetails): ImagePullSecret {
|
|
67
68
|
const auth = Buffer.from(`${details.dockerUsername}:${details.dockerPassword}`).toString(
|
|
@@ -95,7 +96,7 @@ export async function getUserConfirmation(opts: { yes: boolean }): Promise<boole
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
async function buildAndDeployModule(image: string, force: boolean): Promise<void> {
|
|
98
|
-
const builtModule = await buildModule();
|
|
99
|
+
const builtModule = await buildModule("dist");
|
|
99
100
|
if (!builtModule) {
|
|
100
101
|
return;
|
|
101
102
|
}
|
package/src/cli/dev.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { ChildProcess, fork } from "child_process";
|
|
|
7
7
|
import { K8s, kind } from "kubernetes-fluent-client";
|
|
8
8
|
import { Command } from "commander";
|
|
9
9
|
import { Store } from "../lib/k8s";
|
|
10
|
-
import { buildModule
|
|
10
|
+
import { buildModule } from "./build/buildModule";
|
|
11
|
+
import { loadModule } from "./build/loadModule";
|
|
11
12
|
import { deployWebhook } from "../lib/assets/deploy";
|
|
12
13
|
import { promises as fs } from "fs";
|
|
13
14
|
import { validateCapabilityNames } from "../lib/helpers";
|
|
@@ -35,7 +36,7 @@ export default function (program: Command): void {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// Build the module
|
|
38
|
-
const { cfg, path } = await loadModule();
|
|
39
|
+
const { cfg, path } = await loadModule("dist", "pepr.ts");
|
|
39
40
|
|
|
40
41
|
// Generate a secret for the module
|
|
41
42
|
const webhook = new Assets(
|
|
@@ -103,7 +104,7 @@ export default function (program: Command): void {
|
|
|
103
104
|
});
|
|
104
105
|
};
|
|
105
106
|
|
|
106
|
-
await buildModule(async r => {
|
|
107
|
+
await buildModule("dist", async r => {
|
|
107
108
|
if (r.errors.length > 0) {
|
|
108
109
|
console.error(`Error compiling module: ${r.errors}`);
|
|
109
110
|
return;
|
package/src/cli/monitor.ts
CHANGED
|
@@ -81,7 +81,7 @@ export function getK8sLogFromKubeConfig(): K8sLog {
|
|
|
81
81
|
return new K8sLog(kc);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
function createLogStream(): stream.PassThrough {
|
|
84
|
+
export function createLogStream(): stream.PassThrough {
|
|
85
85
|
const logStream = new stream.PassThrough();
|
|
86
86
|
|
|
87
87
|
logStream.on("data", async chunk => {
|
|
@@ -97,7 +97,7 @@ function createLogStream(): stream.PassThrough {
|
|
|
97
97
|
return logStream;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
function processLogLine(line: string): void {
|
|
100
|
+
export function processLogLine(line: string): void {
|
|
101
101
|
try {
|
|
102
102
|
const payload: LogPayload = JSON.parse(line.trim());
|
|
103
103
|
const isMutate = payload.res.patchType || payload.res.warnings;
|
package/src/cli/types.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
import { BuildResult, BuildOptions } from "esbuild";
|
|
1
2
|
import { Answers } from "prompts";
|
|
3
|
+
import { ModuleConfig } from "../lib/types";
|
|
2
4
|
|
|
3
5
|
export type InitOptions = Answers<"name" | "description" | "errorBehavior" | "uuid">;
|
|
6
|
+
|
|
7
|
+
export type Reloader = (opts: BuildResult<BuildOptions>) => void | Promise<void>;
|
|
8
|
+
|
|
9
|
+
export type PeprConfig = Omit<ModuleConfig, keyof PeprNestedFields> & {
|
|
10
|
+
pepr: PeprNestedFields & {
|
|
11
|
+
includedFiles: string[];
|
|
12
|
+
};
|
|
13
|
+
description: string;
|
|
14
|
+
version: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type PeprNestedFields = Pick<
|
|
18
|
+
ModuleConfig,
|
|
19
|
+
| "uuid"
|
|
20
|
+
| "onError"
|
|
21
|
+
| "webhookTimeout"
|
|
22
|
+
| "customLabels"
|
|
23
|
+
| "alwaysIgnore"
|
|
24
|
+
| "env"
|
|
25
|
+
| "rbac"
|
|
26
|
+
| "rbacMode"
|
|
27
|
+
> & {
|
|
28
|
+
peprVersion: string;
|
|
29
|
+
};
|
package/src/cli/uuid.ts
CHANGED
|
@@ -13,12 +13,11 @@ export default function (program: Command): void {
|
|
|
13
13
|
const deployments = await getPeprDeploymentsByUUID(uuid);
|
|
14
14
|
const uuidTable = buildUUIDTable(deployments);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
16
|
+
const uuidTableEntries = Object.entries(uuidTable).map(([uuid, description]) => ({
|
|
17
|
+
UUID: uuid,
|
|
18
|
+
Description: description,
|
|
19
|
+
}));
|
|
20
|
+
console.table(uuidTableEntries);
|
|
22
21
|
});
|
|
23
22
|
}
|
|
24
23
|
|
package/src/lib/assets/deploy.ts
CHANGED
|
@@ -100,7 +100,7 @@ export async function deployWebhook(
|
|
|
100
100
|
// Create the validating webhook configuration if it is needed
|
|
101
101
|
await handleWebhookConfiguration(assets, WebhookType.VALIDATE, webhookTimeout, force);
|
|
102
102
|
|
|
103
|
-
Log.
|
|
103
|
+
Log.debug("Applying the Pepr Store CRD if it doesn't exist");
|
|
104
104
|
await K8s(kind.CustomResourceDefinition).Apply(peprStoreCRD, { force });
|
|
105
105
|
|
|
106
106
|
if (assets.host) return; // Skip resource deployment if a host is already specified
|