Skip to content

Commit ce0c86e

Browse files
author
John Dreyer
committed
feat: label step pods
1 parent 6531ddf commit ce0c86e

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

packages/k8s/src/k8s/index.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ function sanitizeLabel(label: string): string {
9090
return sluggedLabel
9191
}
9292

93+
function getArcContextLabels(): { [key: string]: string } {
94+
const { GITHUB_RUN_ID, GITHUB_RUN_NUMBER, GITHUB_RUN_ATTEMPT } = process.env
95+
return Object.fromEntries(
96+
Object.entries({
97+
'arc-context-event-name': jobContext.eventName,
98+
'arc-context-sha': jobContext.sha,
99+
'arc-context-workflow': jobContext.workflow,
100+
'arc-context-actor': jobContext.actor,
101+
'arc-context-job': jobContext.job,
102+
'arc-context-repository': jobContext.repo.repo,
103+
'arc-context-repository-owner': jobContext.repo.owner,
104+
'arc-context-run-id': GITHUB_RUN_ID || '',
105+
'arc-context-run-number': GITHUB_RUN_NUMBER || '',
106+
'arc-context-run-attempt': GITHUB_RUN_ATTEMPT || ''
107+
})
108+
.map(([key, value]) => [key, sanitizeLabel(value)])
109+
.filter(([, value]) => value !== '')
110+
)
111+
}
112+
93113
export async function createPod(
94114
jobContainer?: k8s.V1Container,
95115
services?: k8s.V1Container[],
@@ -112,22 +132,7 @@ export async function createPod(
112132
appPod.metadata = new k8s.V1ObjectMeta()
113133
appPod.metadata.name = getJobPodName()
114134

115-
const { GITHUB_RUN_ID, GITHUB_RUN_NUMBER, GITHUB_RUN_ATTEMPT } = process.env
116-
const arcLabels = Object.fromEntries(
117-
Object.entries({
118-
'arc-context-event-name': jobContext.eventName,
119-
'arc-context-sha': jobContext.sha,
120-
'arc-context-workflow': jobContext.workflow,
121-
'arc-context-actor': jobContext.actor,
122-
'arc-context-job': jobContext.job,
123-
'arc-context-repository': jobContext.repo.repo,
124-
'arc-context-repository-owner': jobContext.repo.owner,
125-
'arc-context-run-id': GITHUB_RUN_ID || '',
126-
'arc-context-run-number': GITHUB_RUN_NUMBER || '',
127-
'arc-context-run-attempt': GITHUB_RUN_ATTEMPT || ''
128-
}).map(([key, value]) => [key, sanitizeLabel(value)])
129-
)
130-
135+
const arcLabels = getArcContextLabels()
131136
const instanceLabel = new RunnerInstanceLabel()
132137
appPod.metadata.labels = {
133138
[instanceLabel.key]: instanceLabel.value,
@@ -197,9 +202,10 @@ export async function createJob(
197202
job.spec.backoffLimit = 0
198203
job.spec.template = new k8s.V1PodTemplateSpec()
199204

205+
const arcLabels = getArcContextLabels()
200206
job.spec.template.spec = new k8s.V1PodSpec()
201207
job.spec.template.metadata = new k8s.V1ObjectMeta()
202-
job.spec.template.metadata.labels = {}
208+
job.spec.template.metadata.labels = arcLabels
203209
job.spec.template.metadata.annotations = {}
204210
job.spec.template.spec.containers = [container]
205211
job.spec.template.spec.restartPolicy = 'Never'

0 commit comments

Comments
 (0)