mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
more
This commit is contained in:
26
src/crds/backup/backup-report.ts/backup-report.ts
Normal file
26
src/crds/backup/backup-report.ts/backup-report.ts
Normal 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 };
|
||||
0
src/crds/backup/backup/backup.ts
Normal file
0
src/crds/backup/backup/backup.ts
Normal 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,
|
||||
};
|
||||
|
||||
8
src/utils/types.d.ts
vendored
8
src/utils/types.d.ts
vendored
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user