Compare commits

..
Author SHA1 Message Date
Nikola Jokic 70841b6972 bump docker dep as well 2025-04-16 14:43:46 +02:00
Nikola Jokic 1c2ae5d20a rework 2025-04-16 14:25:04 +02:00
Nikola Jokic 928f63d88a exclude eslint.config.js 2025-04-16 13:42:50 +02:00
Nikola Jokic 3bda7ef21e wip 2025-04-16 10:26:22 +02:00
Nikola Jokic 3b0e87c9a7 fmt 2025-04-15 14:53:53 +02:00
Nikola Jokic a7349e7d70 fix errors and bump client node to stable version 2025-04-15 14:53:21 +02:00
Nikola Jokic ff583c8917 bump all dependencies 2025-04-15 14:29:29 +02:00
30 changed files with 9648 additions and 18651 deletions
-4
View File
@@ -1,4 +0,0 @@
dist/
lib/
node_modules/
**/tests/**
-56
View File
@@ -1,56 +0,0 @@
{
"plugins": ["@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-constant-condition": "off",
"no-unused-vars": "off",
"i18n-text/no-en": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"camelcase": "off",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": ["error"]
},
"env": {
"node": true,
"es6": true
}
}
+82
View File
@@ -0,0 +1,82 @@
import { defineConfig, globalIgnores } from 'eslint/config'
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import globals from 'globals'
import tsParser from '@typescript-eslint/parser'
import github from 'eslint-plugin-github'
export default defineConfig([
globalIgnores(['**/dist/', '**/lib/', '**/node_modules/', '**/tests/**/*', 'eslint.config.js']),
github.getFlatConfigs().recommended,
{
plugins: {
'@typescript-eslint': typescriptEslint
},
files: ['packages/**/*.ts'],
languageOptions: {
globals: globals.node,
parser: tsParser,
ecmaVersion: 9,
sourceType: 'module',
parserOptions: {
project: './tsconfig.json'
}
},
rules: {
'eslint-comments/no-use': 'off',
'import/no-namespace': 'off',
'no-constant-condition': 'off',
'no-unused-vars': 'off',
'i18n-text/no-en': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
accessibility: 'no-public'
}
],
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/await-thenable': 'error',
camelcase: 'off',
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true
}
],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-for-of': 'warn',
'@typescript-eslint/prefer-function-type': 'warn',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/unbound-method': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error']
}
}
])
+1 -1
View File
@@ -4,7 +4,7 @@
"state": {}, "state": {},
"args": { "args": {
"container": { "container": {
"image": "node:22", "image": "node:14.16",
"workingDirectory": "/__w/repo/repo", "workingDirectory": "/__w/repo/repo",
"createOptions": "--cpus 1", "createOptions": "--cpus 1",
"environmentVariables": { "environmentVariables": {
+1 -1
View File
@@ -9,7 +9,7 @@
} }
}, },
"args": { "args": {
"image": "node:22", "image": "node:14.16",
"dockerfile": null, "dockerfile": null,
"entryPointArgs": [ "entryPointArgs": [
"-e", "-e",
+2782 -2893
View File
File diff suppressed because it is too large Load Diff
+9 -9
View File
@@ -1,6 +1,6 @@
{ {
"name": "hooks", "name": "hooks",
"version": "0.7.0", "version": "0.6.2",
"description": "Three projects are included - k8s: a kubernetes hook implementation that spins up pods dynamically to run a job - docker: A hook implementation of the runner's docker implementation - A hook lib, which contains shared typescript definitions and utilities that the other packages consume", "description": "Three projects are included - k8s: a kubernetes hook implementation that spins up pods dynamically to run a job - docker: A hook implementation of the runner's docker implementation - A hook lib, which contains shared typescript definitions and utilities that the other packages consume",
"main": "", "main": "",
"directories": { "directories": {
@@ -11,7 +11,7 @@
"bootstrap": "npm install --prefix packages/hooklib && npm install --prefix packages/k8s && npm install --prefix packages/docker", "bootstrap": "npm install --prefix packages/hooklib && npm install --prefix packages/k8s && npm install --prefix packages/docker",
"format": "prettier --write '**/*.ts'", "format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'", "format-check": "prettier --check '**/*.ts'",
"lint": "eslint packages/**/*.ts", "lint": "eslint",
"build-all": "npm run build --prefix packages/hooklib && npm run build --prefix packages/k8s && npm run build --prefix packages/docker" "build-all": "npm run build --prefix packages/hooklib && npm run build --prefix packages/k8s && npm run build --prefix packages/docker"
}, },
"repository": { "repository": {
@@ -25,12 +25,12 @@
}, },
"homepage": "https://github.com/actions/runner-container-hooks#readme", "homepage": "https://github.com/actions/runner-container-hooks#readme",
"devDependencies": { "devDependencies": {
"@types/jest": "^27.5.1", "@types/jest": "^29.5.14",
"@types/node": "^17.0.23", "@types/node": "^22.14.1",
"@typescript-eslint/parser": "^5.18.0", "@typescript-eslint/parser": "^8.30.1",
"eslint": "^8.12.0", "eslint": "^9.24.0",
"eslint-plugin-github": "^4.3.6", "eslint-plugin-github": "^6.0.0",
"prettier": "^2.6.2", "prettier": "^3.5.3",
"typescript": "^4.6.3" "typescript": "^5.8.3"
} }
} }
-13
View File
@@ -1,13 +0,0 @@
// eslint-disable-next-line import/no-commonjs
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*-test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
setupFilesAfterEnv: ['./jest.setup.js'],
verbose: true
}
+12
View File
@@ -0,0 +1,12 @@
{
"clearMocks": true,
"moduleFileExtensions": ["js", "ts"],
"testEnvironment": "node",
"testMatch": ["**/*-test.ts"],
"testRunner": "jest-circus/runner",
"transform": {
"^.+\\.ts$": "ts-jest"
},
"verbose": true,
"testTimeout": 500000
}
-1
View File
@@ -1 +0,0 @@
jest.setTimeout(500000)
+2058 -6271
View File
File diff suppressed because it is too large Load Diff
+12 -15
View File
@@ -5,29 +5,26 @@
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
"test": "jest --runInBand", "test": "jest --runInBand",
"build": "npx tsc && npx ncc build", "build": "npx tsc && npx ncc build"
"format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts"
}, },
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.9.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"hooklib": "file:../hooklib", "hooklib": "file:../hooklib",
"shlex": "^2.1.2", "shlex": "^2.1.2",
"uuid": "^8.3.2" "uuid": "^11.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.4.1", "@types/jest": "^29.5.14",
"@types/node": "^17.0.23", "@types/node": "^22.14.1",
"@typescript-eslint/parser": "^5.18.0", "@typescript-eslint/parser": "^8.30.1",
"@vercel/ncc": "^0.33.4", "@vercel/ncc": "^0.38.3",
"jest": "^27.5.1", "jest": "^29.7.0",
"ts-jest": "^27.1.4", "ts-jest": "^29.3.2",
"ts-node": "^10.7.0", "ts-node": "^10.9.2",
"tsconfig-paths": "^3.14.1", "tsconfig-paths": "^4.2.0",
"typescript": "^4.6.3" "typescript": "^5.8.3"
} }
} }
@@ -43,16 +43,11 @@ export async function createContainer(
if (args.environmentVariables) { if (args.environmentVariables) {
for (const [key] of Object.entries(args.environmentVariables)) { for (const [key] of Object.entries(args.environmentVariables)) {
dockerArgs.push('-e', key) dockerArgs.push('-e')
dockerArgs.push(key)
} }
} }
dockerArgs.push('-e', 'GITHUB_ACTIONS=true')
// Use same behavior as the runner https://github.com/actions/runner/blob/27d9c886ab9a45e0013cb462529ac85d581f8c41/src/Runner.Worker/Container/DockerCommandManager.cs#L150
if (!('CI' in (args.environmentVariables ?? {}))) {
dockerArgs.push('-e', 'CI=true')
}
const mountVolumes = [ const mountVolumes = [
...(args.userMountVolumes || []), ...(args.userMountVolumes || []),
...(args.systemMountVolumes || []) ...(args.systemMountVolumes || [])
@@ -408,16 +403,11 @@ export async function containerRun(
} }
if (args.environmentVariables) { if (args.environmentVariables) {
for (const [key] of Object.entries(args.environmentVariables)) { for (const [key] of Object.entries(args.environmentVariables)) {
dockerArgs.push('-e', key) dockerArgs.push('-e')
dockerArgs.push(key)
} }
} }
dockerArgs.push('-e', 'GITHUB_ACTIONS=true')
// Use same behavior as the runner https://github.com/actions/runner/blob/27d9c886ab9a45e0013cb462529ac85d581f8c41/src/Runner.Worker/Container/DockerCommandManager.cs#L150
if (!('CI' in (args.environmentVariables ?? {}))) {
dockerArgs.push('-e', 'CI=true')
}
const mountVolumes = [ const mountVolumes = [
...(args.userMountVolumes || []), ...(args.userMountVolumes || []),
...(args.systemMountVolumes || []) ...(args.systemMountVolumes || [])
@@ -75,22 +75,4 @@ describe('run script step', () => {
runScriptStep(definitions.runScriptStep.args, prepareJobResponse.state) runScriptStep(definitions.runScriptStep.args, prepareJobResponse.state)
).resolves.not.toThrow() ).resolves.not.toThrow()
}) })
it('Should confirm that CI and GITHUB_ACTIONS are set', async () => {
definitions.runScriptStep.args.entryPoint = '/bin/bash'
definitions.runScriptStep.args.entryPointArgs = [
'-c',
`'if [[ ! $(env | grep "^CI=") = "CI=true" ]]; then exit 1; fi'`
]
await expect(
runScriptStep(definitions.runScriptStep.args, prepareJobResponse.state)
).resolves.not.toThrow()
definitions.runScriptStep.args.entryPointArgs = [
'-c',
`'if [[ ! $(env | grep "^GITHUB_ACTIONS=") = "GITHUB_ACTIONS=true" ]]; then exit 1; fi'`
]
await expect(
runScriptStep(definitions.runScriptStep.args, prepareJobResponse.state)
).resolves.not.toThrow()
})
}) })
+2 -3
View File
@@ -45,9 +45,8 @@ export default class TestSetup {
public initialize(): void { public initialize(): void {
env['GITHUB_WORKSPACE'] = this.workingDirectory env['GITHUB_WORKSPACE'] = this.workingDirectory
env['RUNNER_NAME'] = 'test' env['RUNNER_NAME'] = 'test'
env[ env['RUNNER_TEMP'] =
'RUNNER_TEMP' `${this.runnerMockDir}/${this.runnerMockSubdirs.workTemp}`
] = `${this.runnerMockDir}/${this.runnerMockSubdirs.workTemp}`
for (const dir of this.allTestDirectories) { for (const dir of this.allTestDirectories) {
fs.mkdirSync(dir, { recursive: true }) fs.mkdirSync(dir, { recursive: true })
+2573 -2784
View File
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -14,15 +14,15 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^17.0.23", "@types/node": "^22.14.1",
"@typescript-eslint/parser": "^5.18.0", "@typescript-eslint/parser": "^8.30.1",
"@zeit/ncc": "^0.22.3", "@zeit/ncc": "^0.22.3",
"eslint": "^8.12.0", "eslint": "^9.24.0",
"eslint-plugin-github": "^4.3.6", "eslint-plugin-github": "^6.0.0",
"prettier": "^2.6.2", "prettier": "^3.5.3",
"typescript": "^4.6.3" "typescript": "^5.8.3"
}, },
"dependencies": { "dependencies": {
"@actions/core": "^1.9.1" "@actions/core": "^1.11.1"
} }
} }
-13
View File
@@ -1,13 +0,0 @@
// eslint-disable-next-line import/no-commonjs
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*-test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
setupFilesAfterEnv: ['./jest.setup.js'],
verbose: true
}
+12
View File
@@ -0,0 +1,12 @@
{
"clearMocks": true,
"moduleFileExtensions": ["js", "ts"],
"testEnvironment": "node",
"testMatch": ["**/*-test.ts"],
"testRunner": "jest-circus/runner",
"transform": {
"^.+\\.ts$": "ts-jest"
},
"verbose": true,
"testTimeout": 500000
}
-1
View File
@@ -1 +0,0 @@
jest.setTimeout(500000)
+1976 -6331
View File
File diff suppressed because it is too large Load Diff
+13 -11
View File
@@ -8,25 +8,27 @@
"build": "tsc && npx ncc build", "build": "tsc && npx ncc build",
"format": "prettier --write '**/*.ts'", "format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'", "format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts" "lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix"
}, },
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.9.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/io": "^1.1.2", "@actions/io": "^1.1.3",
"@kubernetes/client-node": "^0.22.2", "@kubernetes/client-node": "^1.1.2",
"hooklib": "file:../hooklib", "hooklib": "file:../hooklib",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"shlex": "^2.1.2" "shlex": "^2.1.2",
"uuid": "^11.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.4.1", "@types/jest": "^29.5.14",
"@types/node": "^17.0.23", "@types/node": "^22.14.1",
"@vercel/ncc": "^0.33.4", "@vercel/ncc": "^0.38.3",
"jest": "^27.5.1", "jest": "^29.7.0",
"ts-jest": "^27.1.4", "ts-jest": "^29.3.2",
"typescript": "^4.6.3" "typescript": "^5.8.3"
} }
} }
-12
View File
@@ -229,18 +229,6 @@ export function createContainerSpec(
} }
} }
podContainer.env.push({
name: 'GITHUB_ACTIONS',
value: 'true'
})
if (!('CI' in container['environmentVariables'])) {
podContainer.env.push({
name: 'CI',
value: 'true'
})
}
podContainer.volumeMounts = containerVolumes( podContainer.volumeMounts = containerVolumes(
container.userMountVolumes, container.userMountVolumes,
jobContainer jobContainer
+1 -8
View File
@@ -29,14 +29,7 @@ export async function runContainerStep(
let secretName: string | undefined = undefined let secretName: string | undefined = undefined
if (stepContainer.environmentVariables) { if (stepContainer.environmentVariables) {
try { try {
const envs = JSON.parse( secretName = await createSecretForEnvs(stepContainer.environmentVariables)
JSON.stringify(stepContainer.environmentVariables)
)
envs['GITHUB_ACTIONS'] = 'true'
if (!('CI' in envs)) {
envs.CI = 'true'
}
secretName = await createSecretForEnvs(envs)
} catch (err) { } catch (err) {
core.debug(`createSecretForEnvs failed: ${JSON.stringify(err)}`) core.debug(`createSecretForEnvs failed: ${JSON.stringify(err)}`)
const message = (err as any)?.response?.body?.message || err const message = (err as any)?.response?.body?.message || err
+73 -70
View File
@@ -127,8 +127,10 @@ export async function createPod(
mergePodSpecWithOptions(appPod.spec, extension.spec) mergePodSpecWithOptions(appPod.spec, extension.spec)
} }
const { body } = await k8sApi.createNamespacedPod(namespace(), appPod) return await k8sApi.createNamespacedPod({
return body namespace: namespace(),
body: appPod
})
} }
export async function createJob( export async function createJob(
@@ -183,46 +185,42 @@ export async function createJob(
} }
} }
const { body } = await k8sBatchV1Api.createNamespacedJob(namespace(), job) return await k8sBatchV1Api.createNamespacedJob({
return body namespace: namespace(),
body: job
})
} }
export async function getContainerJobPodName(jobName: string): Promise<string> { export async function getContainerJobPodName(jobName: string): Promise<string> {
const selector = `job-name=${jobName}` const selector = `job-name=${jobName}`
const backOffManager = new BackOffManager(60) const backOffManager = new BackOffManager(60)
while (true) { while (true) {
const podList = await k8sApi.listNamespacedPod( const podList = await k8sApi.listNamespacedPod({
namespace(), namespace: namespace(),
undefined, labelSelector: selector,
undefined, limit: 1
undefined, })
undefined,
selector,
1
)
if (!podList.body.items?.length) { if (!podList.items?.length) {
await backOffManager.backOff() await backOffManager.backOff()
continue continue
} }
if (!podList.body.items[0].metadata?.name) { if (!podList.items[0].metadata?.name) {
throw new Error( throw new Error(
`Failed to determine the name of the pod for job ${jobName}` `Failed to determine the name of the pod for job ${jobName}`
) )
} }
return podList.body.items[0].metadata.name return podList.items[0].metadata.name
} }
} }
export async function deletePod(podName: string): Promise<void> { export async function deletePod(podName: string): Promise<void> {
await k8sApi.deleteNamespacedPod( await k8sApi.deleteNamespacedPod({
podName, name: podName,
namespace(), namespace: namespace(),
undefined, gracePeriodSeconds: 0
undefined, })
0
)
} }
export async function execPodStep( export async function execPodStep(
@@ -274,7 +272,7 @@ export async function waitForJobToComplete(jobName: string): Promise<void> {
return return
} }
} catch (error) { } catch (error) {
throw new Error(`job ${jobName} has failed`) throw new Error(`job ${jobName} has failed: ${JSON.stringify(error)}`)
} }
await backOffManager.backOff() await backOffManager.backOff()
} }
@@ -315,8 +313,10 @@ export async function createDockerSecret(
) )
} }
const { body } = await k8sApi.createNamespacedSecret(namespace(), secret) return await k8sApi.createNamespacedSecret({
return body namespace: namespace(),
body: secret
})
} }
export async function createSecretForEnvs(envs: { export async function createSecretForEnvs(envs: {
@@ -340,30 +340,30 @@ export async function createSecretForEnvs(envs: {
secret.data[key] = Buffer.from(value).toString('base64') secret.data[key] = Buffer.from(value).toString('base64')
} }
await k8sApi.createNamespacedSecret(namespace(), secret) await k8sApi.createNamespacedSecret({ namespace: namespace(), body: secret })
return secretName return secretName
} }
export async function deleteSecret(secretName: string): Promise<void> { export async function deleteSecret(secretName: string): Promise<void> {
await k8sApi.deleteNamespacedSecret(secretName, namespace()) await k8sApi.deleteNamespacedSecret({
name: secretName,
namespace: namespace()
})
} }
export async function pruneSecrets(): Promise<void> { export async function pruneSecrets(): Promise<void> {
const secretList = await k8sApi.listNamespacedSecret( const secretList = await k8sApi.listNamespacedSecret({
namespace(), namespace: namespace(),
undefined, labelSelector: new RunnerInstanceLabel().toString()
undefined, })
undefined, if (!secretList.items.length) {
undefined,
new RunnerInstanceLabel().toString()
)
if (!secretList.body.items.length) {
return return
} }
await Promise.all( await Promise.all(
secretList.body.items.map( secretList.items.map(
secret => secret.metadata?.name && deleteSecret(secret.metadata.name) async secret =>
secret.metadata?.name && deleteSecret(secret.metadata.name)
) )
) )
} }
@@ -391,7 +391,9 @@ export async function waitForPodPhases(
await backOffManager.backOff() await backOffManager.backOff()
} }
} catch (error) { } catch (error) {
throw new Error(`Pod ${podName} is unhealthy with phase status ${phase}`) throw new Error(
`Pod ${podName} is unhealthy with phase status ${phase}: ${JSON.stringify(error)}`
)
} }
} }
@@ -422,8 +424,10 @@ async function getPodPhase(podName: string): Promise<PodPhase> {
PodPhase.FAILED, PodPhase.FAILED,
PodPhase.UNKNOWN PodPhase.UNKNOWN
]) ])
const { body } = await k8sApi.readNamespacedPod(podName, namespace()) const pod = await k8sApi.readNamespacedPod({
const pod = body name: podName,
namespace: namespace()
})
if (!pod.status?.phase || !podPhaseLookup.has(pod.status.phase)) { if (!pod.status?.phase || !podPhaseLookup.has(pod.status.phase)) {
return PodPhase.UNKNOWN return PodPhase.UNKNOWN
@@ -432,8 +436,10 @@ async function getPodPhase(podName: string): Promise<PodPhase> {
} }
async function isJobSucceeded(jobName: string): Promise<boolean> { async function isJobSucceeded(jobName: string): Promise<boolean> {
const { body } = await k8sBatchV1Api.readNamespacedJob(jobName, namespace()) const job = await k8sBatchV1Api.readNamespacedJob({
const job = body name: jobName,
namespace: namespace()
})
if (job.status?.failed) { if (job.status?.failed) {
throw new Error(`job ${jobName} has failed`) throw new Error(`job ${jobName} has failed`)
} }
@@ -455,30 +461,26 @@ export async function getPodLogs(
process.stderr.write(err.message) process.stderr.write(err.message)
}) })
const r = await log.log(namespace(), podName, containerName, logStream, { await log.log(namespace(), podName, containerName, logStream, {
follow: true, follow: true,
pretty: false, pretty: false,
timestamps: false timestamps: false
}) })
await new Promise(resolve => r.on('close', () => resolve(null))) await new Promise(resolve => logStream.on('close', () => resolve(null)))
} }
export async function prunePods(): Promise<void> { export async function prunePods(): Promise<void> {
const podList = await k8sApi.listNamespacedPod( const podList = await k8sApi.listNamespacedPod({
namespace(), namespace: namespace(),
undefined, labelSelector: new RunnerInstanceLabel().toString()
undefined, })
undefined, if (!podList.items.length) {
undefined,
new RunnerInstanceLabel().toString()
)
if (!podList.body.items.length) {
return return
} }
await Promise.all( await Promise.all(
podList.body.items.map( podList.items.map(
pod => pod.metadata?.name && deletePod(pod.metadata.name) async pod => pod.metadata?.name && deletePod(pod.metadata.name)
) )
) )
} }
@@ -486,16 +488,13 @@ export async function prunePods(): Promise<void> {
export async function getPodStatus( export async function getPodStatus(
name: string name: string
): Promise<k8s.V1PodStatus | undefined> { ): Promise<k8s.V1PodStatus | undefined> {
const { body } = await k8sApi.readNamespacedPod(name, namespace()) const pod = await k8sApi.readNamespacedPod({ name, namespace: namespace() })
return body.status return pod.status
} }
export async function isAuthPermissionsOK(): Promise<boolean> { export async function isAuthPermissionsOK(): Promise<boolean> {
const sar = new k8s.V1SelfSubjectAccessReview() const sar = new k8s.V1SelfSubjectAccessReview()
const asyncs: Promise<{ const asyncs: Promise<k8s.V1SelfSubjectAccessReview>[] = []
response: unknown
body: k8s.V1SelfSubjectAccessReview
}>[] = []
for (const resource of requiredPermissions) { for (const resource of requiredPermissions) {
for (const verb of resource.verbs) { for (const verb of resource.verbs) {
sar.spec = new k8s.V1SelfSubjectAccessReviewSpec() sar.spec = new k8s.V1SelfSubjectAccessReviewSpec()
@@ -505,11 +504,13 @@ export async function isAuthPermissionsOK(): Promise<boolean> {
sar.spec.resourceAttributes.group = resource.group sar.spec.resourceAttributes.group = resource.group
sar.spec.resourceAttributes.resource = resource.resource sar.spec.resourceAttributes.resource = resource.resource
sar.spec.resourceAttributes.subresource = resource.subresource sar.spec.resourceAttributes.subresource = resource.subresource
asyncs.push(k8sAuthorizationV1Api.createSelfSubjectAccessReview(sar)) asyncs.push(
k8sAuthorizationV1Api.createSelfSubjectAccessReview({ body: sar })
)
} }
} }
const responses = await Promise.all(asyncs) const responses = await Promise.all(asyncs)
return responses.every(resp => resp.body.status?.allowed) return responses.every(resp => resp.status?.allowed)
} }
export async function isPodContainerAlpine( export async function isPodContainerAlpine(
@@ -527,7 +528,7 @@ export async function isPodContainerAlpine(
podName, podName,
containerName containerName
) )
} catch (err) { } catch {
isAlpine = false isAlpine = false
} }
@@ -535,9 +536,12 @@ export async function isPodContainerAlpine(
} }
async function getCurrentNodeName(): Promise<string> { async function getCurrentNodeName(): Promise<string> {
const resp = await k8sApi.readNamespacedPod(getRunnerPodName(), namespace()) const resp = await k8sApi.readNamespacedPod({
name: getRunnerPodName(),
namespace: namespace()
})
const nodeName = resp.body.spec?.nodeName const nodeName = resp.spec?.nodeName
if (!nodeName) { if (!nodeName) {
throw new Error('Failed to determine node name') throw new Error('Failed to determine node name')
} }
@@ -647,6 +651,5 @@ export function containerPorts(
} }
export async function getPodByName(name): Promise<k8s.V1Pod> { export async function getPodByName(name): Promise<k8s.V1Pod> {
const { body } = await k8sApi.readNamespacedPod(name, namespace()) return await k8sApi.readNamespacedPod({ name, namespace: namespace() })
return body
} }
+10 -18
View File
@@ -32,16 +32,12 @@ describe('Cleanup Job', () => {
kc.loadFromDefault() kc.loadFromDefault()
const k8sApi = kc.makeApiClient(k8s.CoreV1Api) const k8sApi = kc.makeApiClient(k8s.CoreV1Api)
const podList = await k8sApi.listNamespacedPod( const podList = await k8sApi.listNamespacedPod({
namespace(), namespace: namespace(),
undefined, labelSelector: new RunnerInstanceLabel().toString()
undefined, })
undefined,
undefined,
new RunnerInstanceLabel().toString()
)
expect(podList.body.items.length).toBe(0) expect(podList.items.length).toBe(0)
}) })
it('should have no runner linked secrets', async () => { it('should have no runner linked secrets', async () => {
@@ -51,15 +47,11 @@ describe('Cleanup Job', () => {
kc.loadFromDefault() kc.loadFromDefault()
const k8sApi = kc.makeApiClient(k8s.CoreV1Api) const k8sApi = kc.makeApiClient(k8s.CoreV1Api)
const secretList = await k8sApi.listNamespacedSecret( const secretList = await k8sApi.listNamespacedSecret({
namespace(), namespace: namespace(),
undefined, labelSelector: new RunnerInstanceLabel().toString()
undefined, })
undefined,
undefined,
new RunnerInstanceLabel().toString()
)
expect(secretList.body.items.length).toBe(0) expect(secretList.items.length).toBe(0)
}) })
}) })
+3 -3
View File
@@ -394,7 +394,7 @@ metadata:
spec: spec:
containers: containers:
- name: test - name: test
image: node:22 image: node:14.16
- name: job - name: job
image: ubuntu:latest` image: ubuntu:latest`
) )
@@ -407,7 +407,7 @@ spec:
it('should merge container spec', () => { it('should merge container spec', () => {
const base = { const base = {
image: 'node:22', image: 'node:14.16',
name: 'test', name: 'test',
env: [ env: [
{ {
@@ -462,7 +462,7 @@ spec:
const base = { const base = {
containers: [ containers: [
{ {
image: 'node:22', image: 'node:14.16',
name: 'test', name: 'test',
env: [ env: [
{ {
+2 -54
View File
@@ -62,54 +62,6 @@ describe('Prepare job', () => {
).resolves.not.toThrow() ).resolves.not.toThrow()
}) })
it('should prepare job with envs CI and GITHUB_ACTIONS', async () => {
await prepareJob(prepareJobData.args, prepareJobOutputFilePath)
const content = JSON.parse(
fs.readFileSync(prepareJobOutputFilePath).toString()
)
const got = await getPodByName(content.state.jobPod)
expect(got.spec?.containers[0].env).toEqual(
expect.arrayContaining([
{ name: 'CI', value: 'true' },
{ name: 'GITHUB_ACTIONS', value: 'true' }
])
)
expect(got.spec?.containers[1].env).toEqual(
expect.arrayContaining([
{ name: 'CI', value: 'true' },
{ name: 'GITHUB_ACTIONS', value: 'true' }
])
)
})
it('should not override CI env var if already set', async () => {
prepareJobData.args.container.environmentVariables = {
CI: 'false'
}
await prepareJob(prepareJobData.args, prepareJobOutputFilePath)
const content = JSON.parse(
fs.readFileSync(prepareJobOutputFilePath).toString()
)
const got = await getPodByName(content.state.jobPod)
expect(got.spec?.containers[0].env).toEqual(
expect.arrayContaining([
{ name: 'CI', value: 'false' },
{ name: 'GITHUB_ACTIONS', value: 'true' }
])
)
expect(got.spec?.containers[1].env).toEqual(
expect.arrayContaining([
{ name: 'CI', value: 'true' },
{ name: 'GITHUB_ACTIONS', value: 'true' }
])
)
})
it('should throw an exception if the user volume mount is absolute path outside of GITHUB_WORKSPACE', async () => { it('should throw an exception if the user volume mount is absolute path outside of GITHUB_WORKSPACE', async () => {
prepareJobData.args.container.userMountVolumes = [ prepareJobData.args.container.userMountVolumes = [
{ {
@@ -173,7 +125,7 @@ describe('Prepare job', () => {
// job container // job container
expect(got.spec?.containers[0].name).toBe(JOB_CONTAINER_NAME) expect(got.spec?.containers[0].name).toBe(JOB_CONTAINER_NAME)
expect(got.spec?.containers[0].image).toBe('node:22') expect(got.spec?.containers[0].image).toBe('node:14.16')
expect(got.spec?.containers[0].command).toEqual(['sh']) expect(got.spec?.containers[0].command).toEqual(['sh'])
expect(got.spec?.containers[0].args).toEqual(['-c', 'sleep 50']) expect(got.spec?.containers[0].args).toEqual(['-c', 'sleep 50'])
@@ -181,13 +133,9 @@ describe('Prepare job', () => {
expect(got.spec?.containers[1].image).toBe('redis') expect(got.spec?.containers[1].image).toBe('redis')
expect(got.spec?.containers[1].command).toBeFalsy() expect(got.spec?.containers[1].command).toBeFalsy()
expect(got.spec?.containers[1].args).toBeFalsy() expect(got.spec?.containers[1].args).toBeFalsy()
expect(got.spec?.containers[1].env).toEqual( expect(got.spec?.containers[1].env).toEqual([
expect.arrayContaining([
{ name: 'CI', value: 'true' },
{ name: 'GITHUB_ACTIONS', value: 'true' },
{ name: 'ENV2', value: 'value2' } { name: 'ENV2', value: 'value2' }
]) ])
)
expect(got.spec?.containers[1].resources).toEqual({ expect(got.spec?.containers[1].resources).toEqual({
requests: { memory: '1Mi', cpu: '1' }, requests: { memory: '1Mi', cpu: '1' },
limits: { memory: '1Gi', cpu: '2' } limits: { memory: '1Gi', cpu: '2' }
@@ -78,15 +78,4 @@ describe('Run container step', () => {
runContainerStep(runContainerStepData.args) runContainerStep(runContainerStepData.args)
).resolves.not.toThrow() ).resolves.not.toThrow()
}) })
it('should run container step with envs CI and GITHUB_ACTIONS', async () => {
runContainerStepData.args.entryPoint = 'bash'
runContainerStepData.args.entryPointArgs = [
'-c',
"'if [[ -z $GITHUB_ACTIONS ]] || [[ -z $CI ]]; then exit 1; fi'"
]
await expect(
runContainerStep(runContainerStepData.args)
).resolves.not.toThrow()
})
}) })
+3 -17
View File
@@ -1,24 +1,10 @@
## Features <!-- ## Features -->
- k8s: Use pod affinity when KubeScheduler is enabled [#212] <!-- ## Bugs -->
- docker: support alternative network modes [#209]
## Bugs
- Expose CI=true and GITHUB_ACTIONS env variables [#215]
- k8s: add /github/home to containerAction mounts and surface createSecretForEnvs errors [#198]
- k8s: start logging from the beginning [#184]
## Misc ## Misc
- Bump node in tests to node 22 since node14 is quite old [#216] - Bump `@kubernetes/client-node` from 0.18.1 to 0.22.0 in /packages/k8s [#182]
- Bump jsonpath-plus from 10.1.0 to 10.3.0 in /packages/k8s [#213]
- Bump braces from 3.0.2 to 3.0.3 in /packages/hooklib [#194]
- Bump cross-spawn from 7.0.3 to 7.0.6 in /packages/k8s [#196]
- Bump ws from 7.5.8 to 7.5.10 in /packages/k8s [#192]
- Remove dependency on deprecated release actions [#193]
- Update to the latest available actions [#191]
## SHA-256 Checksums ## SHA-256 Checksums