mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
130bfec468 | ||
|
|
ddb3c79657 | ||
|
|
47cf43b44e |
@@ -37,8 +37,8 @@ class GenerateSecretResource extends CustomResource<typeof generateSecretSpecSch
|
|||||||
const current = decodeSecret(this.#secretResource.data) || {};
|
const current = decodeSecret(this.#secretResource.data) || {};
|
||||||
|
|
||||||
const expected = {
|
const expected = {
|
||||||
...current,
|
|
||||||
...secrets,
|
...secrets,
|
||||||
|
...current,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isDeepSubset(current, expected)) {
|
if (!isDeepSubset(current, expected)) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const postgresDatabaseSecretSchema = z.object({
|
|||||||
port: z.string(),
|
port: z.string(),
|
||||||
user: z.string(),
|
user: z.string(),
|
||||||
password: z.string(),
|
password: z.string(),
|
||||||
|
database: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const postgresDatabaseConnectionSecretSchema = z.object({
|
const postgresDatabaseConnectionSecretSchema = z.object({
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ class PostgresDatabaseResource extends CustomResource<typeof postgresDatabaseSpe
|
|||||||
port: serverSecretData.data.port,
|
port: serverSecretData.data.port,
|
||||||
user: this.#userName,
|
user: this.#userName,
|
||||||
database: this.#dbName,
|
database: this.#dbName,
|
||||||
|
...databaseSecretData.data,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isDeepSubset(databaseSecretData.data, expectedSecret)) {
|
if (!isDeepSubset(databaseSecretData.data, expectedSecret)) {
|
||||||
@@ -132,7 +133,7 @@ class PostgresDatabaseResource extends CustomResource<typeof postgresDatabaseSpe
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const secretData = postgresDatabaseConnectionSecretSchema.safeParse(decodeSecret(this.#serverSecret.current?.data));
|
const secretData = postgresDatabaseConnectionSecretSchema.safeParse(decodeSecret(this.#databaseSecret.data));
|
||||||
if (!secretData.success || !secretData.data) {
|
if (!secretData.success || !secretData.data) {
|
||||||
return {
|
return {
|
||||||
ready: false,
|
ready: false,
|
||||||
@@ -145,6 +146,7 @@ class PostgresDatabaseResource extends CustomResource<typeof postgresDatabaseSpe
|
|||||||
const database = postgresService.get({
|
const database = postgresService.get({
|
||||||
...connectionSecretData.data,
|
...connectionSecretData.data,
|
||||||
port: connectionSecretData.data.port ? Number(connectionSecretData.data.port) : 5432,
|
port: connectionSecretData.data.port ? Number(connectionSecretData.data.port) : 5432,
|
||||||
|
database: connectionSecretData.data.database,
|
||||||
});
|
});
|
||||||
await database.upsertRole({
|
await database.upsertRole({
|
||||||
name: secretData.data.user,
|
name: secretData.data.user,
|
||||||
@@ -166,8 +168,8 @@ class PostgresDatabaseResource extends CustomResource<typeof postgresDatabaseSpe
|
|||||||
}
|
}
|
||||||
this.#updateSecret();
|
this.#updateSecret();
|
||||||
await Promise.allSettled([
|
await Promise.allSettled([
|
||||||
await this.reconcileSubresource(DATABASE_READY_CONDITION, this.#reconcileDatabase),
|
this.reconcileSubresource(DATABASE_READY_CONDITION, this.#reconcileDatabase),
|
||||||
await this.reconcileSubresource(SECRET_READY_CONDITION, this.#reconcileSecret),
|
this.reconcileSubresource(SECRET_READY_CONDITION, this.#reconcileSecret),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const secretReady = this.conditions.get(SECRET_READY_CONDITION)?.status === 'True';
|
const secretReady = this.conditions.get(SECRET_READY_CONDITION)?.status === 'True';
|
||||||
|
|||||||
@@ -79,4 +79,4 @@ const customResourceService = services.get(CustomResourceService);
|
|||||||
customResourceService.register(...customResources);
|
customResourceService.register(...customResources);
|
||||||
|
|
||||||
await customResourceService.install(true);
|
await customResourceService.install(true);
|
||||||
// await customResourceService.watch();
|
await customResourceService.watch();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ type PostgresInstanceOptions = {
|
|||||||
port?: number;
|
port?: number;
|
||||||
user: string;
|
user: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
database?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PostgresInstance {
|
class PostgresInstance {
|
||||||
@@ -23,6 +24,7 @@ class PostgresInstance {
|
|||||||
user: process.env.FORCE_PG_USER ?? options.user,
|
user: process.env.FORCE_PG_USER ?? options.user,
|
||||||
password: process.env.FORCE_PG_PASSWORD ?? options.password,
|
password: process.env.FORCE_PG_PASSWORD ?? options.password,
|
||||||
port: process.env.FORCE_PG_PORT ? parseInt(process.env.FORCE_PG_PORT) : options.port,
|
port: process.env.FORCE_PG_PORT ? parseInt(process.env.FORCE_PG_PORT) : options.port,
|
||||||
|
database: options.database,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user