Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/k8s/src/hooks/prepare-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export async function prepareJob(
let services: k8s.V1Container[] = []
if (args.services?.length) {
services = args.services.map(service => {
core.debug(`Adding service '${service.image}' to pod definition`)
core.debug(`Adding service '${service.image}' to pod definition`)
return createContainerSpec(
service,
generateContainerName(service.image),
service,
generateContainerName(service),
false,
extension
)
Expand Down
12 changes: 8 additions & 4 deletions packages/k8s/src/k8s/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as k8s from '@kubernetes/client-node'
import * as fs from 'fs'
import * as yaml from 'js-yaml'
import * as core from '@actions/core'
import { Mount } from 'hooklib'
import { Mount, ServiceContainerInfo } from 'hooklib'
import * as path from 'path'
import { v1 as uuidv4 } from 'uuid'
import { POD_VOLUME_NAME } from './index'
Expand Down Expand Up @@ -155,12 +155,16 @@ exec ${environmentPrefix} ${entryPoint} ${
}
}

export function generateContainerName(image: string): string {
const nameWithTag = image.split('/').pop()
export function generateContainerName(service: ServiceContainerInfo): string {
if (service.contextName){
return service.contextName
}

const nameWithTag = service.image.split('/').pop()
const name = nameWithTag?.split(':').at(0)

if (!name) {
throw new Error(`Image definition '${image}' is invalid`)
throw new Error(`Image definition '${service.image}' is invalid`)
}

return name
Expand Down