@webda/kubernetes 4.0.0-beta.2 → 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 +110 -0
- package/lib/cron.d.ts +2 -3
- package/lib/cron.d.ts.map +1 -1
- package/lib/cron.js +3 -3
- package/lib/cron.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/services/cronexporter.service.d.ts +26 -0
- package/lib/services/cronexporter.service.d.ts.map +1 -0
- package/lib/services/cronexporter.service.js +130 -0
- package/lib/services/cronexporter.service.js.map +1 -0
- package/lib/services/{kuberunner.d.ts → kuberunner.service.d.ts} +22 -10
- package/lib/services/kuberunner.service.d.ts.map +1 -0
- package/lib/services/{kuberunner.js → kuberunner.service.js} +21 -20
- package/lib/services/kuberunner.service.js.map +1 -0
- package/lib/utils/client.d.ts +9 -5
- package/lib/utils/client.d.ts.map +1 -1
- package/lib/utils/client.js +7 -6
- package/lib/utils/client.js.map +1 -1
- package/package.json +32 -43
- package/webda.module.json +194 -186
- package/lib/cron.spec.d.ts +0 -2
- package/lib/cron.spec.d.ts.map +0 -1
- package/lib/cron.spec.js +0 -38
- package/lib/cron.spec.js.map +0 -1
- package/lib/services/kuberunner.d.ts.map +0 -1
- package/lib/services/kuberunner.js.map +0 -1
- package/lib/services/kuberunner.spec.d.ts +0 -2
- package/lib/services/kuberunner.spec.d.ts.map +0 -1
- package/lib/services/kuberunner.spec.js +0 -116
- package/lib/services/kuberunner.spec.js.map +0 -1
- package/lib/shell.d.ts +0 -13
- package/lib/shell.d.ts.map +0 -1
- package/lib/shell.js +0 -53
- package/lib/shell.js.map +0 -1
- package/lib/utils/client.spec.d.ts +0 -2
- package/lib/utils/client.spec.d.ts.map +0 -1
- package/lib/utils/client.spec.js +0 -37
- package/lib/utils/client.spec.js.map +0 -1
- package/webda.shell.json +0 -10
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
|
+

|
|
8
|
+
|
|
9
|
+
[](https://gitter.im/loopingz/webda?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
10
|
+
[](https://codecov.io/gh/loopingz/webda.io)
|
|
11
|
+
[](https://sonarcloud.io/summary/new_code?id=loopingz_webda.io)
|
|
12
|
+

|
|
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 {
|
|
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,9 +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,
|
|
15
|
+
export declare function CronReplace(template: string | any, cron: CronDefinition, replacements?: any): any;
|
|
17
16
|
//# sourceMappingURL=cron.d.ts.map
|
package/lib/cron.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cron.d.ts","sourceRoot":"","sources":["../src/cron.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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,
|
|
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
|
|
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":"
|
|
1
|
+
{"version":3,"file":"cron.js","sourceRoot":"","sources":["../src/cron.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,QAAsB,EAAE,IAAoB,EAAE,YAAY,GAAQ,EAAE;IAC9F,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,EAAE,kBAAkB,CAAC,CAAC;QACnE,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,uBAAuB,EAAE,6BAA6B,CAAC,CAAC;QAC9E,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,IAAI,CAAC,KAAK,CACnB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAA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ED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
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
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,UAAU,CACd,QAAiB,EACjB,MAAM,GAAW,SAAS,EAC1B,gBAAgB,GAAW,uEAAuE,EAClG,KAAc;gBAEd,IAAI,GAAW,CAAC;gBAChB,IAAI,OAAe,CAAC;gBACpB,IAAI,QAAQ,EAAE,CAAC;oBACb,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,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AAC;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
|
|
11
|
+
config?: string | K8sConfiguration;
|
|
13
12
|
/**
|
|
14
13
|
* Default context to use
|
|
15
14
|
*/
|
|
@@ -22,10 +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
|
-
|
|
24
|
+
/**
|
|
25
|
+
* @override
|
|
26
|
+
* @param params - the input parameters
|
|
27
|
+
* @returns this
|
|
28
|
+
*/
|
|
29
|
+
load(params?: any): this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Kubernetes object reference returned by the KubeRunner
|
|
33
|
+
*/
|
|
34
|
+
export interface KubeJobReference {
|
|
35
|
+
metadata: k8s.V1ObjectMeta;
|
|
36
|
+
apiVersion: string;
|
|
37
|
+
kind: string;
|
|
26
38
|
}
|
|
27
39
|
/**
|
|
28
|
-
* Run a Job
|
|
40
|
+
* Run a Job on a Kubernetes cluster
|
|
29
41
|
*
|
|
30
42
|
* @WebdaModda
|
|
31
43
|
*/
|
|
@@ -33,16 +45,16 @@ export default class KubeRunner<T extends KubeRunnerParameters = KubeRunnerParam
|
|
|
33
45
|
client: k8s.KubernetesObjectApi;
|
|
34
46
|
/**
|
|
35
47
|
* @inheritdoc
|
|
48
|
+
* @param _action - the action to launch
|
|
49
|
+
* @param info - the job information
|
|
50
|
+
* @returns the created job reference
|
|
36
51
|
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @inheritdoc
|
|
40
|
-
*/
|
|
41
|
-
launchAction(_action: AsyncAction, info: JobInfo): Promise<k8s.V1Job>;
|
|
52
|
+
launchAction(_action: AsyncAction, info: JobInfo): Promise<KubeJobReference>;
|
|
42
53
|
/**
|
|
43
54
|
* @inheritdoc
|
|
55
|
+
* @returns this
|
|
44
56
|
*/
|
|
45
57
|
resolve(): this;
|
|
46
58
|
}
|
|
47
59
|
export { KubeRunner };
|
|
48
|
-
//# sourceMappingURL=kuberunner.d.ts.map
|
|
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 {
|
|
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,46 +19,45 @@ spec:
|
|
|
18
19
|
* Parameters for the KubeRunner
|
|
19
20
|
*/
|
|
20
21
|
export class KubeRunnerParameters extends RunnerParameters {
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
42
|
-
|
|
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.
|
|
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) {
|
|
60
|
+
if (resources.spec?.template?.spec?.containers) {
|
|
61
61
|
for (const cont of resources.spec.template.spec.containers) {
|
|
62
62
|
cont.env ?? (cont.env = []);
|
|
63
63
|
for (const envKey in info) {
|
|
@@ -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.
|
|
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,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAA0C,MAAM,oBAAoB,CAAC;AAEpG,MAAM,sBAAsB,GAAG;;;;;;;;;;;;CAY9B,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,gBAAgB;IAkBxD;;;;OAIG;IACH,IAAI,CAAC,MAAM,GAAQ,EAAE;QACnB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,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,oFAAoF;YACpF,IAAI,CAAC,YAAY,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,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"}
|
package/lib/utils/client.d.ts
CHANGED
|
@@ -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,9 +28,10 @@ export interface K8sConfiguration {
|
|
|
25
28
|
users: k8s.User[];
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param params
|
|
30
|
-
* @
|
|
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;
|
|
33
37
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"
|
|
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"}
|
package/lib/utils/client.js
CHANGED
|
@@ -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
|
-
* @
|
|
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);
|
package/lib/utils/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAgBzC;;;;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;AAYD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA4B,EAAE,GAAS;IAC5E,MAAM,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,EAAE,CAAC,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"}
|