mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-17 10:16:44 +00:00
Compare commits
1 Commits
v0.5.0
...
nikola-jok
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f9272a5ce |
@@ -175,10 +175,15 @@ function createPodSpec(
|
|||||||
args: container.entryPointArgs,
|
args: container.entryPointArgs,
|
||||||
ports: containerPorts(container)
|
ports: containerPorts(container)
|
||||||
} as k8s.V1Container
|
} as k8s.V1Container
|
||||||
|
|
||||||
if (container.workingDirectory) {
|
if (container.workingDirectory) {
|
||||||
podContainer.workingDir = container.workingDirectory
|
podContainer.workingDir = container.workingDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (container.createOptions) {
|
||||||
|
podContainer.resources = getResourceRequirements(container.createOptions)
|
||||||
|
}
|
||||||
|
|
||||||
podContainer.env = []
|
podContainer.env = []
|
||||||
for (const [key, value] of Object.entries(
|
for (const [key, value] of Object.entries(
|
||||||
container['environmentVariables']
|
container['environmentVariables']
|
||||||
@@ -195,3 +200,62 @@ function createPodSpec(
|
|||||||
|
|
||||||
return podContainer
|
return podContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getResourceRequirements(
|
||||||
|
createOptions: string
|
||||||
|
): k8s.V1ResourceRequirements {
|
||||||
|
const rr = new k8s.V1ResourceRequirements()
|
||||||
|
rr.limits = {}
|
||||||
|
rr.requests = {}
|
||||||
|
|
||||||
|
const options = parseOptions(createOptions)
|
||||||
|
for (const [key, value] of Object.entries(options)) {
|
||||||
|
switch (key) {
|
||||||
|
case '--cpus':
|
||||||
|
rr.requests.cpu = value
|
||||||
|
break
|
||||||
|
case '--memory':
|
||||||
|
case '-m':
|
||||||
|
rr.limits.memory = value
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
core.warning(
|
||||||
|
`Container option ${key} is not supported. Supported options are ['--cpus', '--memory', '-m']`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rr
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseOptions(options: string): { [option: string]: string } {
|
||||||
|
const rv: { [option: string]: string } = {}
|
||||||
|
|
||||||
|
const spaceSplit = options.split(' ')
|
||||||
|
for (let i = 0; i < spaceSplit.length; i++) {
|
||||||
|
if (!spaceSplit[i].startsWith('-')) {
|
||||||
|
throw new Error(`Options specified in wrong format: ${options}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const optSplit = spaceSplit[i].split('=')
|
||||||
|
const optName = optSplit[0]
|
||||||
|
let optValue = ''
|
||||||
|
switch (optSplit.length) {
|
||||||
|
case 1:
|
||||||
|
if (spaceSplit.length <= i + 1) {
|
||||||
|
throw new Error(`Option ${optName} must have a value`)
|
||||||
|
}
|
||||||
|
optValue = spaceSplit[++i]
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
optValue = optSplit[1]
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
throw new Error(`failed to parse option ${spaceSplit[i]}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
rv[optName] = optValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user