volcano.sh/volcano@v1.9.0/test/e2e/schedulingbase/sla.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 schedulingbase
    18  
    19  import (
    20  	"context"
    21  
    22  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  	v1 "k8s.io/api/core/v1"
    25  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    26  
    27  	e2eutil "volcano.sh/volcano/test/e2e/util"
    28  )
    29  
    30  const (
    31  	jobWaitingTime = "sla-waiting-time"
    32  )
    33  
    34  var _ = Describe("SLA Test", func() {
    35  	It("sla permits job to be inqueue", func() {
    36  		ctx := e2eutil.InitTestContext(e2eutil.Options{})
    37  		defer e2eutil.CleanupTestContext(ctx)
    38  
    39  		slot := e2eutil.OneCPU
    40  		rep := e2eutil.ClusterSize(ctx, slot)
    41  
    42  		// job requests resources more than the whole cluster, but after sla-waiting-time, job can be inqueue
    43  		// and create Pending pods
    44  		job := &e2eutil.JobSpec{
    45  			Tasks: []e2eutil.TaskSpec{
    46  				{
    47  					Img: e2eutil.DefaultNginxImage,
    48  					Req: slot,
    49  					Min: rep * 2,
    50  					Rep: rep * 2,
    51  				},
    52  			},
    53  		}
    54  
    55  		annotations := map[string]string{jobWaitingTime: "3s"}
    56  
    57  		job.Name = "j1-overlarge"
    58  		overlargeJob := e2eutil.CreateJobWithPodGroup(ctx, job, "", annotations)
    59  		err := e2eutil.WaitTaskPhase(ctx, overlargeJob, []v1.PodPhase{v1.PodPending}, int(rep*2))
    60  		Expect(err).NotTo(HaveOccurred())
    61  	})
    62  
    63  	It("sla adjusts job order", func() {
    64  		ctx := e2eutil.InitTestContext(e2eutil.Options{})
    65  		defer e2eutil.CleanupTestContext(ctx)
    66  
    67  		slot := e2eutil.OneCPU
    68  		rep := e2eutil.ClusterSize(ctx, slot)
    69  
    70  		// job requests resources more than the whole cluster, but after sla-waiting-time, job can be inqueue
    71  		// and create Pending pods
    72  		job1 := &e2eutil.JobSpec{
    73  			Tasks: []e2eutil.TaskSpec{
    74  				{
    75  					Img: e2eutil.DefaultNginxImage,
    76  					Req: slot,
    77  					Min: rep * 2,
    78  					Rep: rep * 2,
    79  				},
    80  			},
    81  		}
    82  		job2 := &e2eutil.JobSpec{
    83  			Tasks: []e2eutil.TaskSpec{
    84  				{
    85  					Img: e2eutil.DefaultNginxImage,
    86  					Req: slot,
    87  					Min: rep,
    88  					Rep: rep,
    89  				},
    90  			},
    91  		}
    92  
    93  		job1.Name = "j1-overlarge"
    94  		overlargeJob := e2eutil.CreateJobWithPodGroup(ctx, job1, "", map[string]string{jobWaitingTime: "3s"})
    95  		err := e2eutil.WaitTaskPhase(ctx, overlargeJob, []v1.PodPhase{v1.PodPending}, int(rep*2))
    96  		Expect(err).NotTo(HaveOccurred())
    97  
    98  		job2.Name = "j2-slow-sla"
    99  		slowSLAJob := e2eutil.CreateJobWithPodGroup(ctx, job2, "", map[string]string{jobWaitingTime: "1h"})
   100  		err = e2eutil.WaitTaskPhase(ctx, slowSLAJob, []v1.PodPhase{v1.PodPending}, 0)
   101  		Expect(err).NotTo(HaveOccurred())
   102  
   103  		job2.Name = "j3-fast-sla"
   104  		fastSLAJob := e2eutil.CreateJobWithPodGroup(ctx, job2, "", map[string]string{jobWaitingTime: "30m"})
   105  		err = e2eutil.WaitTaskPhase(ctx, fastSLAJob, []v1.PodPhase{v1.PodPending}, 0)
   106  		Expect(err).NotTo(HaveOccurred())
   107  
   108  		err = ctx.Vcclient.BatchV1alpha1().Jobs(e2eutil.Namespace(ctx, job1)).Delete(context.TODO(), job1.Name, metav1.DeleteOptions{})
   109  		Expect(err).NotTo(HaveOccurred())
   110  
   111  		err = e2eutil.WaitTaskPhase(ctx, slowSLAJob, []v1.PodPhase{v1.PodPending}, 0)
   112  		Expect(err).NotTo(HaveOccurred())
   113  
   114  		err = e2eutil.WaitTasksReady(ctx, fastSLAJob, int(rep))
   115  		Expect(err).NotTo(HaveOccurred())
   116  	})
   117  })