@webda/kubernetes 4.0.0-beta.1 → 4.0.0-beta.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/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # @webda/kubernetes module
2
+
3
+ This module is part of Webda Application Framework that allows you to quickly develop applications with all modern prerequisites: Security, Extensibility, GraphQL, REST, CloudNative [https://webda.io](https://webda.io)
4
+
5
+ <img src="https://webda.io/images/webda.svg" width="128" />
6
+
7
+ ![CI](https://github.com/loopingz/webda.io/workflows/CI/badge.svg)
8
+
9
+ [![Join the chat at https://gitter.im/loopingz/webda](https://badges.gitter.im/loopingz/webda.svg)](https://gitter.im/loopingz/webda?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10
+ [![codecov](https://codecov.io/gh/loopingz/webda.io/branch/main/graph/badge.svg?token=8N9DNM3K3O)](https://codecov.io/gh/loopingz/webda.io)
11
+ [![SonarCloud.io](https://sonarcloud.io/api/project_badges/measure?project=loopingz_webda.io&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=loopingz_webda.io)
12
+ ![CodeQL](https://github.com/loopingz/webda.io/workflows/CodeQL/badge.svg)
13
+
14
+ <!-- README_HEADER -->
15
+
16
+ # @webda/kubernetes
17
+
18
+ > Kubernetes integration for Webda — `KubeRunner` dispatches async jobs as Kubernetes batch Jobs, `KubernetesSecretsStore` reads model data from K8s Secrets, and `CronJobDeployer` manages CronJob lifecycle.
19
+
20
+ ## When to use it
21
+
22
+ - You are using `@webda/async` and want async job workers to run as Kubernetes Jobs (one pod per job, auto-retried, auto-cleaned).
23
+ - You want to store Webda model instances in Kubernetes Secrets (useful for small, sensitive configuration objects).
24
+ - You need to deploy a scheduled Webda service operation as a Kubernetes CronJob.
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ pnpm add @webda/kubernetes
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ ### KubeRunner (async job runner)
35
+
36
+ ```json
37
+ {
38
+ "services": {
39
+ "kubeRunner": {
40
+ "type": "KubeRunner",
41
+ "jobImage": "my-registry/my-webda-app:latest",
42
+ "context": "my-k8s-context"
43
+ },
44
+ "asyncJobService": {
45
+ "type": "AsyncJobService",
46
+ "queue": "AsyncActionsQueue",
47
+ "runners": ["kubeRunner"]
48
+ }
49
+ }
50
+ }
51
+ ```
52
+
53
+ | Parameter | Type | Default | Required | Description |
54
+ |---|---|---|---|---|
55
+ | `jobImage` | string | — | Yes* | Docker image to use for the Kubernetes Job pod (`*` or `jobResources`) |
56
+ | `jobResources` | object \| string | — | Yes* | Full Kubernetes Job manifest (object or path to YAML file) overriding the default template |
57
+ | `config` | string \| object | — | No | Kubernetes config path or inline `K8sConfiguration` (defaults to in-cluster config) |
58
+ | `context` | string | — | No | Kubernetes context name (from kubeconfig) to use |
59
+
60
+ ## Usage
61
+
62
+ ```typescript
63
+ // Workers are dispatched automatically by AsyncJobService.
64
+ // KubeRunner translates each AsyncAction into a Kubernetes Job:
65
+ //
66
+ // 1. AsyncJobService.launchAsAsyncAction("MyService", "runReport", reportId)
67
+ // → saves AsyncAction to store → sends to queue
68
+ //
69
+ // 2. KubeRunner picks up the queue message and creates a Kubernetes Job:
70
+ // kubectl get jobs
71
+ // NAME COMPLETIONS DURATION
72
+ // kuberunner-abc123 1/1 12s
73
+ //
74
+ // 3. The Job pod runs: webda runAsyncAction
75
+ // → calls MyService.runReport(reportId) inside the cluster
76
+
77
+ // To run locally (without Kubernetes), switch to ServiceRunner:
78
+ {
79
+ "services": {
80
+ "asyncJobService": {
81
+ "runners": ["serviceRunner"] // swap in for dev
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ ## Reference
88
+
89
+ - API reference: see the auto-generated typedoc at `docs/pages/Modules/kubernetes/`.
90
+ - Source: [`packages/kubernetes`](https://github.com/loopingz/webda.io/tree/main/packages/kubernetes)
91
+ - Related: [`@webda/async`](../async) for the job orchestration layer; [`@webda/aws`](../aws) for `LambdaDeployer` as an AWS equivalent; [`@webda/core`](../core) for the `Runner` base class.
92
+
93
+ <!-- README_FOOTER -->
94
+ ## Sponsors
95
+
96
+ <!--
97
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](mailto:sponsor@webda.io)
98
+ -->
99
+
100
+ Arize AI is a machine learning observability and model monitoring platform. It helps you visualize, monitor, and explain your machine learning models. [Learn more](https://arize.com)
101
+
102
+ [<img src="https://arize.com/hubfs/arize/brand/arize-logomark-1.png" width="200">](https://arize.com)
103
+
104
+ Loopingz is a software development company that provides consulting and development services. [Learn more](https://loopingz.com)
105
+
106
+ [<img src="https://loopingz.com/images/logo.png" width="200">](https://loopingz.com)
107
+
108
+ Tellae is an innovative consulting firm specialized in cities transportation issues. We provide our clients, both public and private, with solutions to support your strategic and operational decisions. [Learn more](https://tellae.fr)
109
+
110
+ [<img src="https://tellae.fr/" width="200">](https://tellae.fr)
package/lib/cron.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Application, CronDefinition } from "@webda/core";
1
+ import { CronDefinition } from "@webda/core";
2
2
  /**
3
3
  * Replaces placeholders in a given template string with values from a CronDefinition object and other replacements.
4
4
  *
@@ -9,8 +9,8 @@ import { Application, CronDefinition } from "@webda/core";
9
9
  *
10
10
  * @param template - The template string to replace placeholders in.
11
11
  * @param cron - The CronDefinition object containing values to replace placeholders with.
12
- * @param app - The Application object.
13
12
  * @param replacements - Optional additional replacements to use in the template string.
14
13
  * @returns The template string with all placeholders replaced with their corresponding values.
15
14
  */
16
- export declare function CronReplace(template: string | any, cron: CronDefinition, app: Application, replacements?: any): any;
15
+ export declare function CronReplace(template: string | any, cron: CronDefinition, replacements?: any): any;
16
+ //# sourceMappingURL=cron.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cron.d.ts","sourceRoot":"","sources":["../src/cron.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAC;AAEhE;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,cAAc,EAAE,YAAY,GAAE,GAAQ,OAwC/F"}
package/lib/cron.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { templateVariables } from "@webda/core";
1
2
  /**
2
3
  * Replaces placeholders in a given template string with values from a CronDefinition object and other replacements.
3
4
  *
@@ -8,11 +9,10 @@
8
9
  *
9
10
  * @param template - The template string to replace placeholders in.
10
11
  * @param cron - The CronDefinition object containing values to replace placeholders with.
11
- * @param app - The Application object.
12
12
  * @param replacements - Optional additional replacements to use in the template string.
13
13
  * @returns The template string with all placeholders replaced with their corresponding values.
14
14
  */
15
- export function CronReplace(template, cron, app, replacements = {}) {
15
+ export function CronReplace(template, cron, replacements = {}) {
16
16
  const cleanVars = (value) => {
17
17
  // @deprecated remove in > 4.x
18
18
  value = value.replace(/"\${...cron\.args}"/g, "${cron.argsArray}");
@@ -38,7 +38,7 @@ export function CronReplace(template, cron, app, replacements = {}) {
38
38
  return value;
39
39
  }));
40
40
  }
41
- return app.replaceVariables(template, {
41
+ return templateVariables(template, {
42
42
  ...replacements,
43
43
  env: process.env,
44
44
  cron: {
package/lib/cron.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cron.js","sourceRoot":"","sources":["../src/cron.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,QAAsB,EAAE,IAAoB,EAAE,GAAgB,EAAE,eAAoB,EAAE;IAChH,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE;QAClC,8BAA8B;QAC9B,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,sBAAsB,EAAE,mBAAmB,CAAC,CAAC;QACnE,+BAA+B;QAC/B,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,0BAA0B,EAAE,mBAAmB,CAAC,CAAC;QACvE,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,uBAAuB,EA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K,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,iBAAiB,EAAE,CAAC;gBAC1E,KAAK,CAAC,GAAG,EAAE,CAAC;gBACZ,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;iBAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACrC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;YAC1B,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,iBAAiB,CAAC,QAAQ,EAAE;QACjC,GAAG,YAAY;QACf,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,mBAAmB;YACnB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAClE,sDAAsD;YACtD,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YAChD,mBAAmB,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YAC3D,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;SACnD;KACF,CAAC,CAAC;AACL,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from "./cron.js";
2
- export * from "./services/kuberunner.js";
2
+ export * from "./services/cronexporter.service.js";
3
+ export * from "./services/kuberunner.service.js";
3
4
  export * from "./utils/client.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mBAAmB,CAAC"}
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./cron.js";
2
- export * from "./services/kuberunner.js";
2
+ export * from "./services/cronexporter.service.js";
3
+ export * from "./services/kuberunner.service.js";
3
4
  export * from "./utils/client.js";
4
5
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Service } from "@webda/core";
2
+ /**
3
+ * Default CronJob template used when no template is provided
4
+ */
5
+ export declare const K8S_DEFAULT_CRON_DEFINITION = "apiVersion: batch/v1\nkind: CronJob\nmetadata:\n name: ${cron.serviceName.toLowerCase()}-${cron.method.toLowerCase()}-${cron.cronId}\nspec:\n concurrencyPolicy: Forbid\n failedJobsHistoryLimit: 1\n jobTemplate:\n spec:\n template:\n spec:\n containers:\n - image: ${resources.tag}\n imagePullPolicy: Always\n name: scheduled-job\n resources: {}\n command: [\"/webda/node_modules/.bin/webda\"]\n args: [\"cron\", \"run\", \"--id\", \"${cron.cronId}\"]\n restartPolicy: Never\n securityContext: {}\n terminationGracePeriodSeconds: 30\n schedule: ${cron.cron}\n successfulJobsHistoryLimit: 3\n";
6
+ /**
7
+ * Export the application crons as Kubernetes resources
8
+ *
9
+ * Exposes the `webda kubernetes cronExport` command
10
+ *
11
+ * @WebdaModda
12
+ */
13
+ export default class KubernetesCronExporter extends Service {
14
+ /**
15
+ * Export all application Cron as Kubernetes resources
16
+ *
17
+ * @param template - Template file to use, default to a Kubernetes CronJob
18
+ * @param target - Folder to write the resources to
19
+ * @param filenameTemplate - Filename template to use
20
+ * @param image - Image to use in the default template
21
+ * @returns the number of exported crons
22
+ */
23
+ cronExport(template?: string, target?: string, filenameTemplate?: string, image?: string): Promise<number>;
24
+ }
25
+ export { KubernetesCronExporter };
26
+ //# sourceMappingURL=cronexporter.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cronexporter.service.d.ts","sourceRoot":"","sources":["../../src/services/cronexporter.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,OAAO,EAA8B,MAAM,aAAa,CAAC;AAKxG;;GAEG;AACH,eAAO,MAAM,2BAA2B,wtBAuBvC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,OAAO;IACzD;;;;;;;;OAQG;IAMG,UAAU,CACd,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,GAAE,MAAkB,EAC1B,gBAAgB,GAAE,MAAgF,EAClG,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAqBjB;CACF;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,130 @@
1
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
+ var useValue = arguments.length > 2;
3
+ for (var i = 0; i < initializers.length; i++) {
4
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
+ }
6
+ return useValue ? value : void 0;
7
+ };
8
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
+ var _, done = false;
14
+ for (var i = decorators.length - 1; i >= 0; i--) {
15
+ var context = {};
16
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
+ if (kind === "accessor") {
21
+ if (result === void 0) continue;
22
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
+ if (_ = accept(result.get)) descriptor.get = _;
24
+ if (_ = accept(result.set)) descriptor.set = _;
25
+ if (_ = accept(result.init)) initializers.unshift(_);
26
+ }
27
+ else if (_ = accept(result)) {
28
+ if (kind === "field") initializers.unshift(_);
29
+ else descriptor[key] = _;
30
+ }
31
+ }
32
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
+ done = true;
34
+ };
35
+ import { Command, CronService, Service, templateVariables, useCore } from "@webda/core";
36
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
37
+ import { extname, join } from "node:path";
38
+ import { CronReplace } from "../cron.js";
39
+ /**
40
+ * Default CronJob template used when no template is provided
41
+ */
42
+ export const K8S_DEFAULT_CRON_DEFINITION = `apiVersion: batch/v1
43
+ kind: CronJob
44
+ metadata:
45
+ name: \${cron.serviceName.toLowerCase()}-\${cron.method.toLowerCase()}-\${cron.cronId}
46
+ spec:
47
+ concurrencyPolicy: Forbid
48
+ failedJobsHistoryLimit: 1
49
+ jobTemplate:
50
+ spec:
51
+ template:
52
+ spec:
53
+ containers:
54
+ - image: \${resources.tag}
55
+ imagePullPolicy: Always
56
+ name: scheduled-job
57
+ resources: {}
58
+ command: ["/webda/node_modules/.bin/webda"]
59
+ args: ["cron", "run", "--id", "\${cron.cronId}"]
60
+ restartPolicy: Never
61
+ securityContext: {}
62
+ terminationGracePeriodSeconds: 30
63
+ schedule: \${cron.cron}
64
+ successfulJobsHistoryLimit: 3
65
+ `;
66
+ let KubernetesCronExporter = (() => {
67
+ var _a;
68
+ let _classSuper = Service;
69
+ let _instanceExtraInitializers = [];
70
+ let _cronExport_decorators;
71
+ return _a = class KubernetesCronExporter extends _classSuper {
72
+ /**
73
+ * Export all application Cron as Kubernetes resources
74
+ *
75
+ * @param template - Template file to use, default to a Kubernetes CronJob
76
+ * @param target - Folder to write the resources to
77
+ * @param filenameTemplate - Filename template to use
78
+ * @param image - Image to use in the default template
79
+ * @returns the number of exported crons
80
+ */
81
+ async cronExport(template, target = "./crons", filenameTemplate = "${serviceName.toLowerCase()}.${method.toLowerCase()}-${cronId}.${ext}", image) {
82
+ let ext;
83
+ let content;
84
+ if (template) {
85
+ ext = extname(template).substring(1);
86
+ content = readFileSync(template).toString();
87
+ }
88
+ else {
89
+ content = K8S_DEFAULT_CRON_DEFINITION;
90
+ ext = "yaml";
91
+ }
92
+ mkdirSync(target, { recursive: true });
93
+ const crons = CronService.loadAnnotations(useCore().getServices());
94
+ crons.forEach((cron) => {
95
+ // Copy so the shared annotation is not changed, its id must stay stable for `cron run`
96
+ const exported = { ...cron, cronId: CronService.getExportId(cron) };
97
+ const filename = join(target, templateVariables(filenameTemplate, { ...exported, ext }));
98
+ this.log("DEBUG", `Exporting ${filename} cron with ${cron.toString()}`);
99
+ writeFileSync(filename, CronReplace(content, exported, { resources: { tag: image } }));
100
+ });
101
+ this.log("INFO", `Exported ${crons.length} crons`);
102
+ return crons.length;
103
+ }
104
+ constructor() {
105
+ super(...arguments);
106
+ __runInitializers(this, _instanceExtraInitializers);
107
+ }
108
+ },
109
+ (() => {
110
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
111
+ _cronExport_decorators = [Command("kubernetes cronExport", {
112
+ description: "Export all application Cron as template",
113
+ requires: ["kubernetes-cron-export"],
114
+ phase: "resolved"
115
+ })];
116
+ __esDecorate(_a, null, _cronExport_decorators, { kind: "method", name: "cronExport", static: false, private: false, access: { has: obj => "cronExport" in obj, get: obj => obj.cronExport }, metadata: _metadata }, null, _instanceExtraInitializers);
117
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
118
+ })(),
119
+ _a;
120
+ })();
121
+ /**
122
+ * Export the application crons as Kubernetes resources
123
+ *
124
+ * Exposes the `webda kubernetes cronExport` command
125
+ *
126
+ * @WebdaModda
127
+ */
128
+ export default KubernetesCronExporter;
129
+ export { KubernetesCronExporter };
130
+ //# sourceMappingURL=cronexporter.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cronexporter.service.js","sourceRoot":"","sources":["../../src/services/cronexporter.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAkB,WAAW,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuB1C,CAAC;;;sBASkD,OAAO;;;sBAAtC,sBAAuB,SAAQ,WAAO;YACzD;;;;;;;;eAQG;YAMH,KAAK,CAAC,U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C,MAAM,QAAQ,CAAC,CAAC;gBACnD,OAAO,KAAK,CAAC,MAAM,CAAC;YACtB,CAAC;;;gBAzCkB,mDAAsB;;;;;sCAUxC,OAAO,CAAC,uBAAuB,EAAE;oBAChC,WAAW,EAAE,yCAAyC;oBACtD,QAAQ,EAAE,CAAC,wBAAwB,CAAC;oBACpC,KAAK,EAAE,UAAU;iBAClB,CAAC;YACF,+KAAM,UAAU,6DA0Bf;;;;;AAhDH;;;;;;GAMG;AACH,sCA0CC;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import * as k8s from "@kubernetes/client-node";
2
2
  import { AsyncAction, JobInfo, Runner, RunnerParameters } from "@webda/async";
3
- import { ServiceParameters } from "@webda/core";
4
3
  import { K8sConfiguration, KubernetesParameters } from "../utils/client.js";
5
4
  /**
6
5
  * Parameters for the KubeRunner
@@ -9,7 +8,7 @@ export declare class KubeRunnerParameters extends RunnerParameters implements Ku
9
8
  /**
10
9
  * Kubernetes configuration
11
10
  */
12
- config: string | K8sConfiguration;
11
+ config?: string | K8sConfiguration;
13
12
  /**
14
13
  * Default context to use
15
14
  */
@@ -22,15 +21,23 @@ export declare class KubeRunnerParameters extends RunnerParameters implements Ku
22
21
  * If default template, use this image
23
22
  */
24
23
  jobImage?: string;
25
- constructor(params: any);
24
+ /**
25
+ * @override
26
+ * @param params - the input parameters
27
+ * @returns this
28
+ */
29
+ load(params?: any): this;
26
30
  }
27
31
  /**
28
- * Type of action returned by LocalRunner
32
+ * Kubernetes object reference returned by the KubeRunner
29
33
  */
30
- export interface KubeJob {
34
+ export interface KubeJobReference {
35
+ metadata: k8s.V1ObjectMeta;
36
+ apiVersion: string;
37
+ kind: string;
31
38
  }
32
39
  /**
33
- * Run a Job locally on the server by spawning a child process
40
+ * Run a Job on a Kubernetes cluster
34
41
  *
35
42
  * @WebdaModda
36
43
  */
@@ -38,15 +45,16 @@ export default class KubeRunner<T extends KubeRunnerParameters = KubeRunnerParam
38
45
  client: k8s.KubernetesObjectApi;
39
46
  /**
40
47
  * @inheritdoc
48
+ * @param _action - the action to launch
49
+ * @param info - the job information
50
+ * @returns the created job reference
41
51
  */
42
- loadParameters(params: any): ServiceParameters;
43
- /**
44
- * @inheritdoc
45
- */
46
- launchAction(_action: AsyncAction, info: JobInfo): Promise<KubeJob>;
52
+ launchAction(_action: AsyncAction, info: JobInfo): Promise<KubeJobReference>;
47
53
  /**
48
54
  * @inheritdoc
55
+ * @returns this
49
56
  */
50
57
  resolve(): this;
51
58
  }
52
59
  export { KubeRunner };
60
+ //# sourceMappingURL=kuberunner.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kuberunner.service.d.ts","sourceRoot":"","sources":["../../src/services/kuberunner.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAG9E,OAAO,EAA0B,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAgBpG;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,gBAAiB,YAAW,oBAAoB;IACxF;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACnC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,IAAI,CAAC,MAAM,GAAE,GAAQ,GAAG,IAAI,CAW3B;CACF;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,GAAG,CAAC,YAAY,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,MAAM,CAAC,CAAC,CAAC;IACtG,MAAM,EAAE,GAAG,CAAC,mBAAmB,CAAC;IAEhC;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAsBjF;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,CAId;CACF;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { Runner, RunnerParameters } from "@webda/async";
2
- import { FileUtils, YAMLUtils } from "@webda/core";
2
+ import { templateVariables } from "@webda/core";
3
+ import { FileUtils, YAMLUtils } from "@webda/utils";
3
4
  import { getKubernetesApiClient } from "../utils/client.js";
4
5
  const DEFAULT_JOB_DEFINITION = `apiVersion: batch/v1
5
6
  kind: Job
@@ -18,49 +19,48 @@ spec:
18
19
  * Parameters for the KubeRunner
19
20
  */
20
21
  export class KubeRunnerParameters extends RunnerParameters {
21
- constructor(params) {
22
- super(params);
22
+ /**
23
+ * @override
24
+ * @param params - the input parameters
25
+ * @returns this
26
+ */
27
+ load(params = {}) {
28
+ super.load(params);
23
29
  if (this.jobImage === undefined && this.jobResources === undefined) {
24
30
  throw new Error("Either jobImage or jobResources need to be defined");
25
31
  }
26
32
  this.jobResources ?? (this.jobResources = YAMLUtils.parse(DEFAULT_JOB_DEFINITION));
27
33
  if (typeof this.jobResources === "string") {
28
- this.jobResources = FileUtils.load(this.jobResources);
34
+ // Convert to a plain object (yaml files are loaded as comment-preserving documents)
35
+ this.jobResources = JSON.parse(JSON.stringify(FileUtils.load(this.jobResources)));
29
36
  }
37
+ return this;
30
38
  }
31
39
  }
32
40
  /**
33
- * Run a Job locally on the server by spawning a child process
41
+ * Run a Job on a Kubernetes cluster
34
42
  *
35
43
  * @WebdaModda
36
44
  */
37
45
  export default class KubeRunner extends Runner {
38
46
  /**
39
47
  * @inheritdoc
40
- */
41
- loadParameters(params) {
42
- return new KubeRunnerParameters(params);
43
- }
44
- /**
45
- * @inheritdoc
48
+ * @param _action - the action to launch
49
+ * @param info - the job information
50
+ * @returns the created job reference
46
51
  */
47
52
  async launchAction(_action, info) {
48
- const resources = this.getWebda()
49
- .getApplication()
50
- .replaceVariables(this.parameters.jobResources, {
53
+ const resources = templateVariables(this.parameters.jobResources, {
51
54
  serviceName: this.getName(),
52
55
  image: this.parameters.jobImage,
53
56
  ...info,
54
57
  env: process.env
55
58
  });
56
59
  // Inject environment variable
57
- if (resources.spec &&
58
- resources.spec.template &&
59
- resources.spec.template.spec &&
60
- resources.spec.template.spec.containers) {
61
- for (let cont of resources.spec.template.spec.containers) {
60
+ if (resources.spec?.template?.spec?.containers) {
61
+ for (const cont of resources.spec.template.spec.containers) {
62
62
  cont.env ?? (cont.env = []);
63
- for (let envKey in info) {
63
+ for (const envKey in info) {
64
64
  cont.env.push({
65
65
  name: envKey,
66
66
  value: info[envKey]
@@ -70,10 +70,11 @@ export default class KubeRunner extends Runner {
70
70
  }
71
71
  // Launch the resource now
72
72
  const result = await this.client.create(resources);
73
- return { metadata: result.body.metadata, apiVersion: result.body.apiVersion, kind: result.body.kind };
73
+ return { metadata: result.metadata, apiVersion: result.apiVersion, kind: result.kind };
74
74
  }
75
75
  /**
76
76
  * @inheritdoc
77
+ * @returns this
77
78
  */
78
79
  resolve() {
79
80
  super.resolve();
@@ -82,4 +83,4 @@ export default class KubeRunner extends Runner {
82
83
  }
83
84
  }
84
85
  export { KubeRunner };
85
- //# sourceMappingURL=kuberunner.js.map
86
+ //# sourceMappingURL=kuberunner.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kuberunner.service.js","sourceRoot":"","sources":["../../src/services/kuberunner.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,C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BAA8B;QAC9B,IAAI,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;YAC/C,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC3D,IAAI,CAAC,GAAG,KAAR,IAAI,CAAC,GAAG,GAAK,EAAE,EAAC;gBAChB,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE,CAAC;oBAC1B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;wBACZ,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;qBACpB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QACD,0BAA0B;QAC1B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IACzF,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,GAA4B,sBAAsB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -14,10 +14,13 @@ export interface KubernetesParameters {
14
14
  }
15
15
  /**
16
16
  * Get a Kubernetes configuration initialized based on Kubernetes Parameters
17
- * @param params
18
- * @returns
17
+ * @param params - the kubernetes parameters
18
+ * @returns the kubernetes configuration
19
19
  */
20
20
  export declare function getKubeConfig(params: KubernetesParameters): k8s.KubeConfig;
21
+ /**
22
+ * Kubernetes configuration as found in a kubeconfig file
23
+ */
21
24
  export interface K8sConfiguration {
22
25
  clusters: k8s.Cluster[];
23
26
  contexts: k8s.Context[];
@@ -25,8 +28,10 @@ export interface K8sConfiguration {
25
28
  users: k8s.User[];
26
29
  }
27
30
  /**
28
- *
29
- * @param params
30
- * @returns
31
+ * Get a Kubernetes API client
32
+ * @param params - the kubernetes parameters
33
+ * @param api - the API class to instantiate, generic object API if not specified
34
+ * @returns the API client
31
35
  */
32
36
  export declare function getKubernetesApiClient(params: KubernetesParameters, api?: any): k8s.ApiType | k8s.KubernetesObjectApi;
37
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAG/C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACnC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,GAAG,CAAC,UAAU,CAgB1E;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IACxB,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,mBAAmB,CAOrH"}
@@ -1,9 +1,9 @@
1
- import { FileUtils } from "@webda/core";
2
1
  import * as k8s from "@kubernetes/client-node";
2
+ import { FileUtils } from "@webda/utils";
3
3
  /**
4
4
  * Get a Kubernetes configuration initialized based on Kubernetes Parameters
5
- * @param params
6
- * @returns
5
+ * @param params - the kubernetes parameters
6
+ * @returns the kubernetes configuration
7
7
  */
8
8
  export function getKubeConfig(params) {
9
9
  const kc = new k8s.KubeConfig();
@@ -25,9 +25,10 @@ export function getKubeConfig(params) {
25
25
  return kc;
26
26
  }
27
27
  /**
28
- *
29
- * @param params
30
- * @returns
28
+ * Get a Kubernetes API client
29
+ * @param params - the kubernetes parameters
30
+ * @param api - the API class to instantiate, generic object API if not specified
31
+ * @returns the API client
31
32
  */
32
33
  export function getKubernetesApiClient(params, api) {
33
34
  const kc = getKubeConfig(params);
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAgB/C;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAA4B;IACxD,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;IAChC,iCAAiC;IACjC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YACtC,EAAE,CAAC,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,EAAE,CAAC,eAAe,EAAE,CAAC;IACvB,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AASD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA4B,EAAE,GA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,aAAa,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,CAAC,mBAAmB,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,52 +1,32 @@
1
1
  {
2
2
  "name": "@webda/kubernetes",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0-beta.3",
4
4
  "description": "Kubernetes Helpers",
5
5
  "main": "lib/index.js",
6
- "scripts": {
7
- "build": "tsc-esm",
8
- "build:module": "webda build",
9
- "build:watch": "webda build --watch",
10
- "pretest": "npm run build",
11
- "test": "c8 mocha -r ../../node_modules/ts-node/register",
12
- "run": "node core"
13
- },
14
6
  "keywords": [
15
7
  "webda-module"
16
8
  ],
17
9
  "files": [
18
10
  "lib",
19
11
  "webda.module.json",
20
- "webda.shell.json",
21
12
  "package.json"
22
13
  ],
23
14
  "dependencies": {
24
- "@kubernetes/client-node": "^0.21.0",
25
- "@webda/async": "^4.0.0-beta.1",
26
- "@webda/core": "^4.0.0-beta.1"
15
+ "@kubernetes/client-node": "^1.4.0",
16
+ "@webda/async": "4.0.0-beta.3",
17
+ "@webda/core": "4.0.0-beta.3",
18
+ "@webda/utils": "4.0.0-beta.3"
27
19
  },
28
20
  "devDependencies": {
29
- "@testdeck/mocha": "^0.3.3",
30
- "@types/node": "18.11.13",
31
- "@webda/tsc-esm": "^4.0.0-beta.1",
32
- "c8": "^10.1.2",
33
- "mocha": "^10.0.0",
34
- "sinon": "^18.0.0",
35
- "source-map-support": "^0.5.19",
36
- "ts-node": "^10.2.0",
37
- "typescript": "~5.5.3"
38
- },
39
- "c8": {
40
- "report-dir": "./reports",
41
- "reporter": [
42
- "html",
43
- "lcov",
44
- "json",
45
- "text"
46
- ],
47
- "exclude": [
48
- "**/*.spec.ts"
49
- ]
21
+ "@types/node": "25.5.0",
22
+ "@vitest/coverage-v8": "^4.1.2",
23
+ "jscodeshift": "^17.3.0",
24
+ "skott": "^0.35.8",
25
+ "typescript": "7.1.0-dev.20260929.1",
26
+ "vite": "^6.0.0",
27
+ "vitest": "^4.1.2",
28
+ "@webda/compiler": "^4.0.0-beta.3",
29
+ "@webda/test": "4.0.0-beta.3"
50
30
  },
51
31
  "bugs": {
52
32
  "url": "https://github.com/loopingz/webda.io/issues"
@@ -60,18 +40,32 @@
60
40
  "access": "public"
61
41
  },
62
42
  "webda": {
63
- "namespace": "Webda"
43
+ "namespace": "Webda",
44
+ "capabilities": {
45
+ "kubernetes-cron-export": "Webda/KubernetesCronExporter"
46
+ }
64
47
  },
65
48
  "type": "module",
66
49
  "engines": {
67
- "node": ">=18.0.0"
50
+ "node": ">=22.0.0"
68
51
  },
69
52
  "nx": {
70
53
  "implicitDependencies": [
71
54
  "@webda/core",
72
- "@webda/tsc-esm",
73
55
  "@webda/async"
74
56
  ]
75
57
  },
76
- "gitHead": "9f0c12d5e43b3484794b2a49c5701b8b9675c4a8"
77
- }
58
+ "license": "LGPL-3.0-only",
59
+ "scripts": {
60
+ "build": "webdac build",
61
+ "build:watch": "webdac build --watch",
62
+ "pretest": "npm run build",
63
+ "test": "vitest run",
64
+ "format": "prettier --check src/**/*",
65
+ "lint": "eslint",
66
+ "lint:fix": "eslint --fix",
67
+ "format:fix": "prettier --write src/**/*",
68
+ "deps:graph": "skott --showCircularDependencies --no-trackTypeOnlyDependencies --displayMode=raw -e .ts",
69
+ "codemod": "jscodeshift --parser=ts --extensions=tsx,ts -t ../codemod/current.mjs src"
70
+ }
71
+ }
package/webda.module.json CHANGED
@@ -1,46 +1,208 @@
1
1
  {
2
+ "$schema": "https://webda.io/schemas/webda.module.v4.json",
2
3
  "beans": {},
3
4
  "deployers": {},
4
5
  "moddas": {
5
- "Webda/KubeRunner": "lib/services/kuberunner:default"
6
- },
7
- "models": {
8
- "graph": {},
9
- "tree": {},
10
- "plurals": {},
11
- "list": {},
12
- "reflections": {}
6
+ "Webda/KubeRunner": {
7
+ "Import": "lib/services/kuberunner.service:default",
8
+ "Schema": {
9
+ "$schema": "http://json-schema.org/draft-07/schema#",
10
+ "additionalProperties": false,
11
+ "definitions": {
12
+ "Cluster": {
13
+ "additionalProperties": false,
14
+ "properties": {
15
+ "caFile": {
16
+ "type": "string"
17
+ }
18
+ },
19
+ "type": "object"
20
+ },
21
+ "Context": {
22
+ "additionalProperties": false,
23
+ "type": "object"
24
+ },
25
+ "K8sConfiguration": {
26
+ "additionalProperties": false,
27
+ "description": "Kubernetes configuration as found in a kubeconfig file",
28
+ "properties": {
29
+ "clusters": {
30
+ "items": {
31
+ "$ref": "#/definitions/Cluster"
32
+ },
33
+ "type": "array"
34
+ },
35
+ "contexts": {
36
+ "items": {
37
+ "$ref": "#/definitions/Context"
38
+ },
39
+ "type": "array"
40
+ },
41
+ "currentContext": {
42
+ "type": "string"
43
+ },
44
+ "users": {
45
+ "items": {
46
+ "$ref": "#/definitions/User"
47
+ },
48
+ "type": "array"
49
+ }
50
+ },
51
+ "required": [
52
+ "clusters",
53
+ "contexts",
54
+ "currentContext",
55
+ "users"
56
+ ],
57
+ "type": "object"
58
+ },
59
+ "User": {
60
+ "additionalProperties": false,
61
+ "properties": {
62
+ "certFile": {
63
+ "type": "string"
64
+ },
65
+ "keyFile": {
66
+ "type": "string"
67
+ }
68
+ },
69
+ "type": "object"
70
+ }
71
+ },
72
+ "description": "Parameters for the KubeRunner",
73
+ "properties": {
74
+ "actions": {
75
+ "default": [],
76
+ "description": "Actions managed by the runner",
77
+ "items": {
78
+ "type": "string"
79
+ },
80
+ "type": "array"
81
+ },
82
+ "config": {
83
+ "anyOf": [
84
+ {
85
+ "type": "string"
86
+ },
87
+ {
88
+ "$ref": "#/definitions/K8sConfiguration"
89
+ }
90
+ ],
91
+ "description": "Kubernetes configuration"
92
+ },
93
+ "context": {
94
+ "description": "Default context to use",
95
+ "type": "string"
96
+ },
97
+ "jobImage": {
98
+ "description": "If default template, use this image",
99
+ "type": "string"
100
+ },
101
+ "jobResources": {
102
+ "description": "Kubernetes resources to use"
103
+ },
104
+ "type": {
105
+ "description": "Type of the service",
106
+ "type": "string"
107
+ },
108
+ "openapi": {
109
+ "type": "object",
110
+ "additionalProperties": true
111
+ }
112
+ },
113
+ "required": [
114
+ "type"
115
+ ],
116
+ "type": "object",
117
+ "title": "KubeRunner"
118
+ },
119
+ "Configuration": "lib/services/kuberunner.service:KubeRunnerParameters"
120
+ },
121
+ "Webda/KubernetesCronExporter": {
122
+ "Import": "lib/services/cronexporter.service:default",
123
+ "Schema": {
124
+ "$schema": "http://json-schema.org/draft-07/schema#",
125
+ "additionalProperties": false,
126
+ "description": "Interface to specify the Service parameters",
127
+ "properties": {
128
+ "type": {
129
+ "description": "Type of the service",
130
+ "type": "string"
131
+ },
132
+ "openapi": {
133
+ "type": "object",
134
+ "additionalProperties": true
135
+ }
136
+ },
137
+ "required": [
138
+ "type"
139
+ ],
140
+ "type": "object",
141
+ "title": "KubernetesCronExporter"
142
+ },
143
+ "Configuration": "node_modules/@webda/core/lib/services/serviceparameters:ServiceParameters",
144
+ "commands": {
145
+ "kubernetes cronExport": {
146
+ "description": "Export all application Cron as template",
147
+ "method": "cronExport",
148
+ "args": {
149
+ "template": {
150
+ "type": "string"
151
+ },
152
+ "target": {
153
+ "type": "string",
154
+ "default": "./crons"
155
+ },
156
+ "filenameTemplate": {
157
+ "type": "string",
158
+ "default": "${serviceName.toLowerCase()}.${method.toLowerCase()}-${cronId}.${ext}"
159
+ },
160
+ "image": {
161
+ "type": "string"
162
+ }
163
+ },
164
+ "requires": [
165
+ "kubernetes-cron-export"
166
+ ],
167
+ "phase": "resolved"
168
+ }
169
+ }
170
+ }
13
171
  },
172
+ "models": {},
14
173
  "schemas": {
15
174
  "Webda/BinaryFile": {
16
- "type": "object",
175
+ "$schema": "http://json-schema.org/draft-07/schema#",
176
+ "WebdaSchema": true,
177
+ "additionalProperties": false,
178
+ "description": "Represent a file to store",
17
179
  "properties": {
18
- "hash": {
19
- "type": "string",
20
- "description": "Will be computed by the service\n\nhash of the content"
21
- },
22
180
  "challenge": {
23
- "type": "string",
24
- "description": "Will be computed by the service\n\nhash of the content prefixed by 'WEBDA'"
181
+ "description": "Will be computed by the service\n\nhash of the content prefixed by 'WEBDA'",
182
+ "type": "string"
25
183
  },
26
- "size": {
27
- "type": "number",
28
- "description": "Size of the binary"
184
+ "hash": {
185
+ "description": "Will be computed by the service\n\nhash of the content",
186
+ "type": "string"
29
187
  },
30
- "name": {
31
- "type": "string",
32
- "description": "Current name"
188
+ "metadata": {
189
+ "description": "Metadatas stored along with the binary"
33
190
  },
34
191
  "mimetype": {
35
- "type": "string",
36
- "description": "Mimetype of the binary"
192
+ "description": "Mimetype of the binary",
193
+ "type": "string"
37
194
  },
38
- "metadata": {
39
- "description": "Metadatas stored along with the binary"
195
+ "name": {
196
+ "description": "Current name",
197
+ "type": "string"
40
198
  },
41
199
  "originalname": {
42
- "type": "string",
43
- "description": "Original name"
200
+ "description": "Original name",
201
+ "type": "string"
202
+ },
203
+ "size": {
204
+ "description": "Size of the binary",
205
+ "type": "number"
44
206
  }
45
207
  },
46
208
  "required": [
@@ -48,166 +210,12 @@
48
210
  "name",
49
211
  "size"
50
212
  ],
51
- "description": "Represent a file to store",
52
- "$schema": "http://json-schema.org/draft-07/schema#",
53
- "title": "BinaryFile"
54
- },
55
- "Webda/KubeRunner": {
56
213
  "type": "object",
57
- "properties": {
58
- "config": {
59
- "anyOf": [
60
- {
61
- "type": "string"
62
- },
63
- {
64
- "type": "object",
65
- "properties": {
66
- "clusters": {
67
- "type": "array",
68
- "items": {
69
- "type": "object",
70
- "properties": {
71
- "name": {
72
- "type": "string"
73
- },
74
- "caData": {
75
- "type": "string"
76
- },
77
- "caFile": {
78
- "type": "string"
79
- },
80
- "server": {
81
- "type": "string"
82
- },
83
- "skipTLSVerify": {
84
- "type": "boolean"
85
- },
86
- "tlsServerName": {
87
- "type": "string"
88
- }
89
- },
90
- "required": [
91
- "name",
92
- "server"
93
- ]
94
- }
95
- },
96
- "contexts": {
97
- "type": "array",
98
- "items": {
99
- "type": "object",
100
- "properties": {
101
- "cluster": {
102
- "type": "string"
103
- },
104
- "user": {
105
- "type": "string"
106
- },
107
- "name": {
108
- "type": "string"
109
- },
110
- "namespace": {
111
- "type": "string"
112
- }
113
- },
114
- "required": [
115
- "cluster",
116
- "user",
117
- "name"
118
- ]
119
- }
120
- },
121
- "currentContext": {
122
- "type": "string"
123
- },
124
- "users": {
125
- "type": "array",
126
- "items": {
127
- "type": "object",
128
- "properties": {
129
- "name": {
130
- "type": "string"
131
- },
132
- "certData": {
133
- "type": "string"
134
- },
135
- "certFile": {
136
- "type": "string"
137
- },
138
- "exec": {},
139
- "keyData": {
140
- "type": "string"
141
- },
142
- "keyFile": {
143
- "type": "string"
144
- },
145
- "authProvider": {},
146
- "token": {
147
- "type": "string"
148
- },
149
- "username": {
150
- "type": "string"
151
- },
152
- "password": {
153
- "type": "string"
154
- }
155
- },
156
- "required": [
157
- "name"
158
- ]
159
- }
160
- }
161
- },
162
- "required": [
163
- "clusters",
164
- "contexts",
165
- "currentContext",
166
- "users"
167
- ]
168
- }
169
- ],
170
- "description": "Kubernetes configuration"
171
- },
172
- "context": {
173
- "type": "string",
174
- "description": "Default context to use"
175
- },
176
- "type": {
177
- "type": "string",
178
- "description": "Type of the service"
179
- },
180
- "url": {
181
- "type": "string",
182
- "description": "URL on which to serve the content"
183
- },
184
- "actions": {
185
- "type": "array",
186
- "items": {
187
- "type": "string"
188
- },
189
- "description": "Actions managed by the runner",
190
- "default": []
191
- },
192
- "jobResources": {
193
- "description": "Kubernetes resources to use"
194
- },
195
- "jobImage": {
196
- "type": "string",
197
- "description": "If default template, use this image"
198
- },
199
- "openapi": {
200
- "type": "object",
201
- "additionalProperties": true
202
- }
203
- },
204
- "required": [
205
- "config",
206
- "type"
207
- ],
208
- "description": "Parameters for the KubeRunner",
209
- "$schema": "http://json-schema.org/draft-07/schema#",
210
- "title": "KubeRunner"
214
+ "title": "BinaryFile"
211
215
  }
216
+ },
217
+ "behaviors": {},
218
+ "capabilities": {
219
+ "kubernetes-cron-export": "Webda/KubernetesCronExporter"
212
220
  }
213
221
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"kuberunner.js","sourceRoot":"","sources":["../../src/services/kuberunner.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAqB,SAAS,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAA0C,MAAM,iBAAiB,CAAC;AAEjG,MAAM,sBAAsB,GAAG;;;;;;;;;;;;CAY9B,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAkBxD,YAAY,MAAW;QACrB,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACnE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,CAAC,YAAY,KAAjB,IAAI,CAAC,YAAY,GAAK,SAAS,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAC;QAC9D,IAAI,OAAO,IAAI,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;YAC1C,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CACF;AAOD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,UAAkE,SAAQ,MAAS;IAGtG;;OAEG;IACH,cAAc,CAAC,MAAW;QACxB,OAAO,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,OAAoB,EAAE,IAAa;QACpD,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE;aAC9B,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AC/E,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
package/lib/shell.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export declare class KubernetesShell {
2
- static shellCommand(Console: any, args: any): Promise<void>;
3
- }
4
- /**
5
- * Create the command line parser
6
- *
7
- * @param y
8
- * @returns
9
- */
10
- declare function yargs(y: any): any;
11
- declare const ShellCommand: typeof KubernetesShell.shellCommand;
12
- export { ShellCommand, yargs };
package/lib/shell.js DELETED
@@ -1,53 +0,0 @@
1
- import { CronService } from "@webda/core";
2
- import { mkdirSync, readFileSync, writeFileSync } from "fs";
3
- import { extname, join } from "path";
4
- import { CronReplace } from "./cron.js";
5
- export class KubernetesShell {
6
- static async shellCommand(Console, args) {
7
- if (args.cronExport) {
8
- // @ts-ignore
9
- const shellModule = await import("@webda/shell");
10
- const target = args.target || "./crons";
11
- let template = args.template;
12
- const filenameTemplate = args.filenameTemplate || "${serviceName.toLowerCase()}.${method.toLowerCase()}-${cronId}.${ext}";
13
- let ext;
14
- if (template) {
15
- ext = extname(template).substring(1);
16
- template = readFileSync(template).toString();
17
- }
18
- else {
19
- template = shellModule.K8S_DEFAULT_CRON_DEFINITION;
20
- ext = "yaml";
21
- }
22
- // Dynanically import
23
- Console.webda = new shellModule.WebdaServer(Console.app);
24
- Console.webda.initStatics();
25
- mkdirSync(target, { recursive: true });
26
- const crons = CronService.loadAnnotations(Console.webda.getServices());
27
- crons.forEach((cron) => {
28
- cron.cronId = CronService.getCronId(cron, "export");
29
- const filename = join(target, Console.app.replaceVariables(filenameTemplate, { ...cron, ext }));
30
- Console.log("DEBUG", `Exporting ${filename} cron with ${cron.toString()}`);
31
- writeFileSync(filename, CronReplace(template, cron, Console.app));
32
- });
33
- Console.log("INFO", `Exported ${crons.length} crons`);
34
- }
35
- }
36
- }
37
- /**
38
- * Create the command line parser
39
- *
40
- * @param y
41
- * @returns
42
- */
43
- function yargs(y) {
44
- return y.command("cronExport [template] [targetDir]", "Export all application Cron as template", yarg => {
45
- yarg.option("filenameTemplate", {
46
- default: "${serviceName}.${method}-${cronId}.${ext}",
47
- description: "Filename template to use"
48
- });
49
- });
50
- }
51
- const ShellCommand = KubernetesShell.shellCommand;
52
- export { ShellCommand, yargs };
53
- //# sourceMappingURL=shell.js.map
package/lib/shell.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"shell.js","sourceRoot":"","sources":["../src/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,OAAO,eAAe;IAC1B,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI;QACrC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,aAAa;YACb,MAAM,WAAW,GAAQ,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;YACtD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC;YACxC,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;YAC7B,MAAM,gBAAgB,GACpB,IAAI,CAAC,gBAAgB,IAAI,uEAAuE,CAAC;YACnG,IAAI,GAAG,CAAC;YACR,IAAI,QAAQ,EAAE,CAAC;gBACb,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBACrC,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,QAAQ,GAAG,WAAW,CAAC,2BAA2B,CAAC;gBACnD,GAAG,GAAG,MAAM,CAAC;YACf,CAAC;YACD,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;AACL,CAAC;AAED,MAAM,YAAY,GAAG,eAAe,CAAC,YAAY,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC"}
package/webda.shell.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "commands": {
3
- "kubernetes": {
4
- "require": "./lib/shell.js",
5
- "export": "ShellCommand",
6
- "description": "Manage Kubernetes",
7
- "command": "kubernetes cronExport [template] [target]"
8
- }
9
- }
10
- }