volcano.sh/volcano@v1.9.0/test/e2e/jobp/pg_controller.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 jobp
    18  
    19  import (
    20  	"context"
    21  
    22  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  
    25  	corev1 "k8s.io/api/core/v1"
    26  	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    27  
    28  	e2eutil "volcano.sh/volcano/test/e2e/util"
    29  )
    30  
    31  var _ = Describe("PG E2E Test: Test PG controller", func() {
    32  	It("Create volcano rc, pg controller process", func() {
    33  		rcName := "rc-volcano"
    34  		podName := "pod-volcano"
    35  		label := map[string]string{"schedulerName": "volcano"}
    36  		ctx := e2eutil.InitTestContext(e2eutil.Options{})
    37  		defer e2eutil.CleanupTestContext(ctx)
    38  
    39  		rc := &corev1.ReplicationController{
    40  			TypeMeta: v1.TypeMeta{
    41  				APIVersion: "v1",
    42  				Kind:       "ReplicationController",
    43  			},
    44  			ObjectMeta: v1.ObjectMeta{
    45  				Name:      rcName,
    46  				Namespace: ctx.Namespace,
    47  			},
    48  			Spec: corev1.ReplicationControllerSpec{
    49  				Selector: label,
    50  				Template: &corev1.PodTemplateSpec{
    51  					ObjectMeta: v1.ObjectMeta{
    52  						Name:   podName,
    53  						Labels: label,
    54  					},
    55  					Spec: corev1.PodSpec{
    56  						SchedulerName: "volcano",
    57  						Containers: []corev1.Container{
    58  							{
    59  								Name:            podName,
    60  								Image:           e2eutil.DefaultNginxImage,
    61  								ImagePullPolicy: corev1.PullIfNotPresent,
    62  							},
    63  						},
    64  					},
    65  				},
    66  			},
    67  		}
    68  
    69  		pod := &corev1.Pod{
    70  			ObjectMeta: v1.ObjectMeta{
    71  				Namespace: ctx.Namespace,
    72  			},
    73  		}
    74  
    75  		_, err := ctx.Kubeclient.CoreV1().ReplicationControllers(ctx.Namespace).Create(context.TODO(), rc, v1.CreateOptions{})
    76  		Expect(err).NotTo(HaveOccurred())
    77  
    78  		err = e2eutil.WaitPodPhase(ctx, pod, []corev1.PodPhase{corev1.PodRunning})
    79  		Expect(err).NotTo(HaveOccurred())
    80  
    81  		ready, err := e2eutil.PodGroupIsReady(ctx, ctx.Namespace)
    82  		Expect(ready).Should(Equal(true))
    83  		Expect(err).NotTo(HaveOccurred())
    84  	})
    85  
    86  	It("Create default-scheduler rc, pg controller don't process", func() {
    87  		rcName := "rc-default-scheduler"
    88  		podName := "pod-default-scheduler"
    89  		label := map[string]string{"a": "b"}
    90  		ctx := e2eutil.InitTestContext(e2eutil.Options{})
    91  		defer e2eutil.CleanupTestContext(ctx)
    92  
    93  		rc := &corev1.ReplicationController{
    94  			TypeMeta: v1.TypeMeta{
    95  				APIVersion: "v1",
    96  				Kind:       "ReplicationController",
    97  			},
    98  			ObjectMeta: v1.ObjectMeta{
    99  				Name:      rcName,
   100  				Namespace: ctx.Namespace,
   101  			},
   102  			Spec: corev1.ReplicationControllerSpec{
   103  				Selector: label,
   104  				Template: &corev1.PodTemplateSpec{
   105  					ObjectMeta: v1.ObjectMeta{
   106  						Name:   podName,
   107  						Labels: label,
   108  					},
   109  					Spec: corev1.PodSpec{
   110  						Containers: []corev1.Container{
   111  							{
   112  								Name:            podName,
   113  								Image:           e2eutil.DefaultNginxImage,
   114  								ImagePullPolicy: corev1.PullIfNotPresent,
   115  							},
   116  						},
   117  					},
   118  				},
   119  			},
   120  		}
   121  
   122  		pod := &corev1.Pod{
   123  			ObjectMeta: v1.ObjectMeta{
   124  				Namespace: ctx.Namespace,
   125  			},
   126  		}
   127  
   128  		_, err := ctx.Kubeclient.CoreV1().ReplicationControllers(ctx.Namespace).Create(context.TODO(), rc, v1.CreateOptions{})
   129  		Expect(err).NotTo(HaveOccurred())
   130  
   131  		err = e2eutil.WaitPodPhase(ctx, pod, []corev1.PodPhase{corev1.PodRunning})
   132  		Expect(err).NotTo(HaveOccurred())
   133  
   134  		ready, err := e2eutil.PodGroupIsReady(ctx, ctx.Namespace)
   135  		Expect(ready).Should(Equal(false))
   136  		Expect(err.Error()).Should(Equal("pod group not found"))
   137  	})
   138  })