diff --git a/test/e2e/framework/helpers/k8s/pod_conf.go b/test/e2e/framework/helpers/k8s/pod_conf.go index 5da113eea..b8280c3b9 100644 --- a/test/e2e/framework/helpers/k8s/pod_conf.go +++ b/test/e2e/framework/helpers/k8s/pod_conf.go @@ -39,10 +39,18 @@ type SleepPodConfig struct { CPU int64 Mem int64 RequiredNode string - Optedout bool + Optedout AllowPreemptOpted Labels map[string]string } +type AllowPreemptOpted int + +const ( + NotConfig AllowPreemptOpted = iota + Allow + Deny +) + // TestPodConfig template for sleepPods func InitSleepPod(conf SleepPodConfig) (*v1.Pod, error) { // Initialize default values @@ -88,9 +96,16 @@ func InitSleepPod(conf SleepPodConfig) (*v1.Pod, error) { } } - optedOut := constants.True - if !conf.Optedout { - optedOut = constants.False + annotation := &PodAnnotation{ + Other: map[string]string{}, + } + + switch conf.Optedout { + case NotConfig: + case Allow: + annotation.Other[constants.AnnotationAllowPreemption] = constants.True + case Deny: + annotation.Other[constants.AnnotationAllowPreemption] = constants.False } labels := map[string]string{ @@ -109,12 +124,8 @@ func InitSleepPod(conf SleepPodConfig) (*v1.Pod, error) { RestartPolicy: v1.RestartPolicyNever, DeletionGracePeriodSeconds: &secs, Command: []string{"sleep", strconv.Itoa(conf.Time)}, - Annotations: &PodAnnotation{ - Other: map[string]string{ - constants.AnnotationAllowPreemption: optedOut, - }, - }, - Labels: labels, + Annotations: annotation, + Labels: labels, Resources: &v1.ResourceRequirements{ Requests: v1.ResourceList{ "cpu": resource.MustParse(strconv.FormatInt(conf.CPU, 10) + "m"), diff --git a/test/e2e/preemption/preemption_test.go b/test/e2e/preemption/preemption_test.go index a2e65c8c1..dc8585aa2 100644 --- a/test/e2e/preemption/preemption_test.go +++ b/test/e2e/preemption/preemption_test.go @@ -162,7 +162,7 @@ var _ = ginkgo.Describe("Preemption", func() { // Define sleepPod sleepPodConfigs := createSandbox1SleepPodCofigs(3, 600) - sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: true, Labels: map[string]string{"queue": "root.sandbox2"}} + sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.sandbox2"}} sleepPodConfigs = append(sleepPodConfigs, sleepPod4Config) for _, config := range sleepPodConfigs { @@ -225,7 +225,7 @@ var _ = ginkgo.Describe("Preemption", func() { // Define sleepPod sandbox1SleepPodConfigs := createSandbox1SleepPodCofigs(3, 30) - sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 30, Optedout: true, Labels: map[string]string{"queue": "root.sandbox2"}} + sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 30, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.sandbox2"}} // Deploy pods in root.sandbox1 for _, config := range sandbox1SleepPodConfigs { @@ -292,7 +292,7 @@ var _ = ginkgo.Describe("Preemption", func() { // Define sleepPod sandbox1SleepPodConfigs := createSandbox1SleepPodCofigs(3, 30) - sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 30, Optedout: true, Labels: map[string]string{"queue": "root.sandbox2"}} + sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 30, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.sandbox2"}} // Deploy pods in root.sandbox1 for _, config := range sandbox1SleepPodConfigs { @@ -367,8 +367,8 @@ var _ = ginkgo.Describe("Preemption", func() { // Define sleepPod sandbox1SleepPodConfigs := createSandbox1SleepPodCofigs(3, 30) - sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: true, Labels: map[string]string{"queue": "root.low-priority"}} - sleepPod5Config := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: true, Labels: map[string]string{"queue": "root.high-priority"}} + sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.low-priority"}} + sleepPod5Config := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit, Time: 600, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.high-priority"}} for _, config := range sandbox1SleepPodConfigs { ginkgo.By("Deploy the sleep pod " + config.Name + " to the development namespace") @@ -483,11 +483,11 @@ var _ = ginkgo.Describe("Preemption", func() { gomega.Ω(err).ShouldNot(HaveOccurred()) // Define sleepPod - sleepPod1Config := k8s.SleepPodConfig{Name: "sleepjob1", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: true, Labels: map[string]string{"queue": "root.sandbox3"}} - sleepPod2Config := k8s.SleepPodConfig{Name: "sleepjob2", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: true, Labels: map[string]string{"queue": "root.sandbox3"}} - sleepPod3Config := k8s.SleepPodConfig{Name: "sleepjob3", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: false, Labels: map[string]string{"queue": "root.sandbox4"}} - sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: false, Labels: map[string]string{"queue": "root.sandbox4"}} - sleepPod5Config := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: true, Labels: map[string]string{"queue": "root.sandbox5"}} + sleepPod1Config := k8s.SleepPodConfig{Name: "sleepjob1", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox3"}} + sleepPod2Config := k8s.SleepPodConfig{Name: "sleepjob2", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox3"}} + sleepPod3Config := k8s.SleepPodConfig{Name: "sleepjob3", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox4"}} + sleepPod4Config := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit2, Time: 60, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox4"}} + sleepPod5Config := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: k8s.NotConfig, Labels: map[string]string{"queue": "root.sandbox5"}} for _, config := range []k8s.SleepPodConfig{sleepPod1Config, sleepPod2Config, sleepPod3Config, sleepPod4Config} { ginkgo.By("Deploy the sleep pod " + config.Name + " to the development namespace") @@ -568,7 +568,7 @@ var _ = ginkgo.Describe("Preemption", func() { func createSandbox1SleepPodCofigs(cnt, time int) []k8s.SleepPodConfig { sandbox1Configs := make([]k8s.SleepPodConfig, 0, cnt) for i := 0; i < cnt; i++ { - sandbox1Configs = append(sandbox1Configs, k8s.SleepPodConfig{Name: fmt.Sprintf("sleepjob%d", i+1), NS: dev, Mem: sleepPodMemLimit, Time: time, Optedout: true, Labels: map[string]string{"queue": "root.sandbox1"}}) + sandbox1Configs = append(sandbox1Configs, k8s.SleepPodConfig{Name: fmt.Sprintf("sleepjob%d", i+1), NS: dev, Mem: sleepPodMemLimit, Time: time, Optedout: k8s.Allow, Labels: map[string]string{"queue": "root.sandbox1"}}) } return sandbox1Configs } diff --git a/test/e2e/simple_preemptor/simple_preemptor_test.go b/test/e2e/simple_preemptor/simple_preemptor_test.go index 9c8386f80..6de50c872 100644 --- a/test/e2e/simple_preemptor/simple_preemptor_test.go +++ b/test/e2e/simple_preemptor/simple_preemptor_test.go @@ -175,9 +175,9 @@ var _ = ginkgo.Describe("SimplePreemptor", func() { sleepPod3Configs := k8s.SleepPodConfig{Name: "sleepjob3", NS: dev, Mem: sleepPodMemLimit1, Time: 600, RequiredNode: Worker1, AppID: "test01"} // add the same AppID to sleepPod3Configs so that sleepPod4Configs is not the originator pod - sleepPod4Configs := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: true, AppID: "test01"} - sleepPod5Configs := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: false} - sleepPod6Configs := k8s.SleepPodConfig{Name: "sleepjob6", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: false} + sleepPod4Configs := k8s.SleepPodConfig{Name: "sleepjob4", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: k8s.Allow, AppID: "test01"} + sleepPod5Configs := k8s.SleepPodConfig{Name: "sleepjob5", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: k8s.Deny} + sleepPod6Configs := k8s.SleepPodConfig{Name: "sleepjob6", NS: dev, Mem: sleepPodMemLimit2, Time: 600, Optedout: k8s.Deny} sleepPod7Configs := k8s.SleepPodConfig{Name: "sleepjob7", NS: dev, Mem: sleepPodMemLimit2, Time: 600, RequiredNode: Worker2} for _, config := range []k8s.SleepPodConfig{sleepPodConfigs, sleepPod2Configs,