Skip to content
Draft
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
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"civo",
"crypted",
"descheduler",
"dyff",
"CNAMEs",
"encodedkey",
"envs",
Expand Down
34 changes: 33 additions & 1 deletion src/cmd/migrate.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { globSync } from 'glob'
import {
applyChanges,
Changes,
filterChanges,
needsMigration,
processDeletionEntry,
removeSopsArtifacts,
sopsMigration,
Expand Down Expand Up @@ -442,3 +442,35 @@ describe('processDeletionEntry', () => {
expect(mockDeleteFile).not.toHaveBeenCalled()
})
})

describe('needsMigration', () => {
const makeLoadYaml =
(repoSpecVersion: number | undefined, defaultSpecVersion: number | undefined) =>
async (path: string, _opts?: any): Promise<any> => {
if (path.includes('versions.yaml'))
return repoSpecVersion !== undefined ? { spec: { specVersion: repoSpecVersion } } : undefined
if (path.includes('defaults.yaml'))
return defaultSpecVersion !== undefined ? { versions: { specVersion: defaultSpecVersion } } : undefined
return undefined
}

it('returns true when repo specVersion differs from defaults specVersion', async () => {
const result = await needsMigration({ loadYaml: makeLoadYaml(69, 70) })
expect(result).toBe(true)
})

it('returns false when repo specVersion matches defaults specVersion', async () => {
const result = await needsMigration({ loadYaml: makeLoadYaml(70, 70) })
expect(result).toBe(false)
})

it('returns false when versions.yaml is missing', async () => {
const result = await needsMigration({ loadYaml: makeLoadYaml(undefined, 70) })
expect(result).toBe(false)
})

it('returns false when defaults.yaml is missing', async () => {
const result = await needsMigration({ loadYaml: makeLoadYaml(69, undefined) })
expect(result).toBe(false)
})
})
9 changes: 9 additions & 0 deletions src/cmd/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,15 @@ export const setAtPath = (path: string, values: Record<string, any>, value: stri
paths.forEach((p) => set(values, p, Array.isArray(value) ? [...value] : value))
}

export const needsMigration = async (deps = { loadYaml }): Promise<boolean> => {
const defaults = await deps.loadYaml(`${rootDir}/helmfile.d/snippets/defaults.yaml`, { noError: true })
const defaultSpecVersion: number = defaults?.versions?.specVersion
const versions = await deps.loadYaml(`${env.ENV_DIR}/env/settings/versions.yaml`, { noError: true })
const repoSpecVersion: number = versions?.spec?.specVersion
if (!repoSpecVersion || !defaultSpecVersion) return false
return repoSpecVersion !== defaultSpecVersion
}

export const migrate = async (): Promise<boolean> => {
const d = terminal(`cmd:${cmdName}:migrate`)
const argv: Arguments = getParsedArgs()
Expand Down
11 changes: 11 additions & 0 deletions src/operator/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import fs from 'fs'
import process from 'node:process'
import path from 'path'
import { retryInstallStep } from '../cmd/install'
import { commit } from '../cmd/commit'
import { needsMigration } from '../cmd/migrate'
import { terminal } from '../common/debug'
import { env } from '../common/envalid'
import { getStoredGitRepoConfig } from '../common/git-config'
import { getDefaultValues, writeValues } from '../common/values'
import { AplOperations } from './apl-operations'
import { AplOperator, AplOperatorConfig } from './apl-operator'
import { GitRepository } from './git-repository'
Expand Down Expand Up @@ -79,6 +82,14 @@ async function main(): Promise<void> {
await installer.ensureRecoveryPrerequisites()
await installer.applyRecoveryManifests()
await installer.recoverFromGit()
if (await needsMigration()) {
d.info('specVersion mismatch detected, running migration before install')
const defaultValues = await getDefaultValues()
await writeValues(defaultValues)
await aplOps.migrate()
const gitConfig = await getStoredGitRepoConfig()
await commit(gitConfig)
}
d.info('Recovery installation completed, switching installation mode to standard')
await installer.resetRecoveryModeToStandard()
await installer.reconcileInstall()
Expand Down
12 changes: 0 additions & 12 deletions tests/fixtures/env/teams/admin/services/misc-admin.yaml

This file was deleted.

Loading