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

Added VC_TASK_INDEX and added env to initContainers. #613

Merged
merged 1 commit into from
Dec 16, 2019
Merged
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
3 changes: 3 additions & 0 deletions pkg/controllers/job/plugins/env/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ const (

// TaskVkIndex used as key in container env
TaskVkIndex = "VK_TASK_INDEX"

// TaskIndex is used as key in container env
TaskIndex = "VC_TASK_INDEX"
)
19 changes: 12 additions & 7 deletions pkg/controllers/job/plugins/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ func (ep *envPlugin) Name() string {
}

func (ep *envPlugin) OnPodCreate(pod *v1.Pod, job *batch.Job) error {
// add VK_TASK_INDEX env to each container
for i, c := range pod.Spec.Containers {
vcIndex := v1.EnvVar{
Name: TaskVkIndex,
Value: jobhelpers.GetTaskIndex(pod),
}
pod.Spec.Containers[i].Env = append(c.Env, vcIndex)
index := jobhelpers.GetTaskIndex(pod)

// add VK_TASK_INDEX and VC_TASK_INDEX env to each container
for i := range pod.Spec.Containers {
pod.Spec.Containers[i].Env = append(pod.Spec.Containers[i].Env, v1.EnvVar{Name: TaskVkIndex, Value: index})
pod.Spec.Containers[i].Env = append(pod.Spec.Containers[i].Env, v1.EnvVar{Name: TaskIndex, Value: index})
}

// add VK_TASK_INDEX and VC_TASK_INDEX env to each init container
for i := range pod.Spec.InitContainers {
pod.Spec.InitContainers[i].Env = append(pod.Spec.InitContainers[i].Env, v1.EnvVar{Name: TaskVkIndex, Value: index})
pod.Spec.InitContainers[i].Env = append(pod.Spec.InitContainers[i].Env, v1.EnvVar{Name: TaskIndex, Value: index})
}

return nil
Expand Down