Skip to content

Commit ed0cc45

Browse files
authored
Upgraded k8s (#189)
* Upgraded k8s * Fixed database to fail if it could not be created (caused by race condition during k8s upgrades and Pulumi thinking the database exists) * Updated to latest k8s version * Updated to latest 1.34 k8s version
1 parent 5805e6f commit ed0cc45

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

infrastructure/pulumi/Pulumi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ config:
1010
value:
1111
name: aphiria-com-cluster
1212
region: nyc3
13-
version: 1.34.1-do.4
13+
version: 1.34.5-do.0
1414
autoUpgrade: true
1515
surgeUpgrade: false
1616
ha: false

infrastructure/pulumi/src/components/db-creation.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ export function createDatabaseCreationJob(args: DatabaseCreationJobArgs): k8s.ba
105105
command: [
106106
"sh",
107107
"-c",
108-
`psql -c "CREATE DATABASE ${args.databaseName};" || echo "Database already exists (this is normal on re-runs)"`,
108+
[
109+
`output=$(psql -c "CREATE DATABASE ${args.databaseName};" 2>&1)`,
110+
"rc=$?",
111+
'if [ $rc -eq 0 ]; then echo "Database created successfully"',
112+
'elif echo "$output" | grep -q "already exists"; then echo "Database already exists (this is normal on re-runs)"',
113+
'else echo "FATAL: Failed to create database: $output" >&2; exit 1',
114+
"fi",
115+
].join("; "),
109116
],
110117
resources: DEFAULT_RESOURCES,
111118
},

infrastructure/pulumi/tests/components/db-creation.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ describe("createDatabaseCreationJob", () => {
7474
expect(namespace).toBe("preview-pr-456");
7575
});
7676

77+
it("should use a command that only tolerates 'already exists' errors", async () => {
78+
const job = createDatabaseCreationJob({
79+
namespace: "preview-pr-123",
80+
databaseName: "aphiria_pr_123",
81+
dbHost: "db.default.svc.cluster.local",
82+
dbAdminUser: pulumi.output("postgres"),
83+
dbAdminPassword: pulumi.output("admin-password"),
84+
provider: k8sProvider,
85+
});
86+
87+
const spec = await promiseOf(job.spec);
88+
const command = spec!.template.spec!.containers[0].command!;
89+
const shellCommand = command[2] as string;
90+
91+
// Must capture psql output and exit code
92+
expect(shellCommand).toContain('output=$(psql -c "CREATE DATABASE aphiria_pr_123;"');
93+
// Must check for "already exists" specifically
94+
expect(shellCommand).toContain('grep -q "already exists"');
95+
// Must exit non-zero on unexpected errors
96+
expect(shellCommand).toContain("exit 1");
97+
});
98+
7799
it("should merge custom labels with default labels", async () => {
78100
const job = createDatabaseCreationJob({
79101
namespace: "preview-pr-789",

0 commit comments

Comments
 (0)