Skip to content

Commit

Permalink
Added VC_TASK_INDEX and added env to initContainers.
Browse files Browse the repository at this point in the history
Signed-off-by: Klaus Ma <klaus1982.cn@gmail.com>
  • Loading branch information
k82cn committed Dec 16, 2019
1 parent 33fa0fd commit c077af9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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"
)
18 changes: 12 additions & 6 deletions pkg/controllers/job/plugins/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ func (ep *envPlugin) Name() string {
}

func (ep *envPlugin) OnPodCreate(pod *v1.Pod, job *batch.Job) error {
// add VK_TASK_INDEX env to each container
index := jobhelpers.GetTaskIndex(pod)

// add VK_TASK_INDEX and VC_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)
pod.Spec.Containers[i].Env = append(c.Env, v1.EnvVar{Name: TaskVkIndex, Value: index})
pod.Spec.Containers[i].Env = append(c.Env, v1.EnvVar{Name: TaskIndex, Value: index})
}

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

}

return nil
Expand Down

0 comments on commit c077af9

Please sign in to comment.