This commit is contained in:
Morten Olsen
2025-07-31 08:51:50 +02:00
parent 523637d40f
commit 85d043aec3
6 changed files with 71 additions and 10 deletions

View File

@@ -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 };

View File

View File

@@ -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<TSpec extends TSchema> {
};
}
export { CustomResource, type CustomResourceConstructor, type CustomResourceHandlerOptions, type EnsureSecretOptions };
const createCustomResource = <TSpec extends TSchema>(
options: CustomResourceConstructor<TSpec> & {
update?: (options: CustomResourceHandlerOptions<TSpec>) => Promise<void>;
create?: (options: CustomResourceHandlerOptions<TSpec>) => Promise<void>;
delete?: (options: CustomResourceHandlerOptions<TSpec>) => Promise<void>;
},
) => {
return class extends CustomResource<TSpec> {
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,
};

View File

@@ -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 };