volcano.sh/volcano@v1.9.0/test/e2e/jobseq/tensorflow.go (about) 1 /* 2 Copyright 2021 The Volcano Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package jobseq 18 19 import ( 20 "context" 21 22 . "github.com/onsi/ginkgo/v2" 23 . "github.com/onsi/gomega" 24 25 v1 "k8s.io/api/core/v1" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 28 vcbatch "volcano.sh/apis/pkg/apis/batch/v1alpha1" 29 vcbus "volcano.sh/apis/pkg/apis/bus/v1alpha1" 30 31 e2eutil "volcano.sh/volcano/test/e2e/util" 32 ) 33 34 var _ = Describe("TensorFlow E2E Test", func() { 35 It("Will Start in pending state and goes through other phases to get complete phase", func() { 36 ctx := e2eutil.InitTestContext(e2eutil.Options{}) 37 defer e2eutil.CleanupTestContext(ctx) 38 39 jobName := "tensorflow-dist-mnist" 40 41 job := &vcbatch.Job{ 42 ObjectMeta: metav1.ObjectMeta{ 43 Name: jobName, 44 }, 45 Spec: vcbatch.JobSpec{ 46 MinAvailable: int32(3), 47 SchedulerName: e2eutil.SchedulerName, 48 Plugins: map[string][]string{ 49 "svc": {}, 50 "env": {}, 51 }, 52 Policies: []vcbatch.LifecyclePolicy{ 53 { 54 Event: vcbus.PodEvictedEvent, 55 Action: vcbus.RestartJobAction, 56 }, 57 }, 58 Tasks: []vcbatch.TaskSpec{ 59 { 60 Replicas: int32(1), 61 Name: "ps", 62 Template: v1.PodTemplateSpec{ 63 Spec: v1.PodSpec{ 64 RestartPolicy: v1.RestartPolicyNever, 65 Containers: []v1.Container{ 66 { 67 Command: []string{ 68 "sh", 69 "-c", 70 "PS_HOST=`cat /etc/volcano/ps.host | sed 's/$/&:2222/g' | sed 's/^/\"/;s/$/\"/' | tr \"\n\" \",\"`; WORKER_HOST=`cat /etc/volcano/worker.host | sed 's/$/&:2222/g' | sed 's/^/\"/;s/$/\"/' | tr \"\n\" \",\"`; export TF_CONFIG={\\\"cluster\\\":{\\\"ps\\\":[${PS_HOST}],\\\"worker\\\":[${WORKER_HOST}]},\\\"task\\\":{\\\"type\\\":\\\"ps\\\",\\\"index\\\":${VK_TASK_INDEX}},\\\"environment\\\":\\\"cloud\\\"}; echo ${TF_CONFIG}; python /var/tf_dist_mnist/dist_mnist.py --train_steps 1000", 71 }, 72 Image: e2eutil.DefaultTFImage, 73 Name: "tensorflow", 74 Ports: []v1.ContainerPort{ 75 { 76 Name: "tfjob-port", 77 ContainerPort: int32(2222), 78 }, 79 }, 80 }, 81 }, 82 }, 83 }, 84 }, 85 { 86 Replicas: int32(2), 87 Name: "worker", 88 Policies: []vcbatch.LifecyclePolicy{ 89 { 90 Event: vcbus.TaskCompletedEvent, 91 Action: vcbus.CompleteJobAction, 92 }, 93 }, 94 Template: v1.PodTemplateSpec{ 95 Spec: v1.PodSpec{ 96 RestartPolicy: v1.RestartPolicyNever, 97 Containers: []v1.Container{ 98 { 99 Command: []string{ 100 "sh", 101 "-c", 102 "PS_HOST=`cat /etc/volcano/ps.host | sed 's/$/&:2222/g' | sed 's/^/\"/;s/$/\"/' | tr \"\n\" \",\"`; WORKER_HOST=`cat /etc/volcano/worker.host | sed 's/$/&:2222/g' | sed 's/^/\"/;s/$/\"/' | tr \"\n\" \",\"`; export TF_CONFIG={\\\"cluster\\\":{\\\"ps\\\":[${PS_HOST}],\\\"worker\\\":[${WORKER_HOST}]},\\\"task\\\":{\\\"type\\\":\\\"worker\\\",\\\"index\\\":${VK_TASK_INDEX}},\\\"environment\\\":\\\"cloud\\\"}; echo ${TF_CONFIG}; python /var/tf_dist_mnist/dist_mnist.py --train_steps 1000", 103 }, 104 Image: e2eutil.DefaultTFImage, 105 Name: "tensorflow", 106 Ports: []v1.ContainerPort{ 107 { 108 Name: "tfjob-port", 109 ContainerPort: int32(2222), 110 }, 111 }, 112 }, 113 }, 114 }, 115 }, 116 }, 117 }, 118 }, 119 } 120 121 created, err := ctx.Vcclient.BatchV1alpha1().Jobs(ctx.Namespace).Create(context.TODO(), job, metav1.CreateOptions{}) 122 Expect(err).NotTo(HaveOccurred()) 123 124 err = e2eutil.WaitJobStates(ctx, created, []vcbatch.JobPhase{vcbatch.Pending, vcbatch.Running, vcbatch.Completed}, e2eutil.FiveMinute) 125 Expect(err).NotTo(HaveOccurred()) 126 }) 127 128 })