Skip to content

Commit bad184b

Browse files
authored
Add a shared directory for service and job containers (#44)
* Add shared directory for service and job containers * Fix formatting
1 parent 431c2a1 commit bad184b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/k8s/src/k8s/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,32 @@ export async function createPod(
134134
})
135135
}
136136

137+
function addSharedVolumes(
138+
podSpec: k8s.V1PodSpec,
139+
jobContainer: k8s.V1Container,
140+
services: k8s.V1Container[]
141+
): void {
142+
podSpec.volumes = podSpec.volumes || []
143+
const sharedVolumeName = 'shared-data'
144+
// Add a shared directory so job container and service containers can share data.
145+
podSpec.volumes.push({
146+
name: sharedVolumeName,
147+
emptyDir: {}
148+
})
149+
jobContainer.volumeMounts = jobContainer.volumeMounts || []
150+
jobContainer.volumeMounts.push({
151+
name: sharedVolumeName,
152+
mountPath: '/shared'
153+
})
154+
for (const service of services) {
155+
service.volumeMounts = service.volumeMounts || []
156+
service.volumeMounts.push({
157+
name: sharedVolumeName,
158+
mountPath: '/shared'
159+
})
160+
}
161+
}
162+
137163
export async function createPodSpec(
138164
jobContainer?: k8s.V1Container,
139165
services?: k8s.V1Container[],
@@ -182,6 +208,10 @@ export async function createPodSpec(
182208
}
183209
)
184210

211+
if (jobContainer && services?.length) {
212+
addSharedVolumes(podSpec, jobContainer, services)
213+
}
214+
185215
if (registry) {
186216
const secret = await createDockerSecret(registry)
187217
if (!secret?.metadata?.name) {

0 commit comments

Comments
 (0)