Skip to content

Commit

Permalink
Merge pull request volcano-sh#51 from volcano-sh/feature/support-mpi
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaus Ma authored Mar 30, 2019
2 parents 453738c + 5ca96a7 commit 4be56b9
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 5 deletions.
17 changes: 17 additions & 0 deletions example/integrations/mpi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:16.04
MAINTAINER volcano <maintainer@volcano.sh>
RUN apt-get update --fix-missing \
&& apt-get install -y libopenmpi-dev openmpi-bin \
&& apt-get install -y git \
&& apt-get install -y build-essential \
&& apt-get install -y ssh \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN git clone https://github.com/wesleykendall/mpitutorial \
&& cd mpitutorial/tutorials/mpi-hello-world/code \
&& make \
&& cp mpi_hello_world /home/ \
&& apt-get autoremove -y git \
&& apt-get autoremove -y build-essential \
&& rm -rf "/mpitutorial"
CMD mkdir -p /var/run/sshd; /usr/sbin/sshd;
52 changes: 52 additions & 0 deletions example/integrations/mpi/mpi-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: batch.volcano.sh/v1alpha1
kind: Job
metadata:
name: lm-mpi-job
spec:
minAvailable: 2
schedulerName: kube-batch
plugins:
ssh: []
env: []
tasks:
- replicas: 1
name: mpimaster
policies:
- event: TaskCompleted
action: CompleteJob
template:
spec:
containers:
- command:
- /bin/sh
- -c
- |
MPI_HOST=`cat /etc/volcano/mpiworker.host | tr "\n" ","`;
mkdir -p /var/run/sshd; /usr/sbin/sshd;
mpiexec --allow-run-as-root --host ${MPI_HOST} -np 2 mpi_hello_world > /home/re;
#TODO: use volcano repo instead in the future.
image: tommylike/volcano-example-mpi:0.0.1
name: mpimaster
ports:
- containerPort: 22
name: mpijob-port
workingDir: /home
restartPolicy: OnFailure
- replicas: 2
name: mpiworker
template:
spec:
containers:
- command:
- /bin/sh
- -c
- |
mkdir -p /var/run/sshd; /usr/sbin/sshd -D;
image: tommylike/volcano-example-mpi:0.0.1
name: mpiworker
ports:
- containerPort: 22
name: mpijob-port
workingDir: /home
restartPolicy: OnFailure
---
6 changes: 6 additions & 0 deletions hack/run-e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export VK_BIN=${VK_ROOT}/_output/bin
export LOG_LEVEL=3
export SHOW_VOLCANO_LOGS=${SHOW_VOLCANO_LOGS:-1}
export CLEANUP_CLUSTER=${CLEANUP_CLUSTER:-1}
#TODO: Use volcano repo instead in the future
export MPI_EXAMPLE_IMAGE=${MPI_EXAMPLE_IMAGE:-"tommylike/volcano-example-mpi:0.0.1"}

if [[ "${CLUSTER_NAME}xxx" != "xxx" ]];then
export CLUSTER_CONTEXT="--name ${CLUSTER_NAME}"
Expand Down Expand Up @@ -52,10 +54,14 @@ function install-volcano {
chmod 700 get_helm.sh && ./get_helm.sh --version v2.13.0
helm init --service-account tiller --kubeconfig ${KUBECONFIG} --wait

echo "Pulling required docker images"
docker pull ${MPI_EXAMPLE_IMAGE}

echo "Loading docker images into kind cluster"
kind load docker-image ${IMAGE}-controllers:${TAG} ${CLUSTER_CONTEXT}
kind load docker-image ${IMAGE}-scheduler:${TAG} ${CLUSTER_CONTEXT}
kind load docker-image ${IMAGE}-admission:${TAG} ${CLUSTER_CONTEXT}
kind load docker-image ${MPI_EXAMPLE_IMAGE} ${CLUSTER_CONTEXT}

echo "Install volcano plugin into cluster...."
helm plugin install --kubeconfig ${KUBECONFIG} installer/chart/volcano/plugins/gen-admission-secret
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/batch/v1alpha1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ type JobStatus struct {
//Current version of job
Version int32 `json:"version,omitempty" protobuf:"bytes,8,opt,name=version"`
// The resources that controlled by this job, e.g. Service, ConfigMap
ControlledResources map[string]string
ControlledResources map[string]string `json:"controlledResources,omitempty" protobuf:"bytes,8,opt,name=controlledResources"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
77 changes: 77 additions & 0 deletions test/e2e/mpi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright 2019 The Volcano Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

vkv1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

var _ = Describe("MPI E2E Test", func() {
It("will run and complete finally", func() {
context := initTestContext()
defer cleanupTestContext(context)

slot := oneCPU

spec := &jobSpec{
name: "mpi",
policies: []vkv1.LifecyclePolicy{
{
Action: vkv1.CompleteJobAction,
Event: vkv1.TaskCompletedEvent,
},
},
plugins: map[string][]string{
"ssh": {},
"env": {},
},
tasks: []taskSpec{
{
name: "mpimaster",
img: defaultMPIImage,
req: slot,
min: 1,
rep: 1,
workingDir: "/home",
//Need sometime waiting for worker node ready
command: `sleep 5;
MPI_HOST=` + "`" + `cat /etc/volcano/mpiworker.host | tr "\n" ","` + "`" + `;
mkdir -p /var/run/sshd; /usr/sbin/sshd;
mpiexec --allow-run-as-root --host ${MPI_HOST} -np 2 mpi_hello_world > /home/re`,
},
{
name: "mpiworker",
img: defaultMPIImage,
req: slot,
min: 2,
rep: 2,
workingDir: "/home",
command: "mkdir -p /var/run/sshd; /usr/sbin/sshd -D;",
},
},
}

job := createJob(context, spec)

err := waitJobStates(context, job, []vkv1.JobPhase{
vkv1.Pending, vkv1.Running, vkv1.Completing, vkv1.Completed})
Expect(err).NotTo(HaveOccurred())
})

})
17 changes: 13 additions & 4 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const (
masterPriority = "master-pri"
defaultNginxImage = "nginx:1.14"
defaultBusyBoxImage = "busybox:1.24"
//TODO: Use volcano repo instead in the future
defaultMPIImage = "tommylike/volcano-example-mpi:0.0.1"
)

func cpuResource(request string) v1.ResourceList {
Expand Down Expand Up @@ -279,6 +281,7 @@ type taskSpec struct {
min, rep int32
img string
command string
workingDir string
hostport int32
req v1.ResourceList
affinity *v1.Affinity
Expand Down Expand Up @@ -359,7 +362,7 @@ func createJobInner(context *context, jobSpec *jobSpec) (*vkv1.Job, error) {
Spec: v1.PodSpec{
SchedulerName: "kube-batch",
RestartPolicy: restartPolicy,
Containers: createContainers(task.img, task.command, task.req, task.hostport),
Containers: createContainers(task.img, task.command, task.workingDir, task.req, task.hostport),
Affinity: task.affinity,
},
},
Expand Down Expand Up @@ -553,7 +556,8 @@ func waitJobUnschedulable(ctx *context, job *vkv1.Job) error {
return wait.Poll(10*time.Second, oneMinute, jobUnschedulable(ctx, job, now))
}

func createContainers(img, command string, req v1.ResourceList, hostport int32) []v1.Container {
func createContainers(img, command, workingDir string, req v1.ResourceList, hostport int32) []v1.Container {
var imageRepo []string
container := v1.Container{
Image: img,
ImagePullPolicy: v1.PullIfNotPresent,
Expand All @@ -562,10 +566,11 @@ func createContainers(img, command string, req v1.ResourceList, hostport int32)
},
}
if strings.Index(img, ":") < 0 {
container.Name = img
imageRepo = strings.Split(img, "/")
} else {
container.Name = img[:strings.Index(img, ":")]
imageRepo = strings.Split(img[:strings.Index(img, ":")], "/")
}
container.Name = imageRepo[len(imageRepo)-1]

if len(command) > 0 {
container.Command = []string{"/bin/sh"}
Expand All @@ -581,6 +586,10 @@ func createContainers(img, command string, req v1.ResourceList, hostport int32)
}
}

if len(workingDir) > 0 {
container.WorkingDir = workingDir
}

return []v1.Container{container}
}

Expand Down

0 comments on commit 4be56b9

Please sign in to comment.