From 85d043aec320aaee460fc5406dcabd6d44a4822b Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Thu, 31 Jul 2025 08:51:50 +0200 Subject: [PATCH] more --- package.json | 3 ++- pnpm-lock.yaml | 17 +++++++----- .../backup/backup-report.ts/backup-report.ts | 26 ++++++++++++++++++ src/crds/backup/backup/backup.ts | 0 src/custom-resource/custom-resource.base.ts | 27 ++++++++++++++++++- src/utils/types.d.ts | 8 +++++- 6 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 src/crds/backup/backup-report.ts/backup-report.ts create mode 100644 src/crds/backup/backup/backup.ts diff --git a/package.json b/package.json index e403f12..4355c84 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "openapi-fetch": "^0.14.0", "pg": "^8.16.3", "sqlite3": "^5.1.7", - "yaml": "^2.8.0" + "yaml": "^2.8.0", + "zod": "^4.0.14" }, "packageManager": "pnpm@10.6.0", "pnpm": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c647049..f5f9a3e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,11 +4,6 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false -patchedDependencies: - '@kubernetes/client-node': - hash: 0b0e5d32aa2930107c8c9b45df2639faf53fa12a389a551885d6e42d71f9429d - path: patches/@kubernetes__client-node.patch - importers: .: @@ -18,7 +13,7 @@ importers: version: 2025.6.3-1751754396 '@kubernetes/client-node': specifier: ^1.3.0 - version: 1.3.0(patch_hash=0b0e5d32aa2930107c8c9b45df2639faf53fa12a389a551885d6e42d71f9429d)(encoding@0.1.13) + version: 1.3.0(encoding@0.1.13) '@sinclair/typebox': specifier: ^0.34.38 version: 0.34.38 @@ -40,6 +35,9 @@ importers: yaml: specifier: ^2.8.0 version: 2.8.0 + zod: + specifier: ^4.0.14 + version: 4.0.14 devDependencies: '@eslint/eslintrc': specifier: 3.3.1 @@ -2484,6 +2482,9 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} + zod@4.0.14: + resolution: {integrity: sha512-nGFJTnJN6cM2v9kXL+SOBq3AtjQby3Mv5ySGFof5UGRHrRioSJ5iG680cYNjE/yWk671nROcpPj4hAS8nyLhSw==} + snapshots: '@babel/code-frame@7.27.1': @@ -2566,7 +2567,7 @@ snapshots: dependencies: jsep: 1.4.0 - '@kubernetes/client-node@1.3.0(patch_hash=0b0e5d32aa2930107c8c9b45df2639faf53fa12a389a551885d6e42d71f9429d)(encoding@0.1.13)': + '@kubernetes/client-node@1.3.0(encoding@0.1.13)': dependencies: '@types/js-yaml': 4.0.9 '@types/node': 22.16.5 @@ -5275,3 +5276,5 @@ snapshots: yargs-parser@21.1.1: {} yocto-queue@0.1.0: {} + + zod@4.0.14: {} diff --git a/src/crds/backup/backup-report.ts/backup-report.ts b/src/crds/backup/backup-report.ts/backup-report.ts new file mode 100644 index 0000000..39f3f09 --- /dev/null +++ b/src/crds/backup/backup-report.ts/backup-report.ts @@ -0,0 +1,26 @@ +import { createCustomResource } from '../../../custom-resource/custom-resource.base.ts'; + +const backupReportSchema = z.object({ + spec: z.object({ + startedAt: z.string({ + format: 'date-time', + }), + finishedAt: z.string({ + format: 'date-time', + }), + status: z.enum(['success', 'failed']), + error: z.string().optional(), + message: z.string().optional(), + }), +}); + +const BackupReport = createCustomResource({ + kind: 'BackupReport', + spec: backupReportSchema, + names: { + plural: 'backupreports', + singular: 'backupreport', + }, +}); + +export { BackupReport }; diff --git a/src/crds/backup/backup/backup.ts b/src/crds/backup/backup/backup.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/custom-resource/custom-resource.base.ts b/src/custom-resource/custom-resource.base.ts index d5f194a..78d878d 100644 --- a/src/custom-resource/custom-resource.base.ts +++ b/src/custom-resource/custom-resource.base.ts @@ -2,6 +2,7 @@ import { type Static, type TObject, type TSchema } from '@sinclair/typebox'; import { GROUP } from '../utils/consts.ts'; import type { Services } from '../utils/service.ts'; +import { noopAsync } from '../utils/types.js'; import { customResourceStatusSchema, type CustomResourceRequest } from './custom-resource.request.ts'; @@ -103,4 +104,28 @@ abstract class CustomResource { }; } -export { CustomResource, type CustomResourceConstructor, type CustomResourceHandlerOptions, type EnsureSecretOptions }; +const createCustomResource = ( + options: CustomResourceConstructor & { + update?: (options: CustomResourceHandlerOptions) => Promise; + create?: (options: CustomResourceHandlerOptions) => Promise; + delete?: (options: CustomResourceHandlerOptions) => Promise; + }, +) => { + return class extends CustomResource { + constructor() { + super(options); + } + + public update = options.update ?? noopAsync; + public create = options.create; + public delete = options.delete; + }; +}; + +export { + CustomResource, + type CustomResourceConstructor, + type CustomResourceHandlerOptions, + type EnsureSecretOptions, + createCustomResource, +}; diff --git a/src/utils/types.d.ts b/src/utils/types.d.ts index c25abd9..9155f10 100644 --- a/src/utils/types.d.ts +++ b/src/utils/types.d.ts @@ -3,4 +3,10 @@ declare global { type ExpectedAny = any; } -export {}; +// eslint-disable-next-line @typescript-eslint/no-empty-function +const noop = () => {}; + +// eslint-disable-next-line @typescript-eslint/no-empty-function +const noopAsync = async () => {}; + +export { noop, noopAsync };