-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { spawnSync } from "child_process"; | ||
|
||
export function zarfExec(args: string[], captureOutput = false) { | ||
const argString = args.join(" ") | ||
return spawnSync( | ||
`uds zarf ${argString}`, { | ||
// Run command in a shell | ||
shell: true, | ||
// Print the command output directly to the shell if we don'e want to capture it (useful for debugging) | ||
stdio: captureOutput ? undefined : 'inherit' | ||
}); | ||
} | ||
|
||
export async function retry(funcCb: Function, retries = 3, timeout = 3000) { | ||
let result = false | ||
for (let i = 0; i < retries; i++) { | ||
await new Promise(r => setTimeout(r, timeout)) | ||
result = await funcCb() | ||
if (result) { | ||
break | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import { expect, test} from '@jest/globals'; | ||
import { K8s, kind } from "kubernetes-fluent-client"; | ||
import { spawnSync } from "child_process"; | ||
import { zarfExec, retry } from "../common"; | ||
|
||
test('test registration of the runner succeeded', async () => { | ||
let foundRegistrationSuccess = false | ||
for (let i = 0; i < 3; i++) { | ||
await new Promise(r => setTimeout(r, 3000)) | ||
let foundRegistrationSuccess = await retry(async () => { | ||
const runnerPods = await K8s(kind.Pod).InNamespace("gitlab-runner").WithLabel("app", "gitlab-runner").Get() | ||
if (runnerPods.items.at(0)?.status?.phase === "Running") { | ||
const podName = runnerPods.items.at(0)?.metadata?.name | ||
const runnerLogs = spawnSync( | ||
`uds zarf tools kubectl logs -n gitlab-runner ${podName} -c gitlab-runner`, { | ||
shell: true, // Run command in a shell | ||
}); | ||
const podName = runnerPods.items.at(0)?.metadata?.name! | ||
const runnerLogs = zarfExec(["tools", "kubectl", "logs", "-n", "gitlab-runner", podName, "-c", "gitlab-runner"], true); | ||
if (runnerLogs.stdout.indexOf("Registering runner... succeeded") > -1) { | ||
foundRegistrationSuccess = true | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
}) | ||
expect(foundRegistrationSuccess).toBe(true) | ||
}); |