mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-30 09:19:27 +08:00
01cfe404ef
* Migrate build toolchain from ncc/Jest to esbuild/Vitest Replace the legacy ncc/Jest/Babel build stack with a modern ESM toolchain: Build: - Replace @vercel/ncc with esbuild (--platform=node --target=node20 --format=esm) - Add createRequire banner for CJS interop in ESM bundle - Add "type": "module" to package.json - Add tsc --noEmit typecheck script (esbuild strips types without checking) - Add typecheck to husky pre-commit hook Dependencies: - Bump @actions/core@3, exec@3, io@3, tool-cache@4 (ESM-only) - Replace jest/ts-jest/@babel/* with vitest@4 Tests: - Convert 29 test files: jest.fn()→vi.fn(), jest.mock()→vi.mock(), jest.spyOn()→vi.spyOn() - Fix vitest 4 compat: mockImplementation requires args, mock call tracking, await .rejects CI: - Update build step from ncc build → npm run build - Update composite action to use npm run build * Switch tsconfig to NodeNext module resolution Change module/moduleResolution from ES2022/bundler to NodeNext/NodeNext and target from ES2022 to ES2020. - Add .js extensions to all relative imports across 59 source/test files (required by NodeNext module resolution) - Add vitest/globals to tsconfig types array for global test API declarations
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
import * as core from '@actions/core'
|
|
|
|
import {Kubectl} from '../../types/kubectl.js'
|
|
|
|
import {BlueGreenDeployment} from '../../types/blueGreenTypes.js'
|
|
import {deployWithLabel, NONE_LABEL_VALUE} from './blueGreenHelper.js'
|
|
|
|
import {validateIngresses} from './ingressBlueGreenHelper.js'
|
|
import {validateServicesState} from './serviceBlueGreenHelper.js'
|
|
import {validateTrafficSplitsState} from './smiBlueGreenHelper.js'
|
|
|
|
export async function promoteBlueGreenIngress(
|
|
kubectl: Kubectl,
|
|
manifestObjects,
|
|
timeout?: string
|
|
): Promise<BlueGreenDeployment> {
|
|
//checking if anything to promote
|
|
const {areValid, invalidIngresses} = await validateIngresses(
|
|
kubectl,
|
|
manifestObjects.ingressEntityList,
|
|
manifestObjects.serviceNameMap
|
|
)
|
|
if (!areValid) {
|
|
throw new Error(
|
|
`Ingresses are not in promote state: ${invalidIngresses.toString()}`
|
|
)
|
|
}
|
|
|
|
// create stable deployments with new configuration
|
|
const result: BlueGreenDeployment = await deployWithLabel(
|
|
kubectl,
|
|
[].concat(
|
|
manifestObjects.deploymentEntityList,
|
|
manifestObjects.serviceEntityList
|
|
),
|
|
NONE_LABEL_VALUE,
|
|
timeout
|
|
)
|
|
|
|
// create stable services with new configuration
|
|
return result
|
|
}
|
|
|
|
export async function promoteBlueGreenService(
|
|
kubectl: Kubectl,
|
|
manifestObjects,
|
|
timeout?: string
|
|
): Promise<BlueGreenDeployment> {
|
|
// checking if services are in the right state ie. targeting green deployments
|
|
if (
|
|
!(await validateServicesState(kubectl, manifestObjects.serviceEntityList))
|
|
) {
|
|
throw new Error('Found services not in promote state')
|
|
}
|
|
|
|
// creating stable deployments with new configurations
|
|
return await deployWithLabel(
|
|
kubectl,
|
|
manifestObjects.deploymentEntityList,
|
|
NONE_LABEL_VALUE,
|
|
timeout
|
|
)
|
|
}
|
|
|
|
export async function promoteBlueGreenSMI(
|
|
kubectl: Kubectl,
|
|
manifestObjects,
|
|
timeout?: string
|
|
): Promise<BlueGreenDeployment> {
|
|
// checking if there is something to promote
|
|
if (
|
|
!(await validateTrafficSplitsState(
|
|
kubectl,
|
|
manifestObjects.serviceEntityList
|
|
))
|
|
) {
|
|
throw Error('Not in promote state SMI')
|
|
}
|
|
|
|
// create stable deployments with new configuration
|
|
return await deployWithLabel(
|
|
kubectl,
|
|
manifestObjects.deploymentEntityList,
|
|
NONE_LABEL_VALUE,
|
|
timeout
|
|
)
|
|
}
|