Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/breezy-runtime-drops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tsops/core": patch
"tsops": patch
---

Do not require generated runtime database Secrets for built-in drop-schema jobs;
the drop SQL only needs lifecycle credentials and resolved metadata.
17 changes: 14 additions & 3 deletions packages/core/src/operations/db-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ export async function runDatabasePostDestroy(
lifecycleSecret,
vars,
schema,
sqlSteps: buildDropSchemaSqlSteps(database, vars, schema)
sqlSteps: buildDropSchemaSqlSteps(database, vars, schema),
includeRuntimeSecretEnv: false
})
await kubectl.apply(job, { namespace })
return { jobName }
Expand Down Expand Up @@ -455,8 +456,18 @@ function renderPsqlJob(input: {
vars: OverlayVars
schema: string
sqlSteps: string[]
includeRuntimeSecretEnv?: boolean
}): SupportedManifest {
const { namespace, name, database, lifecycleSecret, vars, schema, sqlSteps } = input
const {
namespace,
name,
database,
lifecycleSecret,
vars,
schema,
sqlSteps,
includeRuntimeSecretEnv = true
} = input
const sql = shellDoubleQuoted(sqlSteps.join('; '))

const job = {
Expand Down Expand Up @@ -490,7 +501,7 @@ function renderPsqlJob(input: {
}
},
...renderDatabaseMetadataEnv(database, vars, schema),
...renderRuntimeSecretEnv(database, vars)
...(includeRuntimeSecretEnv ? renderRuntimeSecretEnv(database, vars) : [])
]
}
]
Expand Down
10 changes: 10 additions & 0 deletions tests/overlay-lifecycle-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,12 @@ describe('overlay lifecycle preview contract', () => {

const job = applied(kubectl, 'Job', 'tsops-db-drop-pr-857')[0] as any
const command = job.spec.template.spec.containers[0].args[0] as string
const env = Object.fromEntries(
job.spec.template.spec.containers[0].env.map((item: any) => [
item.name,
item.value ?? item.valueFrom
])
)

expect(command).toContain('pg_depend')
expect(command).toContain('cross-schema dependencies')
Expand All @@ -691,6 +697,10 @@ describe('overlay lifecycle preview contract', () => {
)
expect(command).toContain('DROP SCHEMA IF EXISTS \\"pr_857\\" CASCADE')
expect(command).toContain('DROP ROLE IF EXISTS \\"worken_pr_857_app\\"')
expect(env.DATABASE_RUNTIME_ROLE).toBe('worken_pr_857_app')
expect(env.DATABASE_RUNTIME_SECRET_NAME).toBe('pr-857-db-app')
expect(env.DATABASE_RUNTIME_URL).toBeUndefined()
expect(env.DATABASE_RUNTIME_PASSWORD).toBeUndefined()
expect(kubectl.waited).toContainEqual({
name: 'tsops-db-drop-pr-857',
namespace: 'pr-857',
Expand Down