MCPcopy Create free account
hub / github.com/cortexlabs/cortex / BatchContainers

Function BatchContainers

pkg/workloads/k8s.go:281–316  ·  view source on GitHub ↗
(api spec.API, job *spec.BatchJob)

Source from the content-addressed store, hash-verified

279}
280
281func BatchContainers(api spec.API, job *spec.BatchJob) ([]kcore.Container, []kcore.Volume) {
282 userContainers, userVolumes := userPodContainers(api)
283 dequeuerContainer, dequeuerVolume := batchDequeuerProxyContainer(api, job.ID, job.SQSUrl)
284
285 // make sure the dequeuer starts first to allow it to start watching the graveyard before user containers begin
286 containers := append([]kcore.Container{dequeuerContainer}, userContainers...)
287 volumes := append([]kcore.Volume{dequeuerVolume}, userVolumes...)
288
289 k8sName := job.K8sName()
290
291 volumes = append(volumes,
292 KubexitVolume(),
293 APIConfigVolume(k8sName),
294 )
295
296 containerNames := userconfig.GetContainerNames(api.Pod.Containers)
297 containerNames.Add(dequeuerContainer.Name)
298
299 for i, c := range containers {
300 containers[i].VolumeMounts = append(containers[i].VolumeMounts,
301 KubexitMount(),
302 APIConfigMount(k8sName),
303 )
304
305 containerDeathDependencies := containerNames.Copy()
306 containerDeathDependencies.Remove(c.Name)
307 containerDeathEnvVars := getKubexitEnvVars(c.Name, containerDeathDependencies.SliceSorted(), nil)
308 containers[i].Env = append(containers[i].Env, containerDeathEnvVars...)
309
310 if c.Command[0] != "/cortex/kubexit" {
311 containers[i].Command = append([]string{"/cortex/kubexit"}, c.Command...)
312 }
313 }
314
315 return containers, volumes
316}
317
318func userPodContainers(api spec.API) ([]kcore.Container, []kcore.Volume) {
319 volumes := []kcore.Volume{

Callers 1

desiredWorkerJobMethod · 0.92

Calls 13

GetContainerNamesFunction · 0.92
userPodContainersFunction · 0.85
KubexitVolumeFunction · 0.85
APIConfigVolumeFunction · 0.85
KubexitMountFunction · 0.85
APIConfigMountFunction · 0.85
getKubexitEnvVarsFunction · 0.85
K8sNameMethod · 0.80
AddMethod · 0.45
CopyMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected