volcano.sh/volcano@v1.9.0/test/e2e/schedulingaction/enqueue.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 schedulingaction
    18  
    19  import (
    20  	"strings"
    21  
    22  	"github.com/onsi/ginkgo/v2"
    23  	"github.com/onsi/gomega"
    24  
    25  	corev1 "k8s.io/api/core/v1"
    26  	"k8s.io/apimachinery/pkg/api/resource"
    27  
    28  	"gopkg.in/yaml.v2"
    29  	e2eutil "volcano.sh/volcano/test/e2e/util"
    30  )
    31  
    32  var _ = ginkgo.Describe("Enqueue E2E Test", func() {
    33  	ginkgo.It("allocate work even not config enqueue action", func() {
    34  		ginkgo.By("remove action enqueue from configmap")
    35  		cmc := e2eutil.NewConfigMapCase("volcano-system", "integration-scheduler-configmap")
    36  		cmc.ChangeBy(func(data map[string]string) (changed bool, changedBefore map[string]string) {
    37  			vcScheConfStr, ok := data["volcano-scheduler-ci.conf"]
    38  			gomega.Expect(ok).To(gomega.BeTrue())
    39  
    40  			schedulerConf := &e2eutil.SchedulerConfiguration{}
    41  			err := yaml.Unmarshal([]byte(vcScheConfStr), schedulerConf)
    42  			gomega.Expect(err).NotTo(gomega.HaveOccurred())
    43  			actstring := ""
    44  			if strings.Contains(schedulerConf.Actions, "enqueue") {
    45  				acts := strings.Split(schedulerConf.Actions, ",")
    46  				for i, act := range acts {
    47  					acts[i] = strings.TrimSpace(act)
    48  					if acts[i] != "enqueue" {
    49  						actstring += acts[i] + ","
    50  					}
    51  				}
    52  				actstring = strings.TrimRight(actstring, ",")
    53  				schedulerConf.Actions = actstring
    54  			}
    55  
    56  			newVCScheConfBytes, err := yaml.Marshal(schedulerConf)
    57  			gomega.Expect(err).NotTo(gomega.HaveOccurred())
    58  
    59  			changed = true
    60  			changedBefore = make(map[string]string)
    61  			changedBefore["volcano-scheduler-ci.conf"] = vcScheConfStr
    62  			data["volcano-scheduler-ci.conf"] = string(newVCScheConfBytes)
    63  			return
    64  		})
    65  		defer cmc.UndoChanged()
    66  
    67  		ctx := e2eutil.InitTestContext(e2eutil.Options{
    68  			NodesNumLimit: 2,
    69  			NodesResourceLimit: corev1.ResourceList{
    70  				corev1.ResourceCPU:    resource.MustParse("2000m"),
    71  				corev1.ResourceMemory: resource.MustParse("2048Mi")},
    72  		})
    73  		defer e2eutil.CleanupTestContext(ctx)
    74  
    75  		slot1 := corev1.ResourceList{
    76  			corev1.ResourceCPU:    resource.MustParse("500m"),
    77  			corev1.ResourceMemory: resource.MustParse("512Mi")}
    78  		slot2 := corev1.ResourceList{
    79  			corev1.ResourceCPU:    resource.MustParse("1000m"),
    80  			corev1.ResourceMemory: resource.MustParse("1024Mi")}
    81  
    82  		job := &e2eutil.JobSpec{
    83  			Tasks: []e2eutil.TaskSpec{
    84  				{
    85  					Img: e2eutil.DefaultNginxImage,
    86  					Req: slot1,
    87  					Min: 1,
    88  					Rep: 1,
    89  				},
    90  			},
    91  		}
    92  
    93  		job.Name = "low"
    94  		lowReqJob := e2eutil.CreateJob(ctx, job)
    95  		err := e2eutil.WaitJobReady(ctx, lowReqJob)
    96  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
    97  
    98  		job.Name = "high"
    99  		job.Tasks[0].Req = slot2
   100  		highReqJob := e2eutil.CreateJob(ctx, job)
   101  		err = e2eutil.WaitJobReady(ctx, highReqJob)
   102  		gomega.Expect(err).NotTo(gomega.HaveOccurred())
   103  	})
   104  })