Skip to content

Commit

Permalink
adding timeout to the rollout status
Browse files Browse the repository at this point in the history
  • Loading branch information
Vidya2606 committed Nov 19, 2024
1 parent bf768b3 commit 9f7d28b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
41 changes: 41 additions & 0 deletions src/types/kubectl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ describe('Kubectl class', () => {
it('checks rollout status', async () => {
const resourceType = 'type'
const name = 'name'
const timeout = '60s'
expect(await kubectl.checkRolloutStatus(resourceType, name)).toBe(
execReturn
)
Expand Down Expand Up @@ -399,6 +400,46 @@ describe('Kubectl class', () => {
],
{silent: false}
)

// with timeout
await kubectl.checkRolloutStatus(
resourceType,
name,
testNamespace,
timeout
)
expect(exec.getExecOutput).toBeCalledWith(
kubectlPath,
[
'rollout',
'status',
`${resourceType}/${name}`,
'--namespace',
testNamespace,
`--timeout=${timeout}`
],
{silent: false}
)

// overridden ns and timeout
await kubectl.checkRolloutStatus(
resourceType,
name,
otherNamespace,
timeout
)
expect(exec.getExecOutput).toBeCalledWith(
kubectlPath,
[
'rollout',
'status',
`${resourceType}/${name}`,
'--namespace',
otherNamespace,
`--timeout=${timeout}`
],
{silent: false}
)
})

it('gets resource', async () => {
Expand Down
13 changes: 8 additions & 5 deletions src/types/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ export class Kubectl {
public async checkRolloutStatus(
resourceType: string,
name: string,
namespace?: string
namespace?: string,
timeout?: string
): Promise<ExecOutput> {
return await this.execute(
['rollout', 'status', `${resourceType}/${name}`].concat(
this.getFlags(namespace)
)
const command = ['rollout', 'status', `${resourceType}/${name}`].concat(
this.getFlags(namespace)
)
if (timeout) {
command.push(`--timeout=${timeout}`)
}
return await this.execute(command)
}

public async getResource(
Expand Down
6 changes: 4 additions & 2 deletions src/utilities/manifestStabilityUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const POD = 'pod'

export async function checkManifestStability(
kubectl: Kubectl,
resources: Resource[]
resources: Resource[],
timeout?: string
): Promise<void> {
let rolloutStatusHasErrors = false
for (let i = 0; i < resources.length; i++) {
Expand All @@ -24,7 +25,8 @@ export async function checkManifestStability(
const result = await kubectl.checkRolloutStatus(
resource.type,
resource.name,
resource.namespace
resource.namespace,
timeout
)
checkForErrors([result])
} catch (ex) {
Expand Down

0 comments on commit 9f7d28b

Please sign in to comment.