Skip to content

Commit

Permalink
Merge pull request #613 from k82cn/vc_453
Browse files Browse the repository at this point in the history
Added VC_TASK_INDEX and added env to initContainers.
  • Loading branch information
volcano-sh-bot authored Dec 16, 2019
2 parents 33fa0fd + ef05963 commit 2f688bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 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"
)
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

0 comments on commit 2f688bd

Please sign in to comment.