Skip writing extension containers in output context file (#154)

This commit is contained in:
Nikola Jokic
2024-06-19 11:49:43 +02:00
committed by GitHub
parent ed70e2f8e0
commit ca4ea17d58
2 changed files with 41 additions and 17 deletions

View File

@@ -119,11 +119,12 @@ export async function prepareJob(
throw new Error(`failed to determine if the pod is alpine: ${message}`) throw new Error(`failed to determine if the pod is alpine: ${message}`)
} }
core.debug(`Setting isAlpine to ${isAlpine}`) core.debug(`Setting isAlpine to ${isAlpine}`)
generateResponseFile(responseFile, createdPod, isAlpine) generateResponseFile(responseFile, args, createdPod, isAlpine)
} }
function generateResponseFile( function generateResponseFile(
responseFile: string, responseFile: string,
args: PrepareJobArgs,
appPod: k8s.V1Pod, appPod: k8s.V1Pod,
isAlpine isAlpine
): void { ): void {
@@ -156,11 +157,13 @@ function generateResponseFile(
} }
} }
const serviceContainers = appPod.spec?.containers.filter( if (args.services?.length) {
c => c.name !== JOB_CONTAINER_NAME const serviceContainerNames =
) args.services?.map(s => generateContainerName(s.image)) || []
if (serviceContainers?.length) {
response.context['services'] = serviceContainers.map(c => { response.context['services'] = appPod?.spec?.containers
?.filter(c => serviceContainerNames.includes(c.name))
.map(c => {
const ctxPorts: ContextPorts = {} const ctxPorts: ContextPorts = {}
if (c.ports?.length) { if (c.ports?.length) {
for (const port of c.ports) { for (const port of c.ports) {
@@ -174,6 +177,7 @@ function generateResponseFile(
} }
}) })
} }
writeToResponseFile(responseFile, JSON.stringify(response)) writeToResponseFile(responseFile, JSON.stringify(response))
} }

View File

@@ -147,6 +147,26 @@ describe('Prepare job', () => {
expect(got.spec?.containers[2].args).toEqual(['-c', 'sleep 60']) expect(got.spec?.containers[2].args).toEqual(['-c', 'sleep 60'])
}) })
it('should put only job and services in output context file', async () => {
process.env[ENV_HOOK_TEMPLATE_PATH] = path.join(
__dirname,
'../../../examples/extension.yaml'
)
await expect(
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
).resolves.not.toThrow()
const content = JSON.parse(
fs.readFileSync(prepareJobOutputFilePath).toString()
)
expect(content.state.jobPod).toBeTruthy()
expect(content.context.container).toBeTruthy()
expect(content.context.services).toBeTruthy()
expect(content.context.services.length).toBe(1)
})
it('should not throw exception using kube scheduler', async () => { it('should not throw exception using kube scheduler', async () => {
// only for ReadWriteMany volumes or single node cluster // only for ReadWriteMany volumes or single node cluster
process.env[ENV_USE_KUBE_SCHEDULER] = 'true' process.env[ENV_USE_KUBE_SCHEDULER] = 'true'