mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-28 15:59:27 +08:00
Add timeout to the rollout status (#425)
* Added timeout to the rollout status and tests for it * Fixed integration test errors * Fix for blue green integration test * Probable fix for integration errors * No jobs run error fixed * Changed timeout to file level constant * Added parsing logic for timeout * Made tests more concise * implemented timeout validation check in an extracted utils mod * Changed function name to parseDuration * Removed timeout parameter from getResource --------- Co-authored-by: David Gamero <david340804@gmail.com> Co-authored-by: Suneha Bose <123775811+bosesuneha@users.noreply.github.com>
This commit is contained in:
@@ -16,7 +16,9 @@ import {
|
||||
import {
|
||||
routeBlueGreenIngress,
|
||||
routeBlueGreenService,
|
||||
routeBlueGreenForDeploy
|
||||
routeBlueGreenForDeploy,
|
||||
routeBlueGreenSMI,
|
||||
routeBlueGreenIngressUnchanged
|
||||
} from './route'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
@@ -117,3 +119,141 @@ describe('route function tests', () => {
|
||||
).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
||||
// Timeout tests
|
||||
describe('route timeout tests', () => {
|
||||
let testObjects: BlueGreenManifests
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
jest
|
||||
.spyOn(fileHelper, 'writeObjectsToFile')
|
||||
.mockImplementationOnce(() => [''])
|
||||
})
|
||||
|
||||
test('routeBlueGreenService with timeout', async () => {
|
||||
const timeout = '240s'
|
||||
|
||||
// Mock deployObjects to capture timeout parameter
|
||||
const deployObjectsSpy = jest
|
||||
.spyOn(require('./blueGreenHelper'), 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: {exitCode: 0, stderr: '', stdout: ''},
|
||||
manifestFiles: []
|
||||
})
|
||||
|
||||
const value = await routeBlueGreenService(
|
||||
kc,
|
||||
GREEN_LABEL_VALUE,
|
||||
testObjects.serviceEntityList,
|
||||
timeout
|
||||
)
|
||||
|
||||
expect(deployObjectsSpy).toHaveBeenCalledWith(
|
||||
kc,
|
||||
expect.any(Array),
|
||||
timeout
|
||||
)
|
||||
expect(value.objects).toHaveLength(1)
|
||||
|
||||
deployObjectsSpy.mockRestore()
|
||||
})
|
||||
|
||||
test('routeBlueGreenSMI with timeout', async () => {
|
||||
const timeout = '300s'
|
||||
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
|
||||
// Mock deployObjects and createTrafficSplitObject to capture timeout parameter
|
||||
const deployObjectsSpy = jest
|
||||
.spyOn(require('./blueGreenHelper'), 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: {exitCode: 0, stderr: '', stdout: ''},
|
||||
manifestFiles: []
|
||||
})
|
||||
|
||||
const createTrafficSplitSpy = jest
|
||||
.spyOn(require('./smiBlueGreenHelper'), 'createTrafficSplitObject')
|
||||
.mockResolvedValue({
|
||||
metadata: {name: 'nginx-service-trafficsplit'},
|
||||
spec: {backends: []}
|
||||
})
|
||||
|
||||
const value = await routeBlueGreenSMI(
|
||||
kc,
|
||||
GREEN_LABEL_VALUE,
|
||||
testObjects.serviceEntityList,
|
||||
timeout
|
||||
)
|
||||
|
||||
expect(createTrafficSplitSpy).toHaveBeenCalledWith(
|
||||
kc,
|
||||
'nginx-service',
|
||||
GREEN_LABEL_VALUE,
|
||||
timeout
|
||||
)
|
||||
expect(deployObjectsSpy).toHaveBeenCalledWith(
|
||||
kc,
|
||||
expect.any(Array),
|
||||
timeout
|
||||
)
|
||||
|
||||
deployObjectsSpy.mockRestore()
|
||||
createTrafficSplitSpy.mockRestore()
|
||||
})
|
||||
|
||||
test('routeBlueGreenIngressUnchanged with timeout', async () => {
|
||||
const timeout = '180s'
|
||||
|
||||
// Mock deployObjects to capture timeout parameter
|
||||
const deployObjectsSpy = jest
|
||||
.spyOn(require('./blueGreenHelper'), 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: {exitCode: 0, stderr: '', stdout: ''},
|
||||
manifestFiles: []
|
||||
})
|
||||
|
||||
const value = await routeBlueGreenIngressUnchanged(
|
||||
kc,
|
||||
testObjects.serviceNameMap,
|
||||
testObjects.ingressEntityList,
|
||||
timeout
|
||||
)
|
||||
|
||||
expect(deployObjectsSpy).toHaveBeenCalledWith(
|
||||
kc,
|
||||
expect.any(Array),
|
||||
timeout
|
||||
)
|
||||
|
||||
deployObjectsSpy.mockRestore()
|
||||
})
|
||||
|
||||
test('route functions without timeout should pass undefined', async () => {
|
||||
const deployObjectsSpy = jest
|
||||
.spyOn(require('./blueGreenHelper'), 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: {exitCode: 0, stderr: '', stdout: ''},
|
||||
manifestFiles: []
|
||||
})
|
||||
|
||||
// Test routeBlueGreenService without timeout
|
||||
await routeBlueGreenService(
|
||||
kc,
|
||||
GREEN_LABEL_VALUE,
|
||||
testObjects.serviceEntityList
|
||||
)
|
||||
|
||||
expect(deployObjectsSpy).toHaveBeenCalledWith(
|
||||
kc,
|
||||
expect.any(Array),
|
||||
undefined
|
||||
)
|
||||
|
||||
deployObjectsSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user