From 1bc05ba1609273c584b7e31beab5f592e24ef4ec Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Wed, 25 Dec 2019 15:48:14 +0530 Subject: [PATCH 1/3] Add SchedulerName to PodTemplate Set scheduler in PodTemplate to execute Tasks with specific schedulers. --- pkg/apis/pipeline/pod/template.go | 3 +++ pkg/pod/pod.go | 1 + 2 files changed, 4 insertions(+) diff --git a/pkg/apis/pipeline/pod/template.go b/pkg/apis/pipeline/pod/template.go index 01ce09fb739..123c2edde5a 100644 --- a/pkg/apis/pipeline/pod/template.go +++ b/pkg/apis/pipeline/pod/template.go @@ -90,6 +90,9 @@ type Template struct { // default. // +optional PriorityClassName *string `json:"priorityClassName,omitempty" protobuf:"bytes,7,opt,name=priorityClassName"` + // SchedulerName specifies the scheduler to be used to dispatch the Pod + // +optional + SchedulerName string `json:"schedulerName"` } func (tpl *Template) Equals(other *Template) bool { diff --git a/pkg/pod/pod.go b/pkg/pod/pod.go index f17004b508f..b10420d8abf 100644 --- a/pkg/pod/pod.go +++ b/pkg/pod/pod.go @@ -238,6 +238,7 @@ func MakePod(images pipeline.Images, taskRun *v1alpha1.TaskRun, taskSpec v1alpha SecurityContext: podTemplate.SecurityContext, RuntimeClassName: podTemplate.RuntimeClassName, AutomountServiceAccountToken: podTemplate.AutomountServiceAccountToken, + SchedulerName: podTemplate.SchedulerName, DNSPolicy: dnsPolicy, DNSConfig: podTemplate.DNSConfig, EnableServiceLinks: podTemplate.EnableServiceLinks, From 95d9cb476b44ffd58912968cd07635f0b8079f0f Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Mon, 6 Jan 2020 10:18:55 +0530 Subject: [PATCH 2/3] Add test for schedulerName in TaskRunSpec This test checks if the schedulerName has passed down from the TaskRunSpec to the PodSpec --- pkg/pod/pod_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 942c4a2e700..02f27f113eb 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -673,6 +673,45 @@ script-heredoc-randomly-generated-78c5n }}, Volumes: append(implicitVolumes, scriptsVolume, toolsVolume, downwardVolume), }, + }, { + desc: "using another scheduler", + ts: v1alpha1.TaskSpec{ + Steps: []v1alpha1.Step{{Container: corev1.Container{ + Name: "schedule-me", + Image: "image", + Command: []string{"cmd"}, // avoid entrypoint lookup. + }}}, + }, + trs: v1alpha1.TaskRunSpec{ + PodTemplate: v1alpha1.PodTemplate{ + SchedulerName: "there-scheduler", + }, + }, + want: &corev1.PodSpec{ + RestartPolicy: corev1.RestartPolicyNever, + InitContainers: []corev1.Container{placeToolsInit}, + SchedulerName: "there-scheduler", + Volumes: append(implicitVolumes, toolsVolume, downwardVolume), + Containers: []corev1.Container{{ + Name: "step-schedule-me", + Image: "image", + Command: []string{"/tekton/tools/entrypoint"}, + Args: []string{ + "-wait_file", + "/tekton/downward/ready", + "-wait_file_content", + "-post_file", + "/tekton/tools/0", + "-entrypoint", + "cmd", + "--", + }, + Env: implicitEnvVars, + VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount}, implicitVolumeMounts...), + WorkingDir: pipeline.WorkspaceDir, + Resources: corev1.ResourceRequirements{Requests: allZeroQty()}, + }}, + }, }} { t.Run(c.desc, func(t *testing.T) { names.TestingSeed() From 1b75fd6fb227f9ee4ed56b15675c75c874140468 Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Thu, 13 Feb 2020 14:14:02 +0530 Subject: [PATCH 3/3] Update Docs for SchedulerName in PodTemplate --- docs/podtemplates.md | 4 ++++ docs/taskruns.md | 4 +++- pkg/pod/pod_test.go | 29 +++++++++++++++++++---------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/docs/podtemplates.md b/docs/podtemplates.md index 90dc2ef7a65..e7994ef3732 100644 --- a/docs/podtemplates.md +++ b/docs/podtemplates.md @@ -46,6 +46,10 @@ The current fields supported are: [priority class](https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/) to use when running the pod. Use this, for example, to selectively enable preemption on lower priority workloads. + - `schedulerName` the name of the [scheduler](https://kubernetes.io/docs/tasks/administer-cluster/configure-multiple-schedulers/) + to use when dispatching the Pod. This can be used when workloads of specific types need specific schedulers, + eg: If you are using volcano.sh for Machine Learning Workloads, you can pass the schedulerName and have Tasks be + dispatched by the volcano.sh scheduler. A pod template can be specified for `TaskRun` or `PipelineRun` resources. diff --git a/docs/taskruns.md b/docs/taskruns.md index 9fb49e8f46c..b343204727b 100644 --- a/docs/taskruns.md +++ b/docs/taskruns.md @@ -192,7 +192,8 @@ allows to customize some Pod specific field per `Task` execution, aka `TaskRun`. In the following example, the Task is defined with a `volumeMount` (`my-cache`), that is provided by the TaskRun, using a -PersistenceVolumeClaim. The Pod will also run as a non-root user. +PersistenceVolumeClaim. The SchedulerName has also been provided to define which scheduler should be used to +dispatch the Pod. The Pod will also run as a non-root user. ```yaml apiVersion: tekton.dev/v1alpha1 @@ -219,6 +220,7 @@ spec: taskRef: name: mytask podTemplate: + schedulerName: volcano securityContext: runAsNonRoot: true volumes: diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 02f27f113eb..ab068886187 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -676,14 +676,20 @@ script-heredoc-randomly-generated-78c5n }, { desc: "using another scheduler", ts: v1alpha1.TaskSpec{ - Steps: []v1alpha1.Step{{Container: corev1.Container{ - Name: "schedule-me", - Image: "image", - Command: []string{"cmd"}, // avoid entrypoint lookup. - }}}, + TaskSpec: v1alpha2.TaskSpec{ + Steps: []v1alpha1.Step{ + { + Container: corev1.Container{ + Name: "schedule-me", + Image: "image", + Command: []string{"cmd"}, // avoid entrypoint lookup. + }, + }, + }, + }, }, trs: v1alpha1.TaskRunSpec{ - PodTemplate: v1alpha1.PodTemplate{ + PodTemplate: &v1alpha1.PodTemplate{ SchedulerName: "there-scheduler", }, }, @@ -702,14 +708,17 @@ script-heredoc-randomly-generated-78c5n "-wait_file_content", "-post_file", "/tekton/tools/0", + "-termination_path", + "/tekton/termination", "-entrypoint", "cmd", "--", }, - Env: implicitEnvVars, - VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount}, implicitVolumeMounts...), - WorkingDir: pipeline.WorkspaceDir, - Resources: corev1.ResourceRequirements{Requests: allZeroQty()}, + Env: implicitEnvVars, + VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount}, implicitVolumeMounts...), + WorkingDir: pipeline.WorkspaceDir, + Resources: corev1.ResourceRequirements{Requests: allZeroQty()}, + TerminationMessagePath: "/tekton/termination", }}, }, }} {