mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
update
This commit is contained in:
23
src/instances/postgres-database.ts
Normal file
23
src/instances/postgres-database.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { postgresDatabaseSpecSchema } from '../custom-resouces/postgres-database/portgres-database.schemas.ts';
|
||||
import type { CustomResourceObject } from '../services/custom-resources/custom-resources.custom-resource.ts';
|
||||
import { ResourceInstance } from '../services/resources/resources.instance.ts';
|
||||
import { ResourceService } from '../services/resources/resources.ts';
|
||||
|
||||
import { SecretInstance } from './secret.ts';
|
||||
|
||||
class PostgresDatabaseInstance extends ResourceInstance<CustomResourceObject<typeof postgresDatabaseSpecSchema>> {
|
||||
public get secret() {
|
||||
const resourceService = this.services.get(ResourceService);
|
||||
return resourceService.getInstance(
|
||||
{
|
||||
apiVersion: 'v1',
|
||||
kind: 'Secret',
|
||||
name: `${this.name}-postgres-database`,
|
||||
namespace: this.namespace,
|
||||
},
|
||||
SecretInstance,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export { PostgresDatabaseInstance };
|
||||
@@ -1,20 +1,23 @@
|
||||
import type { V1Secret } from '@kubernetes/client-node';
|
||||
import type { z, ZodObject } from 'zod';
|
||||
|
||||
import { ResourceInstance } from '../services/resources/resources.instance.ts';
|
||||
import { decodeSecret, encodeSecret } from '../utils/secrets.ts';
|
||||
|
||||
class SecretInstance extends ResourceInstance<V1Secret> {
|
||||
class SecretInstance<T extends ZodObject = ExpectedAny> extends ResourceInstance<V1Secret> {
|
||||
public get values() {
|
||||
return decodeSecret(this.data);
|
||||
return decodeSecret(this.data) as z.infer<T>;
|
||||
}
|
||||
|
||||
public ensureData = async (values: Record<string, string>) => {
|
||||
public ensureData = async (values: z.infer<T>) => {
|
||||
await this.ensure({
|
||||
data: encodeSecret(values),
|
||||
data: encodeSecret(values as Record<string, string>),
|
||||
});
|
||||
};
|
||||
|
||||
public readonly ready = true;
|
||||
public get ready() {
|
||||
return this.exists;
|
||||
}
|
||||
}
|
||||
|
||||
export { SecretInstance };
|
||||
|
||||
Reference in New Issue
Block a user