volcano.sh/volcano@v1.9.0/test/e2e/jobseq/tensorflow_plugin.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 Plugin 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  					"tensorflow": {"--ps=ps", "--worker=worker", "--port=2222"},
    50  				},
    51  				Policies: []vcbatch.LifecyclePolicy{
    52  					{
    53  						Event:  vcbus.PodEvictedEvent,
    54  						Action: vcbus.RestartJobAction,
    55  					},
    56  				},
    57  				Tasks: []vcbatch.TaskSpec{
    58  					{
    59  						Replicas: int32(1),
    60  						Name:     "ps",
    61  						Template: v1.PodTemplateSpec{
    62  							Spec: v1.PodSpec{
    63  								RestartPolicy: v1.RestartPolicyNever,
    64  								Containers: []v1.Container{
    65  									{
    66  										Command: []string{
    67  											"sh",
    68  											"-c",
    69  											"python /var/tf_dist_mnist/dist_mnist.py --train_steps 1000",
    70  										},
    71  										Image: e2eutil.DefaultTFImage,
    72  										Name:  "tensorflow",
    73  										Ports: []v1.ContainerPort{
    74  											{
    75  												Name:          "tfjob-port",
    76  												ContainerPort: int32(2222),
    77  											},
    78  										},
    79  									},
    80  								},
    81  							},
    82  						},
    83  					},
    84  					{
    85  						Replicas: int32(2),
    86  						Name:     "worker",
    87  						Policies: []vcbatch.LifecyclePolicy{
    88  							{
    89  								Event:  vcbus.TaskCompletedEvent,
    90  								Action: vcbus.CompleteJobAction,
    91  							},
    92  						},
    93  						Template: v1.PodTemplateSpec{
    94  							Spec: v1.PodSpec{
    95  								RestartPolicy: v1.RestartPolicyNever,
    96  								Containers: []v1.Container{
    97  									{
    98  										Command: []string{
    99  											"sh",
   100  											"-c",
   101  											"python /var/tf_dist_mnist/dist_mnist.py --train_steps 1000",
   102  										},
   103  										Image: e2eutil.DefaultTFImage,
   104  										Name:  "tensorflow",
   105  										Ports: []v1.ContainerPort{
   106  											{
   107  												Name:          "tfjob-port",
   108  												ContainerPort: int32(2222),
   109  											},
   110  										},
   111  									},
   112  								},
   113  							},
   114  						},
   115  					},
   116  				},
   117  			},
   118  		}
   119  
   120  		created, err := ctx.Vcclient.BatchV1alpha1().Jobs(ctx.Namespace).Create(context.TODO(), job, metav1.CreateOptions{})
   121  		Expect(err).NotTo(HaveOccurred())
   122  
   123  		err = e2eutil.WaitJobStates(ctx, created, []vcbatch.JobPhase{vcbatch.Pending, vcbatch.Running, vcbatch.Completed}, e2eutil.FiveMinute)
   124  		Expect(err).NotTo(HaveOccurred())
   125  	})
   126  
   127  })