pepr 0.52.1 → 0.52.2-nightly.1
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.d.ts +4 -5
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.helpers.d.ts +2 -2
- package/dist/cli/build.helpers.d.ts.map +1 -1
- package/dist/cli/crd/create/createCRDscaffold.d.ts +7 -0
- package/dist/cli/crd/create/createCRDscaffold.d.ts.map +1 -0
- package/dist/cli/crd/create/index.d.ts +3 -0
- package/dist/cli/crd/create/index.d.ts.map +1 -0
- package/dist/cli/crd/generate/generators.d.ts +20 -0
- package/dist/cli/crd/generate/generators.d.ts.map +1 -0
- package/dist/cli/crd/generate/index.d.ts +3 -0
- package/dist/cli/crd/generate/index.d.ts.map +1 -0
- package/dist/cli/crd/generate/messages.d.ts.map +1 -0
- package/dist/cli/crd/index.d.ts +1 -1
- package/dist/cli/crd/index.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/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +1 -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 +2 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts +4 -0
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +175 -170
- package/dist/controller.js +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.map +2 -2
- package/package.json +3 -3
- package/src/cli/build.helpers.ts +2 -2
- package/src/cli/build.ts +5 -5
- package/src/cli/crd/{create.ts → create/createCRDscaffold.ts} +1 -38
- package/src/cli/crd/create/index.ts +41 -0
- package/src/cli/crd/{generate.ts → generate/generators.ts} +8 -19
- package/src/cli/crd/generate/index.ts +14 -0
- package/src/cli/crd/{messages.ts → generate/messages.ts} +3 -0
- package/src/cli/crd/index.ts +7 -9
- package/src/cli/deploy.ts +3 -2
- package/src/cli/format/index.ts +3 -3
- package/src/cli/init/index.ts +4 -19
- package/src/cli/init/templates.ts +4 -9
- package/src/cli/monitor.ts +2 -2
- package/src/cli/types.ts +3 -0
- package/src/cli/uuid.ts +40 -23
- package/src/cli.ts +1 -1
- package/src/lib/assets/yaml/generateAllYaml.ts +1 -1
- 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/dist/cli/crd/create.d.ts +0 -10
- package/dist/cli/crd/create.d.ts.map +0 -1
- package/dist/cli/crd/generate.d.ts +0 -49
- package/dist/cli/crd/generate.d.ts.map +0 -1
- package/dist/cli/crd/messages.d.ts.map +0 -1
- /package/dist/cli/crd/{messages.d.ts → generate/messages.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"!src/fixtures/**",
|
|
17
17
|
"!dist/**/*.test.d.ts*"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.52.1",
|
|
19
|
+
"version": "0.52.2-nightly.1",
|
|
20
20
|
"main": "dist/lib.js",
|
|
21
21
|
"types": "dist/lib.d.ts",
|
|
22
22
|
"scripts": {
|
|
@@ -62,7 +62,7 @@
|
|
|
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.9.0",
|
|
66
66
|
"pino": "9.7.0",
|
|
67
67
|
"pino-pretty": "13.0.0",
|
|
68
68
|
"prom-client": "15.1.3",
|
|
@@ -106,4 +106,4 @@
|
|
|
106
106
|
"typescript": "5.8.3",
|
|
107
107
|
"uuid": "11.1.0"
|
|
108
108
|
}
|
|
109
|
-
}
|
|
109
|
+
}
|
package/src/cli/build.helpers.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { createDockerfile } from "../lib/included-files";
|
|
|
4
4
|
import { execSync } from "child_process";
|
|
5
5
|
import { CapabilityExport } from "../lib/types";
|
|
6
6
|
import { validateCapabilityNames } from "../lib/helpers";
|
|
7
|
-
import { BuildOptions,
|
|
7
|
+
import { BuildOptions, context, BuildContext } from "esbuild";
|
|
8
8
|
import { Assets } from "../lib/assets/assets";
|
|
9
9
|
import { resolve } from "path";
|
|
10
10
|
import { promises as fs } from "fs";
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
service,
|
|
19
19
|
watcherService,
|
|
20
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
|
package/src/cli/build.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
|
|
4
4
|
import { execFileSync } from "child_process";
|
|
5
|
-
import { BuildContext, BuildOptions,
|
|
5
|
+
import { BuildContext, BuildOptions, analyzeMetafile } from "esbuild";
|
|
6
6
|
import { promises as fs } from "fs";
|
|
7
7
|
import { basename, dirname, extname, resolve } from "path";
|
|
8
8
|
import { Assets } from "../lib/assets/assets";
|
|
@@ -22,11 +22,11 @@ import {
|
|
|
22
22
|
validImagePullSecret,
|
|
23
23
|
generateYamlAndWriteToDisk,
|
|
24
24
|
} from "./build.helpers";
|
|
25
|
+
import { Reloader } from "./types";
|
|
25
26
|
|
|
26
27
|
const peprTS = "pepr.ts";
|
|
27
28
|
let outputDir: string = "dist";
|
|
28
|
-
|
|
29
|
-
export type PeprNestedFields = Pick<
|
|
29
|
+
type PeprNestedFields = Pick<
|
|
30
30
|
ModuleConfig,
|
|
31
31
|
| "uuid"
|
|
32
32
|
| "onError"
|
|
@@ -40,7 +40,7 @@ export type PeprNestedFields = Pick<
|
|
|
40
40
|
peprVersion: string;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
type PeprConfig = Omit<ModuleConfig, keyof PeprNestedFields> & {
|
|
44
44
|
pepr: PeprNestedFields & {
|
|
45
45
|
includedFiles: string[];
|
|
46
46
|
};
|
|
@@ -363,7 +363,7 @@ function handleModuleBuildError(e: BuildModuleResult): void {
|
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
|
|
366
|
+
async function checkFormat(): Promise<void> {
|
|
367
367
|
const validFormat = await peprFormat(true);
|
|
368
368
|
|
|
369
369
|
if (!validFormat) {
|
|
@@ -1,44 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
import { createDirectoryIfNotExists } from "../../lib/filesystemService";
|
|
6
|
-
import { promises as fs } from "fs";
|
|
7
|
-
import path from "path";
|
|
8
|
-
|
|
9
|
-
// Scaffolds a new CRD TypeScript definition
|
|
10
|
-
const create = new Command("create")
|
|
11
|
-
.description("Create a new CRD TypeScript definition")
|
|
12
|
-
.addOption(
|
|
13
|
-
new Option(
|
|
14
|
-
"-S, --scope <scope>",
|
|
15
|
-
"Whether the resulting custom resource is cluster- or namespace-scoped",
|
|
16
|
-
)
|
|
17
|
-
.choices(["Namespaced", "Cluster"])
|
|
18
|
-
.default("Namespaced"),
|
|
19
|
-
)
|
|
20
|
-
.option("-d, --domain <domain>", "Optional domain for CRD (e.g. pepr.dev)", "pepr.dev")
|
|
21
|
-
.requiredOption("-g, --group <group>", "API group (e.g. cache)")
|
|
22
|
-
.requiredOption("-k, --kind <kind>", "Kind name (e.g. memcached)")
|
|
23
|
-
.option("-p, --plural <plural>", "Plural name for CRD (e.g. memcacheds)")
|
|
24
|
-
.requiredOption("-s, --short-name <name>", "Short name for CRD (e.g. mc)", "")
|
|
25
|
-
.requiredOption("-v, --version <version>", "API version (e.g. v1alpha1)")
|
|
26
|
-
.action(async ({ group, version, kind, domain, scope, plural, shortName }) => {
|
|
27
|
-
console.log("This feature is currently in alpha.");
|
|
28
|
-
const outputDir = path.resolve(`./api/${version}`);
|
|
29
|
-
await createDirectoryIfNotExists(outputDir);
|
|
30
|
-
|
|
31
|
-
// create file in directory with kind
|
|
32
|
-
await fs.writeFile(
|
|
33
|
-
`./api/${version}/${kind.toLowerCase()}_types.ts`,
|
|
34
|
-
generateCRDScaffold(group, version, kind, { domain, scope, plural, shortName }),
|
|
35
|
-
);
|
|
36
|
-
console.log(`✔ Created ${kind} TypeScript definition in ${outputDir}`);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
export default create;
|
|
40
|
-
|
|
41
|
-
export const generateCRDScaffold = (
|
|
4
|
+
export const createCRDscaffold = (
|
|
42
5
|
group: string,
|
|
43
6
|
version: string,
|
|
44
7
|
kind: string,
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
+
|
|
4
|
+
import { Command, Option } from "commander";
|
|
5
|
+
import { createDirectoryIfNotExists } from "../../../lib/filesystemService";
|
|
6
|
+
import { promises as fs } from "fs";
|
|
7
|
+
import Log from "../../../lib/telemetry/logger";
|
|
8
|
+
import { createCRDscaffold } from "./createCRDscaffold";
|
|
9
|
+
import path from "path";
|
|
10
|
+
|
|
11
|
+
// Scaffolds a new CRD TypeScript definition
|
|
12
|
+
export default function (): Command {
|
|
13
|
+
return new Command("create")
|
|
14
|
+
.description("Create a new CRD TypeScript definition")
|
|
15
|
+
.addOption(
|
|
16
|
+
new Option(
|
|
17
|
+
"-S, --scope <scope>",
|
|
18
|
+
"Whether the resulting custom resource is cluster- or namespace-scoped",
|
|
19
|
+
)
|
|
20
|
+
.choices(["Namespaced", "Cluster"])
|
|
21
|
+
.default("Namespaced"),
|
|
22
|
+
)
|
|
23
|
+
.option("-d, --domain <domain>", "Optional domain for CRD (e.g. pepr.dev)", "pepr.dev")
|
|
24
|
+
.requiredOption("-g, --group <group>", "API group (e.g. cache)")
|
|
25
|
+
.requiredOption("-k, --kind <kind>", "Kind name (e.g. memcached)")
|
|
26
|
+
.option("-p, --plural <plural>", "Plural name for CRD (e.g. memcacheds)")
|
|
27
|
+
.requiredOption("-s, --short-name <name>", "Short name for CRD (e.g. mc)")
|
|
28
|
+
.requiredOption("-v, --version <version>", "API version (e.g. v1alpha1)")
|
|
29
|
+
.action(async ({ group, version, kind, domain, scope, plural, shortName }) => {
|
|
30
|
+
Log.warn("This feature is currently in alpha.");
|
|
31
|
+
const outputDir = path.resolve(`./api/${version}`);
|
|
32
|
+
await createDirectoryIfNotExists(outputDir);
|
|
33
|
+
|
|
34
|
+
// create file in directory with kind
|
|
35
|
+
await fs.writeFile(
|
|
36
|
+
`./api/${version}/${kind.toLowerCase()}_types.ts`,
|
|
37
|
+
createCRDscaffold(group, version, kind, { domain, scope, plural, shortName }),
|
|
38
|
+
);
|
|
39
|
+
Log.info(`✔ Created ${kind} TypeScript definition in ${outputDir}`);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
-
|
|
4
|
-
import { Command } from "commander";
|
|
5
1
|
import fs from "fs";
|
|
6
2
|
import path from "path";
|
|
7
|
-
import Log from "
|
|
3
|
+
import Log from "../../../lib/telemetry/logger";
|
|
8
4
|
import { stringify } from "yaml";
|
|
9
5
|
import {
|
|
10
6
|
Project,
|
|
@@ -15,19 +11,12 @@ import {
|
|
|
15
11
|
SourceFile,
|
|
16
12
|
Type,
|
|
17
13
|
} from "ts-morph";
|
|
18
|
-
import { createDirectoryIfNotExists } from "
|
|
14
|
+
import { createDirectoryIfNotExists } from "../../../lib/filesystemService";
|
|
19
15
|
import { kind as k } from "kubernetes-fluent-client";
|
|
20
16
|
import { V1JSONSchemaProps } from "@kubernetes/client-node";
|
|
21
17
|
import { WarningMessages, ErrorMessages } from "./messages";
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
.description(
|
|
25
|
-
"Generate CRD manifests from TypeScript definitions stored in 'api/' of the current directory.",
|
|
26
|
-
)
|
|
27
|
-
.option("-o, --output <directory>", "Output directory for generated CRDs", "./crds")
|
|
28
|
-
.action(generateCRDs);
|
|
29
|
-
|
|
30
|
-
export function extractCRDDetails(
|
|
19
|
+
function extractCRDDetails(
|
|
31
20
|
content: string,
|
|
32
21
|
sourceFile: SourceFile,
|
|
33
22
|
): {
|
|
@@ -156,7 +145,7 @@ export function extractDetails(sourceFile: SourceFile): {
|
|
|
156
145
|
throw new Error(ErrorMessages.INVALID_SCOPE(scope));
|
|
157
146
|
}
|
|
158
147
|
|
|
159
|
-
|
|
148
|
+
function getJsDocDescription(node: Node): string {
|
|
160
149
|
if (!Node.isPropertySignature(node) && !Node.isPropertyDeclaration(node)) return "";
|
|
161
150
|
return node
|
|
162
151
|
.getJsDocs()
|
|
@@ -166,7 +155,7 @@ export function getJsDocDescription(node: Node): string {
|
|
|
166
155
|
.trim();
|
|
167
156
|
}
|
|
168
157
|
|
|
169
|
-
|
|
158
|
+
function getSchemaFromType(decl: InterfaceDeclaration | TypeAliasDeclaration): {
|
|
170
159
|
properties: Record<string, V1JSONSchemaProps>;
|
|
171
160
|
required: string[];
|
|
172
161
|
} {
|
|
@@ -194,7 +183,7 @@ export function getSchemaFromType(decl: InterfaceDeclaration | TypeAliasDeclarat
|
|
|
194
183
|
return { properties, required };
|
|
195
184
|
}
|
|
196
185
|
|
|
197
|
-
|
|
186
|
+
function mapTypeToSchema(type: Type): V1JSONSchemaProps {
|
|
198
187
|
if (type.getText() === "Date") return { type: "string", format: "date-time" };
|
|
199
188
|
if (type.isString()) return { type: "string" };
|
|
200
189
|
if (type.isNumber()) return { type: "number" };
|
|
@@ -210,7 +199,7 @@ export function mapTypeToSchema(type: Type): V1JSONSchemaProps {
|
|
|
210
199
|
return { type: "string" };
|
|
211
200
|
}
|
|
212
201
|
|
|
213
|
-
|
|
202
|
+
function buildObjectSchema(type: Type): V1JSONSchemaProps {
|
|
214
203
|
const props: Record<string, V1JSONSchemaProps> = {};
|
|
215
204
|
const required: string[] = [];
|
|
216
205
|
|
|
@@ -260,7 +249,7 @@ interface CRDConfig {
|
|
|
260
249
|
conditionSchema: ReturnType<typeof getSchemaFromType>;
|
|
261
250
|
}
|
|
262
251
|
|
|
263
|
-
|
|
252
|
+
function buildCRD(config: CRDConfig): k.CustomResourceDefinition {
|
|
264
253
|
return {
|
|
265
254
|
apiVersion: "apiextensions.k8s.io/v1",
|
|
266
255
|
kind: "CustomResourceDefinition",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
+
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { generateCRDs } from "./generators";
|
|
6
|
+
|
|
7
|
+
export default function (): Command {
|
|
8
|
+
return new Command("generate")
|
|
9
|
+
.description(
|
|
10
|
+
"Generate CRD manifests from TypeScript definitions stored in 'api/' of the current directory.",
|
|
11
|
+
)
|
|
12
|
+
.option("-o, --output <directory>", "Output directory for generated CRDs", "./crds")
|
|
13
|
+
.action(options => generateCRDs(options));
|
|
14
|
+
}
|
package/src/cli/crd/index.ts
CHANGED
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import generate from "./generate/";
|
|
6
|
+
import create from "./create";
|
|
7
7
|
|
|
8
|
-
export default function (
|
|
9
|
-
|
|
10
|
-
.
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
crd.addCommand(createCmd);
|
|
14
|
-
crd.addCommand(generateCmd);
|
|
8
|
+
export default function (): Command {
|
|
9
|
+
return new Command("crd")
|
|
10
|
+
.description("Scaffold and generate Kubernetes CRDs from structured TypeScript definitions")
|
|
11
|
+
.addCommand(create())
|
|
12
|
+
.addCommand(generate());
|
|
15
13
|
}
|
package/src/cli/deploy.ts
CHANGED
|
@@ -13,7 +13,8 @@ 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(
|
package/src/cli/format/index.ts
CHANGED
|
@@ -16,7 +16,7 @@ export default function (program: Command): void {
|
|
|
16
16
|
const success = await peprFormat(opts.validateOnly);
|
|
17
17
|
|
|
18
18
|
if (success) {
|
|
19
|
-
|
|
19
|
+
Log.info("Module formatted");
|
|
20
20
|
} else {
|
|
21
21
|
process.exit(1);
|
|
22
22
|
}
|
|
@@ -59,8 +59,8 @@ export async function peprFormat(validateOnly: boolean): Promise<boolean> {
|
|
|
59
59
|
hasFailure = hasFailure || (await formatWithPrettier(results, validateOnly));
|
|
60
60
|
|
|
61
61
|
return !hasFailure;
|
|
62
|
-
} catch (
|
|
63
|
-
|
|
62
|
+
} catch (error) {
|
|
63
|
+
Log.error(error, `Error formatting module:`);
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
}
|
package/src/cli/init/index.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { execSync } from "child_process";
|
|
5
5
|
import { resolve } from "path";
|
|
6
|
-
import prompts from "prompts";
|
|
7
6
|
|
|
8
7
|
import { Command } from "commander";
|
|
9
8
|
import {
|
|
@@ -28,7 +27,7 @@ import { Option } from "commander";
|
|
|
28
27
|
|
|
29
28
|
export default function (program: Command): void {
|
|
30
29
|
let response = {} as PromptOptions;
|
|
31
|
-
|
|
30
|
+
|
|
32
31
|
program
|
|
33
32
|
.command("init")
|
|
34
33
|
.description("Initialize a new Pepr Module")
|
|
@@ -50,26 +49,12 @@ export default function (program: Command): void {
|
|
|
50
49
|
)
|
|
51
50
|
.option("-y, --yes", "Skip verification prompt when creating a new module.")
|
|
52
51
|
.hook("preAction", async thisCommand => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (process.env.TEST_MODE === "true") {
|
|
56
|
-
prompts.inject([
|
|
57
|
-
"pepr-test-module",
|
|
58
|
-
"A test module for Pepr",
|
|
59
|
-
"ignore",
|
|
60
|
-
"static-test",
|
|
61
|
-
"y",
|
|
62
|
-
]);
|
|
63
|
-
pkgOverride = "file:../pepr-0.0.0-development.tgz";
|
|
64
|
-
response = await walkthrough();
|
|
65
|
-
} else {
|
|
66
|
-
response = await walkthrough(thisCommand.opts());
|
|
67
|
-
Object.entries(response).map(([key, value]) => thisCommand.setOptionValue(key, value));
|
|
68
|
-
}
|
|
52
|
+
response = await walkthrough(thisCommand.opts());
|
|
53
|
+
Object.entries(response).map(([key, value]) => thisCommand.setOptionValue(key, value));
|
|
69
54
|
})
|
|
70
55
|
.action(async opts => {
|
|
71
56
|
const dirName = sanitizeName(response.name);
|
|
72
|
-
const packageJSON = genPkgJSON(response
|
|
57
|
+
const packageJSON = genPkgJSON(response);
|
|
73
58
|
|
|
74
59
|
const confirmed = await confirm(dirName, packageJSON, peprTSTemplate.path, opts.yes);
|
|
75
60
|
|
|
@@ -49,7 +49,7 @@ export type peprPackageJSON = {
|
|
|
49
49
|
print: string;
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
export function genPkgJSON(opts: InitOptions
|
|
52
|
+
export function genPkgJSON(opts: InitOptions): peprPackageJSON {
|
|
53
53
|
// Generate a random UUID for the module based on the module name if it is not provided
|
|
54
54
|
const uuid = !opts.uuid ? uuidv4() : opts.uuid;
|
|
55
55
|
// Generate a name for the module based on the module name
|
|
@@ -57,11 +57,6 @@ export function genPkgJSON(opts: InitOptions, pgkVerOverride?: string): peprPack
|
|
|
57
57
|
// Make typescript a dev dependency
|
|
58
58
|
const { typescript } = peerDependencies;
|
|
59
59
|
|
|
60
|
-
const testEnv = {
|
|
61
|
-
MY_CUSTOM_VAR: "example-value",
|
|
62
|
-
ZARF_VAR: "###ZARF_VAR_THING###",
|
|
63
|
-
};
|
|
64
|
-
|
|
65
60
|
const data = {
|
|
66
61
|
name,
|
|
67
62
|
version: "0.0.1",
|
|
@@ -71,7 +66,7 @@ export function genPkgJSON(opts: InitOptions, pgkVerOverride?: string): peprPack
|
|
|
71
66
|
node: ">=20.0.0",
|
|
72
67
|
},
|
|
73
68
|
pepr: {
|
|
74
|
-
uuid:
|
|
69
|
+
uuid: uuid,
|
|
75
70
|
onError: opts.errorBehavior,
|
|
76
71
|
webhookTimeout: 10,
|
|
77
72
|
customLabels: {
|
|
@@ -93,13 +88,13 @@ export function genPkgJSON(opts: InitOptions, pgkVerOverride?: string): peprPack
|
|
|
93
88
|
},
|
|
94
89
|
},
|
|
95
90
|
includedFiles: [],
|
|
96
|
-
env:
|
|
91
|
+
env: {},
|
|
97
92
|
},
|
|
98
93
|
scripts: {
|
|
99
94
|
"k3d-setup": scripts["test:journey:k3d"],
|
|
100
95
|
},
|
|
101
96
|
dependencies: {
|
|
102
|
-
pepr:
|
|
97
|
+
pepr: version,
|
|
103
98
|
undici: "^7.0.1",
|
|
104
99
|
},
|
|
105
100
|
devDependencies: {
|
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
package/src/cli/uuid.ts
CHANGED
|
@@ -10,29 +10,8 @@ export default function (program: Command): void {
|
|
|
10
10
|
.command("uuid [uuid]")
|
|
11
11
|
.description("Module UUID(s) currently deployed in the cluster")
|
|
12
12
|
.action(async uuid => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!uuid) {
|
|
17
|
-
deployments = await K8s(kind.Deployment)
|
|
18
|
-
.InNamespace("pepr-system")
|
|
19
|
-
.WithLabel("pepr.dev/uuid")
|
|
20
|
-
.Get();
|
|
21
|
-
} else {
|
|
22
|
-
deployments = await K8s(kind.Deployment)
|
|
23
|
-
.InNamespace("pepr-system")
|
|
24
|
-
.WithLabel("pepr.dev/uuid", uuid)
|
|
25
|
-
.Get();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Populate the uuidTable with the UUID and description
|
|
29
|
-
deployments.items.map(deploy => {
|
|
30
|
-
const uuid = deploy.metadata?.labels?.["pepr.dev/uuid"] || "";
|
|
31
|
-
const description = deploy.metadata?.annotations?.["pepr.dev/description"] || "";
|
|
32
|
-
if (uuid !== "") {
|
|
33
|
-
uuidTable[uuid] = description;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
13
|
+
const deployments = await getPeprDeploymentsByUUID(uuid);
|
|
14
|
+
const uuidTable = buildUUIDTable(deployments);
|
|
36
15
|
|
|
37
16
|
console.log("UUID\t\tDescription");
|
|
38
17
|
console.log("--------------------------------------------");
|
|
@@ -42,3 +21,41 @@ export default function (program: Command): void {
|
|
|
42
21
|
});
|
|
43
22
|
});
|
|
44
23
|
}
|
|
24
|
+
|
|
25
|
+
export async function getPeprDeploymentsByUUID(
|
|
26
|
+
uuid?: string,
|
|
27
|
+
): Promise<KubernetesListObject<kind.Deployment>> {
|
|
28
|
+
const k8sQuery = K8s(kind.Deployment).InNamespace("pepr-system");
|
|
29
|
+
|
|
30
|
+
let deployments = uuid
|
|
31
|
+
? await k8sQuery.WithLabel("pepr.dev/uuid", uuid).Get()
|
|
32
|
+
: await k8sQuery.WithLabel("pepr.dev/uuid").Get();
|
|
33
|
+
|
|
34
|
+
if (uuid) {
|
|
35
|
+
deployments = {
|
|
36
|
+
...deployments,
|
|
37
|
+
items: deployments.items.filter(
|
|
38
|
+
deploy => deploy.metadata?.labels?.["pepr.dev/uuid"] === uuid,
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return deployments;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function buildUUIDTable(
|
|
47
|
+
deployments: KubernetesListObject<kind.Deployment>,
|
|
48
|
+
): Record<string, string> {
|
|
49
|
+
const uuidTable: Record<string, string> = {};
|
|
50
|
+
|
|
51
|
+
deployments.items.forEach(deploy => {
|
|
52
|
+
const uuid = deploy.metadata?.labels?.["pepr.dev/uuid"] || "";
|
|
53
|
+
const description = deploy.metadata?.annotations?.["pepr.dev/description"] || "";
|
|
54
|
+
|
|
55
|
+
if (uuid !== "") {
|
|
56
|
+
uuidTable[uuid] = description;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return uuidTable;
|
|
61
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -29,6 +29,7 @@ program
|
|
|
29
29
|
.enablePositionalOptions()
|
|
30
30
|
.version(version)
|
|
31
31
|
.description(`Pepr (v${version}) - Type safe K8s middleware for humans`)
|
|
32
|
+
.addCommand(crd())
|
|
32
33
|
.action(() => {
|
|
33
34
|
if (program.args.length < 1) {
|
|
34
35
|
console.log(banner);
|
|
@@ -49,5 +50,4 @@ format(program);
|
|
|
49
50
|
monitor(program);
|
|
50
51
|
uuid(program);
|
|
51
52
|
kfc(program);
|
|
52
|
-
crd(program);
|
|
53
53
|
program.parse();
|
package/src/lib/core/storage.ts
CHANGED
|
@@ -6,7 +6,7 @@ import pointer from "json-pointer";
|
|
|
6
6
|
export type DataOp = "add" | "remove";
|
|
7
7
|
export type DataStore = Record<string, string>;
|
|
8
8
|
export type DataSender = (op: DataOp, keys: string[], value?: string) => void;
|
|
9
|
-
|
|
9
|
+
type DataReceiver = (data: DataStore) => void;
|
|
10
10
|
export type Unsubscribe = () => void;
|
|
11
11
|
|
|
12
12
|
const MAX_WAIT_TIME = 15000;
|
|
@@ -74,7 +74,8 @@ export const definedCategory = (binding: Partial<Binding>): string => {
|
|
|
74
74
|
|
|
75
75
|
return Object.keys(categories).find(key => categories[key]) || "";
|
|
76
76
|
};
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
type DefinedCallbackReturnType =
|
|
78
79
|
| FinalizeAction<GenericClass, InstanceType<GenericClass>>
|
|
79
80
|
| WatchLogAction<GenericClass, InstanceType<GenericClass>>
|
|
80
81
|
| MutateAction<GenericClass, InstanceType<GenericClass>>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { __, allPass, complement, defaultTo, equals, length, gt, not, nthArg, pipe } from "ramda";
|
|
5
5
|
import { KubernetesObject } from "kubernetes-fluent-client";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const carriesDeletionTimestamp = pipe(
|
|
8
8
|
kubernetesObject => !!kubernetesObject.metadata?.deletionTimestamp,
|
|
9
9
|
defaultTo(false),
|
|
10
10
|
);
|
package/src/lib/types.ts
CHANGED
|
@@ -68,10 +68,6 @@ export type WhenSelector<T extends GenericClass> = {
|
|
|
68
68
|
/** Register an action to be executed when a Kubernetes resource is deleted. */
|
|
69
69
|
IsDeleted: () => BindingAll<T>;
|
|
70
70
|
};
|
|
71
|
-
export interface RegExpFilter {
|
|
72
|
-
obj: RegExp;
|
|
73
|
-
source: string;
|
|
74
|
-
}
|
|
75
71
|
|
|
76
72
|
export type Filters = {
|
|
77
73
|
annotations: Record<string, string>;
|
package/dist/cli/crd/create.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
declare const create: Command;
|
|
3
|
-
export default create;
|
|
4
|
-
export declare const generateCRDScaffold: (group: string, version: string, kind: string, data: {
|
|
5
|
-
domain: string;
|
|
6
|
-
plural: string;
|
|
7
|
-
scope: string;
|
|
8
|
-
shortName: string;
|
|
9
|
-
}) => string;
|
|
10
|
-
//# sourceMappingURL=create.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/cli/crd/create.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAM5C,QAAA,MAAM,MAAM,SA2BR,CAAC;AAEL,eAAe,MAAM,CAAC;AAEtB,eAAO,MAAM,mBAAmB,GAC9B,OAAO,MAAM,EACb,SAAS,MAAM,EACf,MAAM,MAAM,EACZ,MAAM;IACJ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,KACA,MA8EF,CAAC"}
|