Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use service name as a container name when possible #138

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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