Skip to content

Commit af433ba

Browse files
feat: skip runtime upgrades on initial install (#2715)
Co-authored-by: svcAPLBot <174728082+svcAPLBot@users.noreply.github.com>
1 parent b79dba2 commit af433ba

File tree

4 files changed

+50
-38
lines changed

4 files changed

+50
-38
lines changed

package-lock.json

Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/k8s.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { resolveAny } from 'dns/promises'
2020
import { access, mkdir, writeFile } from 'fs/promises'
2121
import { isEmpty, isEqual, map, mapValues } from 'lodash'
2222
import { dirname, join } from 'path'
23+
import { Writable } from 'stream'
2324
import { parse, stringify } from 'yaml'
2425
import { $, cd, sleep } from 'zx'
2526
import { ARGOCD_APP_PARAMS, DEPLOYMENT_PASSWORDS_SECRET, DEPLOYMENT_STATUS_CONFIGMAP } from './constants'
@@ -28,7 +29,6 @@ import { env } from './envalid'
2829
import { hfValues } from './hf'
2930
import { parser } from './yargs'
3031
import { askYesNo } from './zx-enhance'
31-
import { Writable } from 'stream'
3232

3333
export const secretId = `secret/otomi/${DEPLOYMENT_PASSWORDS_SECRET}`
3434

@@ -124,8 +124,11 @@ export const getK8sSecret = async (name: string, namespace: string): Promise<Rec
124124
export interface DeploymentState {
125125
status?: 'deploying' | 'deployed'
126126
tag?: string
127+
// semantic version string (without 'v' prefix)
127128
version?: string
129+
// container image tag (can be an arbitrary name)
128130
deployingTag?: string
131+
// semantic version string (without 'v' prefix)
129132
deployingVersion?: string
130133
}
131134

src/common/runtime-upgrade.test.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { getApplications } from 'src/cmd/apply-as-apps'
22
import { terminal } from './debug'
3+
import { deployEssential } from './hf'
34
import { getDeploymentState, k8s, waitForArgoCDAppHealthy, waitForArgoCDAppSync } from './k8s'
45
import { filterRuntimeUpgrades, runtimeUpgrade } from './runtime-upgrade'
56
import { RuntimeUpgrades } from './runtime-upgrades/runtime-upgrades'
67
import { getCurrentVersion } from './values'
7-
import { deployEssential } from './hf'
88

99
jest.mock('./k8s')
1010
jest.mock('./hf')
@@ -43,7 +43,7 @@ describe('runtimeUpgrade', () => {
4343
info: jest.fn(),
4444
error: jest.fn(),
4545
}
46-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
46+
4747
mockTerminal.mockReturnValue(mockDebugger as any)
4848
})
4949

@@ -61,7 +61,6 @@ describe('runtimeUpgrade', () => {
6161
})
6262

6363
it('should skip runtime upgrade for null deployment state', async () => {
64-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
6564
mockGetDeploymentState.mockResolvedValue(null as any)
6665
mockGetCurrentVersion.mockResolvedValue('1.0.0')
6766

@@ -80,17 +79,17 @@ describe('runtimeUpgrade', () => {
8079

8180
await runtimeUpgrade({ when: 'pre' })
8281

83-
expect(mockDebugger.info).toHaveBeenCalledWith('Current version of otomi: 2.0.0')
82+
expect(mockDebugger.info).toHaveBeenCalledWith('The current version of the Akamai App Platform: 2.0.0')
83+
expect(mockDebugger.info).toHaveBeenCalledWith('Deploying essential manifests')
8484
expect(mockDebugger.info).toHaveBeenCalledWith('No runtime upgrade operations detected, skipping')
8585
})
8686

8787
it('should use current version when deployment state has no version', async () => {
88-
mockGetDeploymentState.mockResolvedValue({ status: 'deployed' })
89-
mockGetCurrentVersion.mockResolvedValue('1.0.0')
88+
mockGetDeploymentState.mockResolvedValue({ status: 'deployed', version: '1.0.0' })
9089

9190
await runtimeUpgrade({ when: 'pre' })
9291

93-
expect(mockDebugger.info).toHaveBeenCalledWith('Current version of otomi: 1.0.0')
92+
expect(mockDebugger.info).toHaveBeenCalledWith('The current version of the Akamai App Platform: 1.0.0')
9493
})
9594
})
9695

@@ -231,26 +230,16 @@ describe('runtimeUpgrade', () => {
231230
})
232231

233232
describe('filterRuntimeUpgrades', () => {
234-
const sampleUpgrades: RuntimeUpgrades = [
235-
{ version: '1.0.0' },
236-
{ version: '1.5.0' },
237-
{ version: '2.0.0' },
238-
{ version: 'dev' },
239-
]
233+
const sampleUpgrades: RuntimeUpgrades = [{ version: '1.0.0' }, { version: '1.5.0' }, { version: '2.0.0' }]
240234

241235
it('should filter upgrades newer than current version', () => {
242236
const result = filterRuntimeUpgrades('1.2.0', sampleUpgrades)
243-
expect(result).toEqual([{ version: '1.5.0' }, { version: '2.0.0' }, { version: 'dev' }])
244-
})
245-
246-
it('should include dev version regardless of current version', () => {
247-
const result = filterRuntimeUpgrades('99.0.0', sampleUpgrades)
248-
expect(result).toEqual([{ version: 'dev' }])
237+
expect(result).toEqual([{ version: '1.5.0' }, { version: '2.0.0' }])
249238
})
250239

251240
it('should return empty array when no upgrades are newer', () => {
252241
const result = filterRuntimeUpgrades('3.0.0', sampleUpgrades)
253-
expect(result).toEqual([{ version: 'dev' }])
242+
expect(result).toEqual([])
254243
})
255244

256245
it('should handle prerelease versions correctly', () => {
@@ -271,16 +260,16 @@ describe('filterRuntimeUpgrades', () => {
271260

272261
it('should not run with prereleases = version', () => {
273262
const result = filterRuntimeUpgrades('2.0.0-rc.2', sampleUpgrades)
274-
expect(result).toEqual([{ version: 'dev' }])
263+
expect(result).toEqual([])
275264
})
276265

277266
it('should not modify valid semantic versions', () => {
278267
const result = filterRuntimeUpgrades('1.0.0', sampleUpgrades)
279-
expect(result).toEqual([{ version: '1.5.0' }, { version: '2.0.0' }, { version: 'dev' }])
268+
expect(result).toEqual([{ version: '1.5.0' }, { version: '2.0.0' }])
280269
})
281270

282271
it('should handle edge case with exact version match', () => {
283272
const result = filterRuntimeUpgrades('1.5.0', sampleUpgrades)
284-
expect(result).toEqual([{ version: '2.0.0' }, { version: 'dev' }])
273+
expect(result).toEqual([{ version: '2.0.0' }])
285274
})
286275
})

src/common/runtime-upgrade.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { isEmpty } from 'lodash'
21
import semver from 'semver'
32
import { getApplications } from 'src/cmd/apply-as-apps'
43
import { terminal } from './debug'
54
import { getDeploymentState, k8s, waitForArgoCDAppHealthy, waitForArgoCDAppSync } from './k8s'
65
import { RuntimeUpgradeContext, RuntimeUpgrades, runtimeUpgrades } from './runtime-upgrades/runtime-upgrades'
7-
import { getCurrentVersion } from './values'
86
import { deployEssential } from './hf'
97

108
interface RuntimeUpgradeArgs {
@@ -15,23 +13,20 @@ export async function runtimeUpgrade({ when }: RuntimeUpgradeArgs): Promise<void
1513
const d = terminal('cmd:upgrade:runtimeUpgrade')
1614
const deploymentState = await getDeploymentState()
1715

18-
if (isEmpty(deploymentState)) {
16+
if (!deploymentState?.version) {
1917
d.info('Skipping the runtime upgrade procedure as this is the very first installation')
2018
return
2119
}
20+
const deployedVersion: string = deploymentState.version
21+
d.info(`The current version of the Akamai App Platform: ${deployedVersion}`)
2222

2323
d.info('Deploying essential manifests')
2424
const essentialDeployResult = await deployEssential(['upgrade=true'], true)
2525
if (!essentialDeployResult) {
2626
throw new Error('Failed to update namespaces')
2727
}
2828

29-
const declaredVersion = await getCurrentVersion()
30-
const deployedVersion: string = deploymentState.version ?? declaredVersion
3129
const apps = await getApplications()
32-
33-
d.info(`Current version of otomi: ${deployedVersion}`)
34-
3530
const filteredUpgrades = filterRuntimeUpgrades(deployedVersion, runtimeUpgrades)
3631

3732
if (filteredUpgrades.length === 0) {
@@ -85,5 +80,5 @@ export function filterRuntimeUpgrades(version: string, rUpgrades: RuntimeUpgrade
8580
if (!currentVersion) {
8681
throw new Error(`Unsupported version format: ${version}`)
8782
}
88-
return rUpgrades.filter((rUpgrade) => rUpgrade.version === 'dev' || semver.gt(rUpgrade.version, currentVersion))
83+
return rUpgrades.filter((rUpgrade) => semver.gt(rUpgrade.version, currentVersion))
8984
}

0 commit comments

Comments
 (0)